public void Apply_OnSome_ResultContainsValue() { var property = new TestObject.TestProperty(); var testObject = new TestObject { Property = property }; Option <TestObject> some = testObject; var result = some.Apply(obj => obj.Property); ((Some <TestObject.TestProperty>)result).Content.Should().Be(property); }
public void Apply_OnSome_WhenUsingImplicitCast_ContainsValue() { var property = new TestObject.TestProperty(); var testObject = new TestObject { Property = property }; Option <TestObject> some = testObject; TestObject.TestProperty result = some.Apply(obj => obj.Property) as Some <TestObject.TestProperty>; result.Should().Be(property); }
public void SelectSome_ReturnsCorrectValue() { var testProperty = new TestObject.TestProperty(); var list = new List <TestObject> { new TestObject { Option = testProperty } }; var result = list.SelectSome(x => x.Option).First(); result.Should().Be(testProperty); }
public void FirstOrNonePredicateOnEmpty_ReturnsNone() { TestObject.TestProperty nullProperty = null; var notThisOne = new TestObject { Option = nullProperty }; var list = new List <TestObject> { notThisOne }; var result = list.FirstOrNone(x => x.Option is Some <TestObject.TestProperty>); result.Should().BeOfType <None <TestObject> >(); }
public void SelectSome_FiltersOutNones() { TestObject.TestProperty nullProperty = null; var notThisOne = new TestObject { Option = nullProperty }; var list = new List <TestObject> { notThisOne, new TestObject() }; var result = list.SelectSome(x => x.Option); result.Should().ContainSingle(); }
public void FirstOrNonePredicateWithFirst_ContainsCorrectValue() { TestObject.TestProperty nullProperty = null; var notThisOne = new TestObject { Option = nullProperty }; var thatOne = new TestObject(); var list = new List <TestObject> { notThisOne, thatOne }; var result = list.FirstOrNone(x => x.Option is Some <TestObject.TestProperty>) .ResultOr(() => throw new Exception("Test failed because FirstOrNone returned None")); result.Should().Be(thatOne); }