Example #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);
        }
Example #2
0
        public void Can_merge_from_constructor_based_to_property_based(
            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 DestinationWithConstructor(destinationId, destinationName, destinationAge);

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

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