Example #1
0
        public void Test_that_setter_is_created_well_and_works()
        {
            // Arrange
            var factory            = new PropertySettersFactory();
            var valueTypeValue     = 123;
            var referenceTypeValue = new TestComplexType();
            var entity             = new TestEntity
            {
                NullProperty = "not null"
            };

            // Act
            var valueTypePropertySetter     = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.ValueTypeProperty)));
            var referenceTypePropertySetter = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.ReferenceTypeProperty)));
            var nullPropertySetter          = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.NullProperty)));

            valueTypePropertySetter.Invoke(entity, valueTypeValue);
            referenceTypePropertySetter.Invoke(entity, referenceTypeValue);
            nullPropertySetter.Invoke(entity, null);

            // Assert
            Assert.AreEqual(valueTypeValue, entity.ValueTypeProperty);
            Assert.AreEqual(referenceTypeValue, entity.ReferenceTypeProperty);
            Assert.IsNull(entity.NullProperty);
        }
Example #2
0
        public void Test_that_null_value_setting_interpreted_as_null_for_reference_type_property_and_as_default_value_for_value_type_property()
        {
            // Arrange
            var factory = new PropertySettersFactory();
            var entity  = new TestEntity
            {
                ReferenceTypeProperty = new TestComplexType()
            };

            // Act
            var valueTypePropertySetter     = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.ValueTypeProperty)));
            var enumPropertySetter          = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.EnumProperty)));
            var referenceTypePropertySetter = factory.Create(TestEntityType.GetProperty(nameof(TestEntity.ReferenceTypeProperty)));

            valueTypePropertySetter.Invoke(entity, null);
            enumPropertySetter.Invoke(entity, null);
            referenceTypePropertySetter.Invoke(entity, null);

            // Assert
            Assert.AreEqual(default(int), entity.ValueTypeProperty);
            Assert.AreEqual(default(DateTimeKind), entity.EnumProperty);
            Assert.AreEqual(null, entity.ReferenceTypeProperty);
        }
Example #3
0
        public void Test_that_inherited_properties_can_be_get()
        {
            // Arrange
            var factory        = new PropertySettersFactory();
            var valueTypeValue = 123;
            var derivedVaue    = 555;
            var virtualValue   = "333";
            var entity         = new DerivedTestEntity();

            // Act
            var valueTypePropertySetter = factory.Create(DerivedTestEntityType.GetProperty(nameof(DerivedTestEntity.ValueTypeProperty)));
            var derivedPropertySetter   = factory.Create(DerivedTestEntityType.GetProperty(nameof(DerivedTestEntity.PropertyInDerivedEntity)));
            var virtualPropertySetter   = factory.Create(DerivedTestEntityType.GetProperty(nameof(DerivedTestEntity.VirtualProperty)));

            valueTypePropertySetter.Invoke(entity, valueTypeValue);
            derivedPropertySetter.Invoke(entity, derivedVaue);
            virtualPropertySetter.Invoke(entity, virtualValue);

            // Assert
            Assert.AreEqual(valueTypeValue, entity.ValueTypeProperty);
            Assert.AreEqual(derivedVaue, entity.PropertyInDerivedEntity);
            Assert.AreEqual(virtualValue, entity.VirtualProperty);
        }