Created
October 21, 2011 04:29
-
-
Save mattflo/1303096 to your computer and use it in GitHub Desktop.
Objectifying Xml using dynamic
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
using System.Dynamic; | |
using System.Linq; | |
using System.Xml.Linq; | |
using NSpec; | |
class describe_Objectify : nspec | |
{ | |
dynamic kitten; | |
string markup; | |
void when_objectifying_xml() | |
{ | |
act = () => kitten = new Objectify(markup); | |
context["property is attribute"] = () => | |
{ | |
before = () => markup = "<kitten color=\"orange\" />"; | |
KittenColorIsOrange(); | |
}; | |
context["property is element"] = () => | |
{ | |
before = () => markup = "<kitten><color>orange</color></kitten>"; | |
KittenColorIsOrange(); | |
}; | |
context["nesting - the kitten's ear"] = () => | |
{ | |
before = () => markup = "<kitten><ear color=\"white\"/></kitten>"; | |
it["is white"] = () => (kitten.ear.color as object).Is("white"); | |
}; | |
} | |
private void KittenColorIsOrange() | |
{ | |
it["is orange"] = () => (kitten.color as object).Is("orange"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment