Пример #1
0
        public void Test_That_Modifying_Nested_Object_Keeps_Original_Unmodified()
        {
            var testClass = new Immutable<TestClass>();
            var newTestClass = testClass.Modify(x => x.Data, 
                testClass.Get(x => x.Data)
                .Modify(x => x.Member, 2)
            );

            Assert.Equal(testClass.Get(x => x.Data.Get(y => y.Member)), 0);
        }
        public void Test_That_Modifying_Nested_Object_Keeps_Original_Unmodified()
        {
            var testClass    = new Immutable <TestClass>();
            var newTestClass = testClass.Modify(x => x.Data =
                                                    testClass.Get(t => t.Data)
                                                    .Modify(t => t.Member = 2)
                                                );

            testClass.Get(x => x.Data.Get(y => y.Member)).ShouldBe(0);
        }
Пример #3
0
        public void Test_That_Getting_Self_Returns_Clone()
        {
            var testClass = new Immutable <TestClass>();

            testClass = testClass.Modify(x => x.Test = 5);

            var self = testClass.Get(x => x);

            self.Test = 6;

            testClass.Get(x => x.Test).ShouldNotBe(self.Test);
        }
        public void Test_That_Original_Object_Cannot_Be_Modified()
        {
            var testClass    = new Immutable <TestClass>();
            var newTestClass = testClass.Modify(x => x.Test = 1);

            testClass.Get(x => x.Test).ShouldBe(0);
        }
Пример #5
0
        public void Test_That_Original_Object_Cannot_Be_Modified()
        {
            var testClass = new Immutable<TestClass>();
            var newTestClass = testClass.Modify(x => x.Test, 1);

            Assert.Equal(testClass.Get(x => x.Test), 0);
        }
        public void Test_That_Modify_Can_Alter_Converted_Nullables()
        {
            var     testClass   = new Immutable <TestNullableClass>();
            decimal?testDecimal = null;

            testClass = testClass.Modify(x => x.Nullable = (int?)testDecimal);

            testClass.Get(x => x.Nullable).ShouldBeNull();
        }
        public void Test_That_Modifying_Nested_Returns_Modifications()
        {
            var testClass    = new Immutable <TestClass>();
            var newTestClass = testClass.Modify(x => x.Data =
                                                    testClass.Get(t => t.Data)
                                                    .Modify(t => t.Member = 2)
                                                );

            newTestClass.Get(x => x.Data.Get(y => y.Member)).ShouldBe(2);
        }
Пример #8
0
        public void Test_That_Modifying_Nested_Returns_Modifications()
        {
            var testClass = new Immutable<TestClass>();
            var newTestClass = testClass.Modify(x => x.Data, 
                testClass.Get(x => x.Data)
                .Modify(x => x.Member, 2)
            );

            Assert.Equal(newTestClass.Get(x => x.Data.Get(y => y.Member)), 2);
        }
Пример #9
0
        public void Test_That_Modify_Can_Alter_Converted_Nullables()
        {
            var testClass = new Immutable<TestNullableClass>();
            decimal? testDecimal = null;

            testClass = testClass.Modify(x => x.Nullable, testDecimal);

            Assert.Null(testClass.Get(x => x.Nullable));
        }
Пример #10
0
        public void Test_Modify_Nested_With_Implicit_Conversion()
        {
            var testClass = new Immutable<TestClass>();
            var newTestClass = testClass.Modify(x => x.Data,
                testClass.Get(x => x.Data)
                .Modify(x => x.Member, 2.0M)
            );

            Assert.Equal(newTestClass.Get(x => x.Data.Get(y => y.Member)), 2);
        }
Пример #11
0
 void DoSomething(Immutable <Entity> entity)
 {
     string             name    = entity.Get(e => e.Name);
     Immutable <Entity> renamed = entity
                                  .Modify(e => e.Name = "new name");
 }