예제 #1
0
        public void Should_set_first_level_property()
        {
            Expression <Func <Outer, string> > expression = o => o.Value;
            SafeProperty setter = SafeProperty.Create(expression);

            var outer = new Outer();

            setter.Set(outer, 0, "Hello");

            Assert.AreEqual("Hello", outer.Value);
        }
예제 #2
0
        public void Should_not_throw_a_null_reference_exception()
        {
            Expression <Func <OuterClass, object> > accessor = o => o.Inner.Value;

            SafeProperty writer = accessor.CreateSafeProperty();

            const string expected = "Hello";

            var subject = new OuterClass();

            writer.Set(subject, 0, expected);

            subject.Inner.Value.ShouldEqual(expected);
        }
예제 #3
0
        public void Should_go_way_deep()
        {
            Expression <Func <WayOuterClass, object> > accessor = o => o.Outer.Inner.Value;

            SafeProperty writer = accessor.CreateSafeProperty();

            const string expected = "Hello";

            var subject = new WayOuterClass();

            writer.Set(subject, 0, expected);

            subject.Outer.Inner.Value.ShouldEqual(expected);
        }
예제 #4
0
        public void Should_set_third_level_value_with_one_array_indexer()
        {
            Expression <Func <Outer, string> > expression = o => o.Middles[0].Inner.Value;

            SafeProperty setter = SafeProperty.Create(expression);

            var outer = new Outer();

            setter.Set(outer, 0, "Hello");

            Assert.IsNotNull(outer.Middles);
            Assert.AreEqual(1, outer.Middles.Count);
            Assert.IsNotNull(outer.Middles[0].Inner);
            Assert.AreEqual("Hello", outer.Middles[0].Inner.Value);
        }
예제 #5
0
        public void Should_create_a_backing_list_for_list_based_properties()
        {
            Expression <Func <OuterClass, object> > accessor = o => o.Inners[0].Value;

            SafeProperty writer = accessor.CreateSafeProperty();

            const string expected = "Hello";

            var subject = new OuterClass();

            writer.Set(subject, 0, expected);

            subject.Inners.ShouldNotBeNull();
            subject.Inners[0].Value.ShouldEqual(expected);
        }
예제 #6
0
        public void Should_create_a_setter_for_a_simple_value()
        {
            Expression <Func <OuterClass, object> > accessor = o => o.Value;


            SafeProperty writer = accessor.CreateSafeProperty();


            var subject = new OuterClass();

            const string expected = "Hello";

            writer.Set(subject, 0, expected);

            subject.Value.ShouldEqual(expected);
        }
예제 #7
0
        public void Should_allow_property_to_already_be_set()
        {
            Expression <Func <OuterClass, object> > accessor = o => o.Inner.Value;

            SafeProperty writer = accessor.CreateSafeProperty();

            const string expected = "Hello";

            var subject = new OuterClass();

            subject.Inner = new InnerClass {
                OtherValue = "Hi"
            };

            writer.Set(subject, 0, expected);

            subject.Inner.Value.ShouldEqual(expected);
            subject.Inner.OtherValue.ShouldEqual("Hi");
        }