示例#1
0
        public void IntProperty()
        {
            var obj = new TestClass()
            {
                IntProp = 3
            };

            var lens = new PropertyLens<TestClass, int>(m => m.IntProp);

            Assert.AreEqual(3, obj.IntProp);
            Assert.AreEqual(3, lens.Map(obj));
            lens.Apply(obj, 42);
            Assert.AreEqual(42, obj.IntProp);
            Assert.AreEqual(42, lens.Map(obj));
        }
示例#2
0
        public void StringProperty()
        {
            var obj = new TestClass()
            {
                StringProp = "initial"
            };

            var lens = new PropertyLens<TestClass, string>(m => m.StringProp);

            Assert.AreEqual("initial", obj.StringProp);
            Assert.AreEqual("initial", lens.Map(obj));
            lens.Apply(obj, "new");
            Assert.AreEqual("new", obj.StringProp);
            Assert.AreEqual("new", lens.Map(obj));
        }
示例#3
0
        public void ChildProperty()
        {
            var obj = new TestClass()
            {
                Child = new Child()
                {
                    ChildStringProp = "initial"
                }
            };

            var lens = new PropertyLens<TestClass, string>(m => m.Child.ChildStringProp);

            Assert.AreEqual(obj.Child.ChildStringProp, lens.Map(obj));
            lens.Apply(obj, "new");
            Assert.AreEqual("new", obj.Child.ChildStringProp);
        }