Skip to content

Instantly share code, notes, and snippets.

@mattflo
Created October 21, 2011 04:29
Show Gist options
  • Save mattflo/1303096 to your computer and use it in GitHub Desktop.
Save mattflo/1303096 to your computer and use it in GitHub Desktop.
Objectifying Xml using dynamic
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