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); }); }); }
public void NoMappingStrategyFound_ExceptionIsRaised() { var testPlugin = new MockHostPlugin(); var testSrcObj = new TestMapTypeOne { Values = new[] { 30, 5, 88, 33, 83 } }; ContainerFixture.Test(fixture => { var testResult = fixture.Arrange .Container(c => { c.RegisterPlugins(testPlugin); c.RegisterPlugin <MappingPlugin>(); }) .Act.OnServices(s => { var mapper = s.GetService <IObjectMapper>(); mapper.Map <TestInvalidMapType>(testSrcObj); }); testResult.Assert.Exception <InvalidOperationException>(ex => { Assert.Contains("Mapping strategy not found.", ex.Message); }); }); }
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); }); }); }