Пример #1
0
        public void Should_Not_Set_Default_Values_For_Defined_Properties_If_Requested()
        {
            var person = new ExtensibleTestPerson(false);

            person.HasProperty("Name").ShouldBeFalse();
            person.HasProperty("Age").ShouldBeFalse();
            person.HasProperty("NoPairCheck").ShouldBeFalse();
            person.HasProperty("CityName").ShouldBeFalse();
        }
Пример #2
0
        public HasExtraPropertiesObjectExtendingExtensions_Tests()
        {
            _person = new ExtensibleTestPerson()
                      .SetProperty("Name", "John")
                      .SetProperty("Age", 42)
                      .SetProperty("ChildCount", 2)
                      .SetProperty("Sex", "male")
                      .SetProperty("NoPairCheck", "test-value")
                      .SetProperty("CityName", "Adana");

            _personDto = new ExtensibleTestPersonDto()
                         .SetProperty("ExistingDtoProperty", "existing-value");
        }
Пример #3
0
        public void Should_Set_Default_Values_For_Defined_Properties_On_Create()
        {
            var person = new ExtensibleTestPerson();

            person.HasProperty("Name").ShouldBeTrue();
            person.HasProperty("Age").ShouldBeTrue();
            person.HasProperty("NoPairCheck").ShouldBeTrue();
            person.HasProperty("CityName").ShouldBeTrue();

            person.GetProperty <string>("Name").ShouldBeNull();
            person.GetProperty <int>("Age").ShouldBe(0);
            person.GetProperty <string>("NoPairCheck").ShouldBeNull();
            person.GetProperty <string>("CityName").ShouldBeNull();
        }
    public void MapExtraPropertiesTo_Should_Only_Map_Defined_Properties_By_Default()
    {
        var person = new ExtensibleTestPerson()
                     .SetProperty("Name", "John")
                     .SetProperty("Age", 42)
                     .SetProperty("ChildCount", 2)
                     .SetProperty("Sex", "male")
                     .SetProperty("CityName", "Adana");

        var personDto = new ExtensibleTestPersonDto()
                        .SetProperty("ExistingDtoProperty", "existing-value");

        _objectMapper.Map(person, personDto);

        personDto.GetProperty <string>("Name").ShouldBe("John");                          //Defined in both classes
        personDto.GetProperty <string>("ExistingDtoProperty").ShouldBe("existing-value"); //Should not clear existing values
        personDto.GetProperty <int>("ChildCount").ShouldBe(0);                            //Not defined in the source, but was set to the default value by ExtensibleTestPersonDto constructor
        personDto.GetProperty("CityName").ShouldBeNull();                                 //Ignored, but was set to the default value by ExtensibleTestPersonDto constructor
        personDto.HasProperty("Age").ShouldBeFalse();                                     //Not defined on the destination
        personDto.HasProperty("Sex").ShouldBeFalse();                                     //Not defined in both classes
    }
    public void MapExtraProperties_Also_Should_Map_To_RegularProperties()
    {
        var person = new ExtensibleTestPerson()
                     .SetProperty("Name", "John")
                     .SetProperty("Age", 42);

        var personDto = new ExtensibleTestPersonWithRegularPropertiesDto()
                        .SetProperty("IsActive", true);

        _objectMapper.Map(person, personDto);

        //Defined in both classes
        personDto.HasProperty("Name").ShouldBe(false);
        personDto.Name.ShouldBe("John");

        //Defined in both classes
        personDto.HasProperty("Age").ShouldBe(false);
        personDto.Age.ShouldBe(42);

        //Should not clear existing values
        personDto.HasProperty("IsActive").ShouldBe(false);
        personDto.IsActive.ShouldBe(true);
    }