Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }