Skip to content

Instantly share code, notes, and snippets.

@gravypower
Last active December 26, 2015 10:49
Show Gist options
  • Save gravypower/7139963 to your computer and use it in GitHub Desktop.
Save gravypower/7139963 to your computer and use it in GitHub Desktop.
public class MockNode
{
private readonly IDictionary<string, object> properties;
public MockNode()
{
this.properties = new Dictionary<string, object>();
}
public MockNode AddProperty(string alias, string value)
{
properties.Add(alias, value);
return this;
}
public INode Mock()
{
var node = Substitute.For<INode>();
foreach (var pair in properties)
{
var property = Substitute.For<IProperty>();
property.Alias.Returns(pair.Key);
property.Value.Returns(pair.Value);
node.GetProperty(pair.Key).Returns(property);
}
return node;
}
}
public class MockNodeFactory
{
public static INode BuildNode(IDictionary<string, object> properties)
{
var node = Substitute.For<INode>();
foreach (var pair in properties)
{
var property = Substitute.For<IProperty>();
property.Alias.Returns(pair.Key);
property.Value.Returns(pair.Value);
node.GetProperty(pair.Key).Returns(property);
}
return node;
}
}
var mockNode = new MockNode()
.AddProperty("Body", "Body")
.AddProperty("Title", "Title")
.Mock();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment