示例#1
0
        public void DictionaryBaseTest()
        {
            var map = MapFactory.CreateMapRule <InnType, OutType2>();

            //Adding mapping rule for field that does not match on name.
            map.GetRule <InnType, OutType2>()
            .Add(type => type.DesimalValue, type => type.DesimalValue1, BasicTypes.Convertable);
            var target = new Dictionary <int, InnType>
            {
                {
                    1,
                    new InnType
                    {
                        DateTimeValue = DateTime.Now,
                        MyInts        = new List <int>(),
                        StringValue   = "test1",
                        DesimalValue  = 1
                    }
                },
                {
                    2,
                    new InnType
                    {
                        DateTimeValue = DateTime.Now,
                        MyInts        = new List <int>(),
                        StringValue   = "test1",
                        DesimalValue  = 2
                    }
                }
            };
            var result = target.Map <int, InnType>().To <string, OutType2>(map);

            Assert.AreEqual(2, result.Count);
        }
示例#2
0
        public void AutoMapperRemoveNodeDictionaryConvertTest()
        {
            MapFactory.ResetAllMaps();
            var map = MapFactory.CreateMapRule <DictionaryTestInn, DictionaryTestOut>();

            map.GetRule <DictionaryTestInn, DictionaryTestOut>().RemoveMapping("TypeToString");
            var target = GetDictionaryTarget();
            var timer  = Stopwatch.StartNew();
            var result = target.Map().To <DictionaryTestOut>(map);

            Assert.AreEqual(1, result.MyDictionary.Count);
            var firstTime = timer.ElapsedMilliseconds;

            timer.Reset();
            result = target.Map().To <DictionaryTestOut>(map);
            Assert.AreEqual(1, result.MyDictionary.Count);
            var lastTime = timer.ElapsedMilliseconds;

            if (lastTime > firstTime && lastTime != firstTime)
            {
                Assert.Fail("The first run took more time than the last {0}>{1}", lastTime, firstTime);
            }
            Assert.AreEqual(1, result.YourDictionary.Count);
            Assert.AreEqual("SubTest1", result.YourDictionary.First().Value.Child.First().Name);
            Assert.AreEqual(2, result.StringToType.Count);
            Assert.IsNull(result.TypeToString);
        }
示例#3
0
        public void AutoMapperAddExpanderNodeDictionaryConvertTest()
        {
            MapFactory.ResetAllMaps();
            var map = MapFactory.CreateMapRule <DictionaryTestInn, DictionaryTestOut>();

            map.GetRule <DictionaryTestInn, DictionaryTestOut>()
            .RemoveMapping("TypeToString")
            .Add("GivenName", "ExpanderField", BasicTypes.Expander);
            map.AddMap <DictionaryTestInn, FlatteningInput>(new Dictionary <string, string> {
                { "GivenName", "FirstName" }, { "SurName", "LastName" }
            });
            var target = GetDictionaryTarget();
            var timer  = Stopwatch.StartNew();
            var result = target.Map().To <DictionaryTestOut>(map);

            Assert.AreEqual(1, result.MyDictionary.Count);
            var firstTime = timer.ElapsedMilliseconds;

            timer.Reset();
            result = target.Map().To <DictionaryTestOut>(map);
            Assert.AreEqual(1, result.MyDictionary.Count);
            var lastTime = timer.ElapsedMilliseconds;

            if (lastTime > firstTime && lastTime != firstTime)
            {
                Assert.Fail("The first run took more time than the last {0}>{1}", lastTime, firstTime);
            }
            Assert.AreEqual(1, result.YourDictionary.Count);
            Assert.AreEqual("SubTest1", result.YourDictionary.First().Value.Child.First().Name);
            Assert.AreEqual(2, result.StringToType.Count);
            Assert.IsNull(result.TypeToString);
            Assert.AreEqual("Jonas", result.ExpanderField.FirstName);
        }
示例#4
0
        public void AutoMapperDictionaryTest()
        {
            MapFactory.ResetAllMaps();
            var map = MapFactory.CreateMapRule <DictionaryTestInn, DictionaryTestOut>();

            map = MapFactory.CreateMapRule <DictionaryTestInn, DictionaryTestOut>();
            Assert.AreEqual(2, map.Rules.Count);
            Assert.IsTrue(map.Rules.First().Value.Fields.First().Value.Convertible);
        }
示例#5
0
        public void DottedSourceTest()
        {
            MapFactory.CreateMapRule <DottedSource, OutType>()
            .Add(s => s.Dotted.StringValue, d => d.StringValue1);
            var target = new DottedSource {
                Dotted = new InnType {
                    StringValue = "test"
                }
            };
            var result = target.Map().To <OutType>();

            Assert.AreEqual("test", result.StringValue1);
        }
示例#6
0
        public void EnumerableListObjectTestWithAutoMapping()
        {
            MapFactory.ResetAllMaps();
            var map    = MapFactory.CreateMapRule <InnTypeEnum, OutTypeEnum>();
            var target = CreateTestTarget();
            var timer  = Stopwatch.StartNew();
            var result = target.Map().To <OutTypeEnum>();

            Assert.AreEqual(3, result.Count());
            Assert.IsTrue(timer.ElapsedMilliseconds < 20);
            Assert.IsNotNull(result);

            Assert.AreEqual((object)target.First().DateTimeValue, result.First().DateTimeValue);
            Assert.AreEqual(3, result.First().Child.Count());
            Assert.AreEqual(2, result.First().Child.First().Child.Count());
        }
