Last active
December 26, 2015 10:49
-
-
Save gravypower/7139963 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
} |
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
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; | |
} | |
} |
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
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