Esempio n. 1
0
        public void TestInitialize()
        {
            _source = new Source
            {
                Name      = "Test Name",
                Id        = 123,
                FirstName = "Brian",
                LastName  = "Schroer",
                FullName  = "Brian Schroer",
                Children  = new[] { "Child1", "Child2" }
            };

            _dest = new Dest
            {
                Name     = "Test Name",
                Id       = 123,
                Children = new[] { "Child1", "Child2" }
            };

            _mapTester = MapTester.ForMap <Source, Dest>()
                         //.WithLogging()
                         .IgnoringMember(dest => dest.DestOnly)
                         .IgnoringMember(dest => dest.Date)
                         .IgnoringMember(dest => dest.Children);
        }
Esempio n. 2
0
 public void AssertMappedValues_should_throw_exception_for_unmapped_dest_property()
 {
     AssertExceptionThrown
     .OfType <MapTesterException>()
     .WithMessageContaining("Property \"DestOnly\" was not tested")
     .WhenExecuting(() => MapTester.ForMap <Source, Dest>().AssertMappedValues(_source, _dest));
 }
Esempio n. 3
0
 private void AssertSourceToDestMapping(Source sourceInstance, Dest destInstance)
 {
     MapTester.ForMap <Source, Dest>()
     .WhereMember(dest => dest.Id).ShouldEqual(src => src.Id)
     .WhereMember(dest => dest.Name).ShouldEqual(src => src.FullName)
     .WhereMember(dest => dest.Address).ShouldEqualValue("Address")
     .AssertMappedValues(sourceInstance, destInstance);
 }
        public void AssertAutoMappedRandomValues_with_IMapper_should_work()
        {
            Dest dest = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedRandomValues(_mapper));

            Assert.IsInstanceOfType(dest, typeof(Dest));
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void AssertAutoMappedRandomValues_should_work()
        {
            Dest dest = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedRandomValues());

            dest.Should().BeOfType <Dest>();
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void AssertAutoMappedValues_with_IMapper_should_work()
        {
            Source source = GetRandom.InstanceOf <Source>();
            Dest   dest   = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedValues(_mapper, source));

            dest.Should().BeOfType <Dest>();
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void AssertAutoMappedValues_should_work()
        {
            Source source = new RandomValuesHelper().CreateInstanceWithRandomValues <Source>();
            Dest   dest   = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedValues(source));

            Assert.IsInstanceOfType(dest, typeof(Dest));
            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
        public void AssertAutoMappedRandomValues_with_IMapper_and_RandomValueProvider_should_work()
        {
            Dest dest = null;

            AssertExceptionNotThrown.WhenExecuting(() =>
                                                   dest = MapTester.ForMap <Source, Dest>().AssertAutoMappedRandomValues(_mapper, this));

            dest.Should().BeOfType <Dest>();
            dest.Id.Should().Be(_testInt);

            Console.WriteLine(JsonConvert.SerializeObject(dest));
        }
Esempio n. 9
0
        public void IgnoringAllOtherMembers_should_work_as_expected()
        {
            var loggedMessages = new List <string>();

            MapTester.ForMap <Source, Dest>()
            .WithLogging(loggedMessages.Add)
            .IgnoringMember(dest => dest.Children)
            .IgnoringAllOtherMembers()
            .AssertMappedValues(_source, _dest);

            Assert.IsNotNull(loggedMessages.SingleOrDefault(x => x == "Property \"DestOnly\" was not tested."));
        }
Esempio n. 10
0
        public void IgnoringMember_should_exclude_dest_member_check()
        {
            var input = new RestaurantEditModel {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };
            var output = new Restaurant {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };

            MapTester.ForMap <RestaurantEditModel, Restaurant>()
            .WhereMember(dest => dest.Id).ShouldEqualValue(0)
            .AssertMappedValues(input, output);
        }
Esempio n. 11
0
        public void Mapping_should_work_from_readonly_properties()
        {
            var source = new SourceWithReadOnlyProperties();

            _dest = new Dest
            {
                Name = source.Name,
                Id   = source.Id
            };

            MapTester.ForMap <SourceWithReadOnlyProperties, Dest>()
            .IgnoringMembers(dest => dest.DestOnly, dest => dest.Date, dest => dest.Children)
            .AssertMappedValues(source, _dest);
        }
Esempio n. 12
0
        public void ToString_should_return_expected_results()
        {
            const string Stan = "Stan";

            ForTest.Scenarios
            (
                (
                    MapTester: MapTester.ForMap <Source, Dest>().IgnoringMember(dest => dest.Children).IgnoringMember(dest => dest.DestOnly),
                    Expected: "MapTester.ForMap<Source, Dest>().IgnoringMembers(dest => dest.Children, dest => dest.DestOnly)"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).ShouldEqual(src => src.LastName),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).ShouldEqual(src => src.LastName)"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).ShouldEqual(src => src.FirstName + src.LastName),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).ShouldEqual(src => (src.FirstName + src.LastName))"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Id).ShouldEqualValue(1).WhereMember(dest => dest.Name).ShouldEqualValue("Stan"),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Id).ShouldEqualValue(1).WhereMember(dest => dest.Name).ShouldEqualValue(\"Stan\")"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).ShouldEqualValue(null),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).ShouldEqualValue(null)"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).ShouldEqualValue(Stan),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).ShouldEqualValue(\"Stan\")"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Date).ShouldEqualValue(new DateTime(2018, 1, 15)),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Date).ShouldEqualValue(1/15/2018 12:00:00 AM)"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).IsTestedBy((src, dest) => { /* custom test */ }),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).IsTestedBy((src, dest) => { /* custom test */ })"
                ),
                (
                    MapTester: MapTester.ForMap <Source, Dest>().WhereMember(dest => dest.Name).IsTestedBy(dest => { /* custom test */ }),
                    Expected: "MapTester.ForMap<Source, Dest>().WhereMember(dest => dest.Name).IsTestedBy(dest => { /* custom test */ })"
                )
            )
            .TestEach(scenario =>
            {
                string actual = scenario.MapTester.ToString().Replace("\n", "").Replace("\t", "");
                Assert.AreEqual(scenario.Expected, actual);
            });
        }
Esempio n. 13
0
        public void Mapping_should_work_with_matching_properties_with_case_differences()
        {
            var source = new SourceWithCaseDifferences
            {
                ID   = 123,
                NaMe = "Test Name"
            };

            _dest = new Dest
            {
                Name = source.NaMe,
                Id   = source.ID
            };

            MapTester.ForMap <SourceWithCaseDifferences, Dest>()
            .IgnoringMembers(dest => dest.DestOnly, dest => dest.Date, dest => dest.Children)
            .AssertMappedValues(source, _dest);
        }
Esempio n. 14
0
        public void ShouldBeStringMatchFor_should_work_as_expected()
        {
            var restaurant = new Restaurant {
                Id = 24, Name = "TestName", Cuisine = CuisineType.German
            };
            var diner = new Diner {
                Id = 24, Name = "TestName", Cuisine = FoodType.German
            };

            var mapTester = MapTester.ForMap <Restaurant, Diner>()
                            .WhereMember(dest => dest.Cuisine).ShouldBeStringMatchFor(src => src.Cuisine);

            AssertExceptionNotThrown.WhenExecuting(() => mapTester.AssertMappedValues(restaurant, diner));

            diner.Cuisine = FoodType.Italian;

            AssertExceptionThrown
            .OfType <MapTesterException>()
            .WithMessageContaining("Mapping test failed for property \"Cuisine\". Expected<German>. Actual: <Italian>")
            .WhenExecuting(() => mapTester.AssertMappedValues(restaurant, diner));
        }
Esempio n. 15
0
        public void HiddenProperty_should_resolve_to_top_most_member()
        {
            var restaurantEditModel = new RestaurantEditModel {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };
            var restaurantModel = new Restaurant {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };

            var restaurantList = new RestaurantList {
                Restaurants = new[] { restaurantModel }
            };
            var editRestaurantList = new RestaurantEditList {
                Restaurants = new[] { restaurantEditModel }
            };

            MapTester.ForMap <RestaurantList, RestaurantEditList>()
            // ignored since the internal constructor of MapTester is what's being tested
            .IgnoringMember(dest => dest.Restaurants)
            .AssertMappedValues(restaurantList, editRestaurantList);
        }
Esempio n. 16
0
        public void MapTester_exception_should_prettify_ScenarioTestFailureException()
        {
            var source = new Source();
            var dummy  = new Dummy();

            string[] destPropertyNames =
                PropertyEnumerator.GetPublicInstanceReadWriteProperties(typeof(Dummy).GetTypeInfo()).Select(x => x.Name).ToArray();
            int propertyCount = destPropertyNames.Length;

            string message = string.Empty;

            try
            {
                MapTester.ForMap <Source, Dummy>().AssertMappedValues(source, dummy);
            }
            catch (MapTesterException ex)
            {
                message = ex.Message;
            }

            StringAssert.Contains(message, $"{propertyCount} properties tested. 0 passed. {propertyCount} failed.");
            StringAssert.DoesNotMatch(message, new Regex("cenario"));
        }
Esempio n. 17
0
 public void TestInitialize()
 {
     _source    = new RandomValuesHelper().CreateInstanceWithRandomValues <Source>();
     _mapTester = MapTester.ForMap <Source, Dest>();
 }