示例#7
0
        public void AutoMapperDictionaryConvertTest()
        {
            MapFactory.ResetAllMaps();
            var map    = MapFactory.CreateMapRule <DictionaryTestInn, DictionaryTestOut>();
            var target = GetDictionaryTarget();
            var timer  = Stopwatch.StartNew();
            var result = target.Map().To <DictionaryTestOut>(map);

            Assert.AreEqual(1, result.MyDictionary.Count);
            var firstTime = timer.ElapsedMilliseconds;

            timer.Reset();
            result = target.Map().To <DictionaryTestOut>(map);
            Assert.AreEqual(1, result.MyDictionary.Count);
            var lastTime = timer.ElapsedMilliseconds;

            Assert.AreEqual(1, result.YourDictionary.Count);
            Assert.AreEqual("SubTest1", result.YourDictionary.First().Value.Child.First().Name);
            Assert.AreEqual(2, result.StringToType.Count);
            Assert.AreEqual(2, result.TypeToString.Count);
        }
示例#8
0
        public void Perf_ListStringsOnlyObjectTestWithAutoMapping()
        {
            MapFactory.ResetAllMaps();
            var map = MapFactory.CreateMapRule <StringInnType, StringOutType1>();
            //warm-up run
            var wUpResult = loadTestStringTarget.Take(10).Map().To <StringOutType1>(map).ToList();

            var timer  = Stopwatch.StartNew();
            var result = loadTestStringTarget.Map().To <StringOutType1>(map);

            Assert.AreEqual(100002, result.Count());
            timer.Stop();
            var time = timer.ElapsedTicks;

            Assert.IsNotNull(result);
            Assert.AreEqual((object)loadTestStringTarget.First().Value1, result.First().Value1);
            Assert.AreEqual((object)loadTestStringTarget.First().Value3, result.First().Value3);
            if (new TimeSpan(time).TotalMilliseconds > 250)
            {
                Assert.Fail("Mapping took {0}", new TimeSpan(time));
            }
        }
示例#9
0
        public void Perf_ListObjectTestWithAutoMapping()
        {
            MapFactory.ResetAllMaps();
            var map = MapFactory.CreateMapRule <InnType, OutType2>();
            //warm-up run
            var wUpResult = loadTestTarget.Take(10).Map().To <OutType2>(map).ToList();

            var timer  = Stopwatch.StartNew();
            var result = loadTestTarget.Map().To <OutType2>(map);

            Assert.AreEqual(100002, result.Count());
            timer.Stop();
            var time = timer.ElapsedTicks;

            Assert.IsNotNull(result);
            Assert.AreEqual((object)loadTestTarget.First().DateTimeValue, result.First().DateTimeValue);
            Assert.AreNotEqual((object)loadTestTarget.First().DesimalValue, result.First().DesimalValue1);
            if (new TimeSpan(time).TotalMilliseconds > 350)
            {
                Assert.Fail("Mapping took {0}", new TimeSpan(time));
            }
            #region comparison with IL
            //Just for comparison with pure IL and Linq
            //timer.Restart();
            //var ilTest = (from i in loadTestTarget
            //              select
            //                  new OutType2
            //                  {
            //                      DateTimeValue = i.DateTimeValue,
            //                      DesimalValue1 = i.DesimalValue,
            //                      StringValue = i.StringValue,
            //                      MyInts = i.MyInts == null ? null : (from s in i.MyInts select s.ToString()).ToArray()
            //                  }).ToList();
            //Assert.AreEqual(100002, ilTest.Count());
            //var referenceTime = timer.ElapsedTicks;
            //if (referenceTime * 250 < time)
            //    Assert.Fail("Mapping took {0} vs reference {1}", time, referenceTime);
            #endregion
        }
示例#10
0
        public void MergeDataWithSameBaseType()
        {
            MapFactory.CreateMapRule <InnType, InnType>(true).GetRule().RemoveMapping("MyInts").RemoveMapping("DesimalValue");
            var inValue = new InnType
            {
                DateTimeValue = DateTime.Now,
                MyInts        = new List <int>(),
                StringValue   = "Updated string",
                DesimalValue  = 100
            };
            var targetValue = new InnType
            {
                DateTimeValue = DateTime.Now.AddYears(-1),
                MyInts        = new List <int>(),
                StringValue   = "original string",
                DesimalValue  = 0
            };
            var newTarget = inValue.Map().To(targetValue);

            Assert.AreNotSame(inValue, newTarget);
            Assert.AreEqual(inValue.StringValue, newTarget.StringValue);
            Assert.AreEqual(inValue.DateTimeValue, newTarget.DateTimeValue);
            Assert.AreNotEqual(inValue.DesimalValue, newTarget.DesimalValue);
        }
示例#11
0
        public void AutoMapperTest()
        {
            var map = MapFactory.CreateMapRule <InnTypeEnum, OutTypeEnum>();

            Assert.AreEqual(2, map.Rules.Count);
        }
示例#12
0
 public void Register()
 {
     MapFactory.CreateMapRule <ICacheSettings, ICacheSettings>().GetRule().RemoveMapping("Environment");
     MapFactory.CreateMapRule <IServiceHostParameter, PropertyRequest>().Add(s => s.Name, t => t.PropertyName).Add(s => s.ServiceHost.Name, t => t.ParentContainer);
     MapFactory.CreateMapRule <IEnvironmentParameter, PropertyRequest>().Add(s => s.Name, t => t.PropertyName).Add(s => s.Environment.ConfigSet.Id, t => t.ParentContainer).Add(s => s.Environment.ConfigSet.Id, t => t.SubContainer);
 }