コード例 #1
0
        public void Should_return_null_when_the_subject_property_is_null()
        {
            GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.TheB.TheC.Value);

            var subject = new A();

            Assert.AreEqual(null, getValue.Get(subject));
        }
コード例 #2
0
        public void Should_return_the_default_if_array_value_missing()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.Values[0]);

            var obj = new A();

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #3
0
        public void Should_return_nothing_if_object_is_null()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            A obj = null;

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #4
0
        public void Should_return_default_if_the_array_is_null()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            var obj = new A();

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #5
0
        public void Should_return_default_if_item_missing()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            A obj = null;

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #6
0
        public void Should_return_default_value_for_null_object_on_value_type_references()
        {
            GetProperty <A, int> getValue = SafeProperty <A> .GetGetProperty(x => x.Id);

            const int expected = 0;

            A obj = null;

            int value = getValue.Get(obj);

            Assert.AreEqual(expected, value);
        }
コード例 #7
0
        public void Should_return_nothing_if_list_is_empty()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            var obj = new A
            {
                TheBs = new List <B>()
            };

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #8
0
        public void Should_work_for_reference_types()
        {
            GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.Value);

            const string expected = "123";

            var obj = new A
            {
                Value = expected
            };

            string value = getValue.Get(obj);

            Assert.AreEqual(expected, value);
        }
コード例 #9
0
        public void Should_return_the_value_for_value_types()
        {
            GetProperty <A, int> getValue = SafeProperty <A> .GetGetProperty(x => x.Id);

            const int expected = 123;

            var obj = new A
            {
                Id = expected
            };

            int value = getValue.Get(obj);

            Assert.AreEqual(expected, value);
        }
コード例 #10
0
        public void Should_retrieve_a_property_value_when_present()
        {
            GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.TheB.TheC.Value);

            var subject = new A
            {
                TheB = new B
                {
                    TheC = new C
                    {
                        Value = "123"
                    }
                }
            };

            Assert.AreEqual("123", getValue.Get(subject));
        }
コード例 #11
0
        public void Should_return_nothing_if_list_entry_is_null()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            var obj = new A
            {
                TheBs = new List <B>
                {
                    null
                }
            };

            Assert.AreEqual(1, obj.TheBs.Count);

            int value = getter.Get(obj);

            Assert.AreEqual(0, value);
        }
コード例 #12
0
        public void Should_return_the_nested_value()
        {
            GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.TheB.Value);

            const string expected = "123";

            var obj = new A
            {
                TheB = new B
                {
                    Value = expected
                }
            };

            string value = getValue.Get(obj);

            Assert.AreEqual(expected, value);
        }
コード例 #13
0
        public void Should_return_the_value_if_it_exists()
        {
            GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value);

            var obj = new A
            {
                TheBs = new List <B>
                {
                    new B
                    {
                        Value = 27
                    }
                }
            };

            int value = getter.Get(obj);

            Assert.AreEqual(27, value);
        }