Exemplo n.º 1
0
        public void StrategyUsedTo_MapSourceToTarget()
        {
            var testPlugin = new MockHostPlugin();

            testPlugin.AddPluginType <TestMapStrategyOneToTwo>();

            var testSrcObj = new TestMapTypeOne
            {
                Values = new[] { 30, 5, 88, 33, 83 }
            };
            TestMapTypeTwo testTgtObj = null;

            ContainerFixture.Test(fixture =>
            {
                var testResult = fixture.Arrange
                                 .Container(c =>
                {
                    c.RegisterPlugins(testPlugin);
                    c.RegisterPlugin <MappingPlugin>();
                })
                                 .Act.OnServices(s =>
                {
                    var mapper = s.GetService <IObjectMapper>();
                    testTgtObj = mapper.Map <TestMapTypeTwo>(testSrcObj);
                });

                testResult.Assert.State(() =>
                {
                    Assert.NotNull(testTgtObj);
                    Assert.Equal(5, testTgtObj.Min);
                    Assert.Equal(88, testTgtObj.Max);
                    Assert.Equal(239, testTgtObj.Sum);
                });
            });
        }
Exemplo n.º 2
0
        public void StrategyUsedTo_MapTargetToSource()
        {
            var testPlugin = new MockHostPlugin();

            testPlugin.AddPluginType <TestMapStrategyOneToTwo>();

            var testSrcObj = new TestMapTypeTwo
            {
                Min = 5,
                Max = 60,
                Sum = 65
            };

            TestMapTypeOne testTgtObj = null;

            ContainerFixture.Test(fixture =>
            {
                var testResult = fixture.Arrange
                                 .Container(c =>
                {
                    c.RegisterPlugins(testPlugin);
                    c.RegisterPlugin <MappingPlugin>();
                })
                                 .Act.OnServices(s =>
                {
                    var mapper = s.GetService <IObjectMapper>();
                    testTgtObj = mapper.Map <TestMapTypeOne>(testSrcObj);
                });

                testResult.Assert.State(() =>
                {
                    Assert.NotNull(testTgtObj);
                    Assert.Equal(3, testTgtObj.Values.Length);
                    Assert.Contains(5, testTgtObj.Values);
                    Assert.Contains(60, testTgtObj.Values);
                    Assert.Contains(65, testTgtObj.Values);
                });
            });
        }
Exemplo n.º 3
0
        public void CanMapSourceToTarget_WithFactorySpecifiedStrategy()
        {
            var testPlugin = new MockHostPlugin();

            testPlugin.AddPluginType <TestMappingStrategyFactory>();

            var testSrcObj = new TestMapTypeThree
            {
                MaxAllowedValue = 70,
                Values          = new[] { 30, 5, 88, 60, 65, 33, 83 }
            };

            TestMapTypeTwo testTgtObj = null;

            ContainerFixture.Test(fixture =>
            {
                var testResult = fixture.Arrange
                                 .Container(c =>
                {
                    c.RegisterPlugins(testPlugin);
                    c.RegisterPlugin <MappingPlugin>();
                })
                                 .Act.OnServices(s =>
                {
                    var mapper = s.GetService <IObjectMapper>();
                    testTgtObj = mapper.Map <TestMapTypeTwo>(testSrcObj);
                });

                testResult.Assert.State(() =>
                {
                    Assert.NotNull(testTgtObj);
                    Assert.Equal(5, testTgtObj.Min);
                    Assert.Equal(65, testTgtObj.Max);
                    Assert.Equal(193, testTgtObj.Sum);
                });
            });
        }