Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speccing out spark element /node wrapper interfaces
git-svn-id: http://openrastasparkcodec.googlecode.com/svn/trunk@22 1f2a5d12-3dac-11de-b232-599c1b3c59e8
- Loading branch information
Jennifer.E.M.Smith
authored and
Jennifer.E.M.Smith
committed
Sep 11, 2009
1 parent
82d196f
commit 7772849
Showing
16 changed files
with
292 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/OpenRasta.Codecs.Spark.UnitTests/SparkInterface/SparkElementWrapperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using OpenRasta.Codecs.Spark2.Model; | ||
using OpenRasta.Codecs.Spark2.SparkInterface; | ||
using Spark.Parser.Markup; | ||
|
||
namespace OpenRasta.Codecs.Spark.UnitTests.SparkInterface | ||
{ | ||
[TestFixture] | ||
public class SparkElementWrapperTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
Context = new SparkElementWrapperTestContext(); | ||
} | ||
|
||
[Test] | ||
public void ShouldAddAnAttributeToOriginalNodeOnAddAttribute() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
WhenAnAttributeIsAdded("theAttribute"); | ||
ThenTheWrappedElementShouldHaveABlankAttributeNamed("theAttribute"); | ||
} | ||
[Test] | ||
public void ShouldReturnWrappedAttributeNodeWhenAttributeIsAdded() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
WhenAnAttributeIsAdded("theAttribute"); | ||
ThenTheReturnedAttributeShouldBeWrappedSparkAttributeNamed("theAttribute"); | ||
} | ||
[Test] | ||
public void ShouldReturnTrueForHasAttributeIfUnderlyingNodeHasAttribute() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
WhenAnAttributeIsAdded("theAttribute"); | ||
ThenHasAttributeShouldBeTrueFor("theAttribute"); | ||
} | ||
[Test] | ||
public void ShouldReturnFalseForHasAttributeIfUnderlyingNodeDoesntHaveAttribute() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
ThenHasAttributeShouldBeFalseFor("theAttribute"); | ||
} | ||
|
||
[Test] | ||
public void ShouldReturnTrueForHasAttributeIfUnderlyingNodeHasAttributeWithDifferentCase() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
WhenAnAttributeIsAdded("theATTriBUTE"); | ||
ThenHasAttributeShouldBeTrueFor("theAttribute"); | ||
} | ||
|
||
[Test] | ||
public void GetAttributeShouldReturnEmptyAttributreNodeIfTheAttributeDoesntExist() | ||
{ | ||
GivenAnOriginalElement(SparkTestNodes.BasicElementNode()); | ||
WhenAttributeIsRetreived("thisAttribute"); | ||
ThenGetAttributeResultShouldBeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void ShouldReturnWrappedAttributeNodeIfItExists() | ||
{ | ||
AttributeNode attributeNode = SparkTestNodes.BasicAttributeNode("thisAttribute"); | ||
ElementNode node = SparkTestNodes.BasicElementNode().WithAttribute(attributeNode); | ||
GivenAnOriginalElement(node); | ||
WhenAttributeIsRetreived("thisAttribute"); | ||
ThenRetrievedAttributeShouldWrap(attributeNode); | ||
} | ||
|
||
private void ThenRetrievedAttributeShouldWrap(Node attributeNode) | ||
{ | ||
Context.GetAttributeResult.ShouldNotBeNull(); | ||
Context.GetAttributeResult.Unwrap().ShouldEqual(attributeNode); | ||
} | ||
|
||
private void ThenGetAttributeResultShouldBeEmpty() | ||
{ | ||
Context.GetAttributeResult.Unwrap().ShouldBeNull(); | ||
} | ||
|
||
private void WhenAttributeIsRetreived(string attributeName) | ||
{ | ||
Context.GetAttributeResult = Context.Target.GetAttribute(attributeName); | ||
} | ||
|
||
private void ThenHasAttributeShouldBeFalseFor(string attributeName) | ||
{ | ||
Context.Target.HasAttribute(attributeName).ShouldBeFalse(); | ||
} | ||
|
||
private void ThenHasAttributeShouldBeTrueFor(string attributeName) | ||
{ | ||
Context.Target.HasAttribute(attributeName).ShouldBeTrue(); | ||
} | ||
|
||
|
||
private void ThenTheReturnedAttributeShouldBeWrappedSparkAttributeNamed(string attributeName) | ||
{ | ||
Context.AddAttributeResult.Unwrap().As<AttributeNode>().Name.ShouldEqual(attributeName); | ||
} | ||
|
||
private void ThenTheWrappedElementShouldHaveABlankAttributeNamed(string attribute) | ||
{ | ||
Context.Target.CurrentNode.Attributes.ShouldContain(x => x.Name == attribute); | ||
AttributeNode attributeNode = Context.Target.CurrentNode.Attributes.Where(x => x.Name == attribute).First(); | ||
attributeNode.Value.ShouldBeEmpty(); | ||
} | ||
|
||
private void WhenAnAttributeIsAdded(string attributeName) | ||
{ | ||
Context.AddAttributeResult = Context.Target.AddAttribute(attributeName); | ||
} | ||
|
||
private void GivenAnOriginalElement(ElementNode elementNode) | ||
{ | ||
Context.Target = new SparkElementWrapper(elementNode); | ||
} | ||
|
||
public SparkElementWrapperTestContext Context { get; set; } | ||
|
||
public class SparkElementWrapperTestContext | ||
{ | ||
public SparkElementWrapper Target { get; set; } | ||
|
||
public IAttribute AddAttributeResult { get; set; } | ||
|
||
public IAttribute GetAttributeResult { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OpenRasta.Codecs.Spark2.Model; | ||
|
||
namespace OpenRasta.Codecs.Spark.UnitTests | ||
{ | ||
public class TestAttributeNode :ContentContainingNode, IAttribute | ||
{ | ||
private readonly string _value; | ||
|
||
public TestAttributeNode(string name, string value) : base(name) | ||
{ | ||
_value = value; | ||
} | ||
public IEnumerable<ICodeExpressionNode> CodeNodes | ||
{ | ||
get | ||
{ | ||
return Nodes.Where(x => (x is ICodeExpressionNode)).Cast<ICodeExpressionNode>(); | ||
} | ||
} | ||
|
||
public ICodeExpressionNode AddExpression() | ||
{ | ||
var codeExpressionNode = new TestCodeExpressionNode(); | ||
Nodes.Add(codeExpressionNode); | ||
return codeExpressionNode; | ||
} | ||
|
||
public string GetTextValue() | ||
{ | ||
return _value; | ||
} | ||
|
||
public bool Exists() | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.