Ejemplo n.º 1
0
        public void GIVEN_PropertiesAndFilteredOutSetters_WHEN_DeltaApply_THEN_OnlyThoseSpecifiedApplied()
        {
            //Arrange
            Setup();
            _mapping.Object.PropertySetters.Add("id", (o, p) => { ((Author)o).Id = (int)p; });
            _mapping.Object.PropertySetters.Add("name", (o, p) => { ((Author)o).Name = (string)p; });
            _mapping.Object.PropertySetters.Add("dateTimeCreated", (o, p) => { ((Author)o).DateTimeCreated = (DateTime)p; });


            var author         = new Author();
            var classUnderTest = new Delta <Author>(_configuration.Object);

            classUnderTest.ObjectPropertyValues =
                new Dictionary <string, object>()
            {
                { "id", 1 },
                { "dateTimeCreated", new DateTime(2016, 1, 1) },
                { "name", "author name to be filtered out" }
            };

            classUnderTest.Scan();
            classUnderTest.FilterOut(t => t.Name);

            //Act
            classUnderTest.ApplySimpleProperties(author);

            //Assert
            Assert.Equal(author.Id, 1);
            Assert.Equal(author.DateTimeCreated, new DateTime(2016, 1, 1));
            Assert.Null(author.Name);
        }
Ejemplo n.º 2
0
        public void TestEmptyPropertiesValues()
        {
            //Arrange
            var simpleObject = new SimpleTestClass();
            var objectUnderTest = new Delta<SimpleTestClass>();

            //Act
            objectUnderTest.FilterOut(t => t.Prop1NotIncluded);
            objectUnderTest.ApplySimpleProperties(simpleObject);

            //Assert
            Assert.Null(simpleObject.Prop1NotIncluded);
            Assert.Null(simpleObject.Prop1);
            Assert.Null(simpleObject.Prop2);
        }
Ejemplo n.º 3
0
        public void GIVEN_ScanNotCalled_WHEN_DeltaFilterOut_THEN_ExceptionThrown()
        {
            //Arrange
            Setup();

            var classUnderTest = new Delta <Author>(_configuration.Object);

            classUnderTest.ObjectPropertyValues =
                new Dictionary <string, object>()
            {
                { "id", 1 },
                { "dateTimeCreated", new DateTime(2016, 1, 1) }
            };

            //Act/Assert
            var ex = Assert.Throws <Exception>(() => classUnderTest.FilterOut(t => t.Name));

            Assert.Equal("Scan must be called before this method", ex.Message);
        }
Ejemplo n.º 4
0
        public void SimpleTestOfFunction()
        {
            //Arange
            var simpleObject = new SimpleTestClass();
            var classUnderTest = new Delta<SimpleTestClass>();

            classUnderTest.FilterOut(t => t.Prop1NotIncluded);
            classUnderTest.ObjectPropertyValues = new Dictionary<string, object>()
                                         {
                                           {"Prop2","b"}
                                         };
            //Act
            classUnderTest.ApplySimpleProperties(simpleObject);

            //Assert
            Assert.NotNull(simpleObject.Prop2);
            Assert.Equal(simpleObject.Prop2, "b");
            Assert.Null(simpleObject.Prop1NotIncluded);
        }
Ejemplo n.º 5
0
        public void GIVEN_IncompleteProperties_WHEN_DeltaApply_THEN_OnlyThoseSpecifiedApplied()
        {
            //Arange
            var author         = new Author();
            var classUnderTest = new Delta <Author>();

            classUnderTest.FilterOut(t => t.Name);
            classUnderTest.ObjectPropertyValues =
                new Dictionary <string, object>()
            {
                { "Id", 1 },
                { "DateTimeCreated", new DateTime(2016, 1, 1) }
            };
            //Act
            classUnderTest.ApplySimpleProperties(author);

            //Assert
            Assert.Equal(author.Id, 1);
            Assert.Equal(author.DateTimeCreated, new DateTime(2016, 1, 1));
            Assert.Null(author.Name);
        }