public void DeepRetrieveFromObjectGraph() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, Parent = new Node { Number = 3 } } }; // Act var third = node.Maybe() .Apply(n => n.Parent) .Apply(n => n.Parent) .Return(); // Assert Assert.IsNotNull(third); Assert.AreEqual(3, third.Number); }
public void PassingIf() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, Parent = new Node { Number = 3 } } }; // Act var third = node.Maybe() .Apply(n => n.Parent) .If(n => n.Number == 2) .Apply(n => n.Parent) .Return(n => n.Number); // Assert Assert.AreEqual(3, third); }
public void PassingDo() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, Parent = new Node { Number = 3 } } }; int blah = 0; // Act node.Maybe() .Apply(n => n.Parent) .Do(n => blah = n.Number); // Assert Assert.AreEqual(2, blah); }
public void PassingCast() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, Parent = new Node { Number = 3 } } }; // Act var secondNum = node.Maybe() .Apply(n => n.Parent) .Cast<IDoStuff>() .Return(n => n.Number); // Assert Assert.AreEqual(2, secondNum); }
public void FailingCast() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, Parent = new Node { Number = 3 } } }; // Act var third = node.Maybe() .Apply(n => n.Parent) .Cast<Blah>() .Apply(n => n.Parent) .Return(n => n.Number); // Assert Assert.AreEqual(0, third); }
public void DeepRetrieveFromPartialObjectGraph() { // Arrange Node node = new Node { Number = 1, Parent = new Node { Number = 2, } }; // Act var third = node.Maybe() .Apply(n => n.Parent) .Apply(n => n.Parent) .Return(); // Assert Assert.IsNull(third); }