예제 #1
0
        public void Should_Select_Simple_Property_Value()
        {
            var selector = new MemberSelector() { MemberName = "StringValue" };

            var data = new Item() { StringValue = "Value1" };

            Assert.Same("Value1", selector.Select(data));
        }
예제 #2
0
        public void Should_Select_Null_Value_On_Wrong_MemberName()
        {
            var selector = new MemberSelector() { MemberName = "WrongProperty" };

            var data = new Item() { StringValue = "Value1" };

            Assert.Same(null, selector.Select(data));
        }
예제 #3
0
        public void Should_Select_Child_Property_Value_In_Multiple_Items()
        {
            var selector = new MemberSelector() { MemberName = "Child.StringValue" };

            var data = new Item[]
            {
                new Item() { Child = new Item() { StringValue = "Value1" } },
                new Item() { Child = new Item() { StringValue = "Value2" } },
                new Item() { Child = new Item() { StringValue = "Value3" } }
            };

            Assert.Same("Value1", selector.Select(data[0]));
            Assert.Same("Value2", selector.Select(data[1]));
            Assert.Same("Value3", selector.Select(data[2]));
        }
예제 #4
0
        public void Should_Select_MoreComplex_Property_Value()
        {
            var selector = new MemberSelector() { MemberName = "Child.Child.Child.StringValue" };

            var data = new Item()
            {
                Child = new Item()
                {
                    Child = new Item()
                    {
                        Child = new Item() { StringValue = "Value1" }
                    }
                }
            };

            Assert.Same("Value1", selector.Select(data));
        }
예제 #5
0
        public void Should_Not_Hold_Reference_To_Object()
        {
            WeakReference dataRef = null;

            var selector = new MemberSelector() { MemberName = "Child.StringValue" };

            Action run = () =>
            {
                var data = new Item()
                {
                    Child = new Item() { StringValue = "Value1" }
                };

                Assert.Same("Value1", selector.Select(data));

                dataRef = new WeakReference(data);
            };

            run();

            GC.Collect();

            Assert.False(dataRef.IsAlive);
        }
예제 #6
0
        public void Should_Select_Null_Value_On_Null_Object()
        {
            var selector = new MemberSelector() { MemberName = "StringValue" };

            Assert.Equal(null, selector.Select(null));
        }
예제 #7
0
        public void Should_Support_Change_Of_Target_Value()
        {
            var selector = new MemberSelector() { MemberName = "StringValue" };

            var data = new Item()
            {
                StringValue = "Value1"
            };

            Assert.Same("Value1", selector.Select(data));

            data.StringValue = "Value2";

            Assert.Same("Value2", selector.Select(data));
        }
예제 #8
0
        public void Should_Support_Change_Of_MemberName()
        {
            var selector = new MemberSelector() { MemberName = "StringValue" };

            var data = new Item()
            {
                StringValue = "Value1",
                IntValue = 1
            };

            Assert.Same("Value1", selector.Select(data));

            selector.MemberName = "IntValue";

            Assert.Equal(1, selector.Select(data));
        }
예제 #9
0
        public void Should_Select_Target_On_Empty_MemberName()
        {
            var selector = new MemberSelector();

            var data = new Item() { StringValue = "Value1" };

            Assert.Same(data, selector.Select(data));
        }