示例#1
0
        public void Can_merge_types_using_properties(
            string sourceId, string sourceName, int?sourceAge,
            string destinationId, string destinationName, int?destinationAge,
            string expectedId, string expectedName, int?expectedAge)
        {
            // Arrange
            var source = new SourceWithSetters
            {
                Id   = sourceId,
                Age  = sourceAge,
                Name = sourceName
            };
            var destination = new DestinationWithSetters
            {
                Id   = destinationId,
                Age  = destinationAge,
                Name = destinationName
            };

            // Act
            var result = ObjectExtensions.Merge <SourceWithSetters, SourceWithSetters, DestinationWithSetters>(source, destination);

            // Assert
            result.Age.Should().Be(expectedAge);
            result.Id.Should().Be(expectedId);
            result.Name.Should().Be(expectedName);
        }
示例#2
0
        public void Can_merge_from_property_based_to_constructor_based(
            string sourceId, string sourceName, int?sourceAge,
            string destinationId, string destinationName, int?destinationAge,
            string expectedId, string expectedName, int?expectedAge)
        {
            // Arrange
            var source      = new SourceWithConstructor(sourceId, sourceName, sourceAge);
            var destination = new DestinationWithSetters
            {
                Id   = destinationId,
                Age  = destinationAge,
                Name = destinationName
            };

            // Act
            var result = ObjectExtensions.Merge <SourceWithConstructor, SourceWithConstructor, DestinationWithSetters>(source, destination);

            // Assert
            result.Age.Should().Be(expectedAge);
            result.Id.Should().Be(expectedId);
            result.Name.Should().Be(expectedName);
        }