Пример #1
0
        public void MapFirstElementWhenCollectionIsNotEmpty()
        {
            // Arrange
            var mapper = CreateMapper<ListWithEmptyCollectionAndDecimal>(new[]
                {
                    "Collection.Element", "FirstLevelElement"
                });
            var objectToMap = new ListWithEmptyCollectionAndDecimal
            {
                Collection = new List<ElementWithDecimal>
                    {
                        new ElementWithDecimal
                            {
                                Element = 4.321m
                            }
                    },
                FirstLevelElement = 1.234m
            };

            // Act
            var mapping = mapper.Map(new object[] { objectToMap });

            // Assert
            Assert.AreEqual(1.234m, GetMappedPathFromCollection(mapping, 0, "FirstLevelElement"));
            Assert.AreEqual(4.321m, GetMappedPathFromCollection(mapping, 0, "Collection.Element"));
        }
Пример #2
0
        public void MapFirstLevelElementWhenCollectionIsEmpty()
        {
            // Arrange
            var mapper = CreateMapper<ListWithEmptyCollectionAndDecimal>(new[]
                {
                    "Collection.Element", "FirstLevelElement"
                });
            var objectToMap = new ListWithEmptyCollectionAndDecimal
                {
                    Collection = new List<ElementWithDecimal>(),
                    FirstLevelElement = 1.234m
                };

            // Act
            var mapping = mapper.Map(new object[] {objectToMap});

            // Assert
            Assert.AreEqual(1.234m, GetMappedPathFromCollection(mapping, 0, "FirstLevelElement"));

            // Expected behavior here is that FirstLevelElement is mapped one time when any other path goes through collection,
            // but elements from empty collection should not be mapped.
            //
            // Currently for empty collection the element not from collection is not mapped, but should be mapped.
        }