コード例 #1
0
ファイル: ManualMapperTest.cs プロジェクト: LuanNunes/MOO
        public void ManualMapperMapErrorTest()
        {
            var target = new ManualMapper<FromTestClass, ToTestClass>();
            var source = new FromTestClass() { Id = 5, Description = "test" };

            var targetObj = new ToTestClass();
            target.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); });
            target.Map(source, targetObj);
        }
コード例 #2
0
ファイル: ManualMapperTests.cs プロジェクト: dclucas/MOO
        public void Map_InvalidMappingAction_WrapsAndThrows()
        {
            var sut = new ManualMapper<FromTestClass, ToTestClass>();
            var source = new FromTestClass {Id = 5, Description = "test"};

            var targetObj = new ToTestClass();
            sut.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); });
            Should.Throw<MappingException>(() => sut.Map(source, targetObj));
        }
コード例 #3
0
ファイル: ManualMapperTests.cs プロジェクト: jangocheng/MOO
        public async Task Map_ManualMappingsWithTarget_MapsCorrectly()
        {
            var source = new FromTestClass();
            var sut    = SetupTest(source);
            var target = new ToTestClass();
            await sut.MapAsync(source, target);

            CheckMapping(source, target);
        }
コード例 #4
0
        public void MapExplicit()
        {
            var from = new FromTestClass();
            var to   = new ToTestClass();

            Mapper.MapExplicit(from, to, new[] { "PublicProp" });

            Assert.AreEqual(to.PublicField, 2);
            Assert.AreEqual(to.PublicProp, 1);
            Assert.AreEqual(to.PublicReadOnlyProp, 2);
        }
コード例 #5
0
        public void MapTestExceptions()
        {
            var from = new FromTestClass();
            var to   = new ToTestClass();

            Mapper.MapExcept(from, to, "PublicField");

            Assert.AreEqual(to.PublicField, 2);
            Assert.AreEqual(to.PublicProp, 1);
            Assert.AreEqual(to.PublicReadOnlyProp, 1);
        }
コード例 #6
0
        public void MapBasic()
        {
            var from = new FromTestClass();
            var to   = new ToTestClass();

            Mapper.MapExcept(from, to);

            Assert.AreEqual(to.PublicField, 1);
            Assert.AreEqual(to.PublicProp, 1);
            Assert.AreEqual(to.PublicReadOnlyProp, 1);
        }
コード例 #7
0
ファイル: ManualMapperTests.cs プロジェクト: jangocheng/MOO
        public void Map_InvalidMappingAction_WrapsAndThrows()
        {
            var sut    = new ManualMapper <FromTestClass, ToTestClass>();
            var source = new FromTestClass {
                Id = 5, Description = "test"
            };

            var targetObj = new ToTestClass();

            sut.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); });
            Should.Throw <MappingException>(() => sut.Map(source, targetObj));
        }
コード例 #8
0
ファイル: ManualMapperTest.cs プロジェクト: LuanNunes/MOO
 public void ManualMapperMapTest()
 {
     var target = new ManualMapper<FromTestClass, ToTestClass>();
     FromTestClass source = new FromTestClass() { Id = 5, Description = "test" };
     var targetObj = new ToTestClass();
     target.AddMappingAction("Id", "Code", (f, t) => t.Code = f.Id);
     target.AddMappingAction("Description", "Name", (f, t) => t.Name = f.Description);
     target.AddMappingAction("SampleDate", "SampleDateInStrFormat", (f, t) => t.SampleDateInStrFormat = f.SampleDate.ToShortDateString());
     target.Map(source, targetObj);
     Assert.AreEqual(source.Id, targetObj.Code);
     Assert.AreEqual(source.Description, targetObj.Name);
     Assert.AreEqual(source.SampleDate.ToShortDateString(), targetObj.SampleDateInStrFormat);
 }
コード例 #9
0
ファイル: ManualMapperTest.cs プロジェクト: dcollioni/MOO
        public void ManualMapperMapErrorTest()
        {
            var target = new ManualMapper <FromTestClass, ToTestClass>();
            var source = new FromTestClass()
            {
                Id = 5, Description = "test"
            };

            var targetObj = new ToTestClass();

            target.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); });
            target.Map(source, targetObj);
        }
コード例 #10
0
ファイル: ManualMapperTest.cs プロジェクト: dcollioni/MOO
        public void ManualMapperMapTest()
        {
            var           target = new ManualMapper <FromTestClass, ToTestClass>();
            FromTestClass source = new FromTestClass()
            {
                Id = 5, Description = "test"
            };
            var targetObj = new ToTestClass();

            target.AddMappingAction("Id", "Code", (f, t) => t.Code          = f.Id);
            target.AddMappingAction("Description", "Name", (f, t) => t.Name = f.Description);
            target.AddMappingAction("SampleDate", "SampleDateInStrFormat", (f, t) => t.SampleDateInStrFormat = f.SampleDate.ToShortDateString());
            target.Map(source, targetObj);
            Assert.AreEqual(source.Id, targetObj.Code);
            Assert.AreEqual(source.Description, targetObj.Name);
            Assert.AreEqual(source.SampleDate.ToShortDateString(), targetObj.SampleDateInStrFormat);
        }
コード例 #11
0
ファイル: ManualMapperTests.cs プロジェクト: dclucas/MOO
 private void CheckMapping(FromTestClass source, ToTestClass target)
 {
     source.Id.ShouldBe(target.Code);
     source.Description.ShouldBe(target.Name);
     source.SampleDate.ToShortDateString().ShouldBe(target.SampleDateInStrFormat);            
 }
コード例 #12
0
ファイル: ManualMapperTests.cs プロジェクト: dclucas/MOO
 public async Task Map_ManualMappingsWithTarget_MapsCorrectly()
 {
     var source = new FromTestClass();
     var sut = SetupTest(source);
     var target = new ToTestClass();
     await sut.MapAsync(source, target);
     CheckMapping(source, target);
 }
コード例 #13
0
ファイル: ManualMapperTests.cs プロジェクト: jangocheng/MOO
 private void CheckMapping(FromTestClass source, ToTestClass target)
 {
     source.Id.ShouldBe(target.Code);
     source.Description.ShouldBe(target.Name);
     source.SampleDate.ToShortDateString().ShouldBe(target.SampleDateInStrFormat);
 }