Esempio n. 1
0
            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);
            }
Esempio n. 2
0
            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);
            }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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> >();
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        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);
        }