public void CreateMap_PersonToPersonSwedish() { SafeMap.CreateMap <Person, PersonSwedish>( cfg => { cfg.Map(x => x.Id, x => x.PersonId); cfg.Map(x => x.Name, x => x.Namn); cfg.Map(x => x.Age, x => x.Ålder); cfg.Map(x => x.Length, x => x.Längd); cfg.Map(x => x.BirthDate, x => x.Födelsedag); }); var person = new Person { Id = Guid.NewGuid(), Name = "Magnus Unger", Age = 38, Length = 1.85m, BirthDate = new DateTime(1977, 03, 04), }; var result = SafeMap.Convert <Person, PersonSwedish>(person); Assert.AreEqual(person.Id, result.PersonId); Assert.AreEqual(person.Name, result.Namn); Assert.AreEqual(person.Age, result.Ålder); Assert.AreEqual(person.Length, result.Längd); Assert.AreEqual(person.BirthDate, result.Födelsedag); }
public void CreateMap_NameValueCollectionToClassPropertyInt_StringIndexer() { SafeMap.CreateMap <NameValueCollection, ClassProperty <int> >( cfg => { cfg.MapGetIndexer((x, key) => x[key]); cfg.Map <string, int>("Value2", x => x.Value); }); var input = new NameValueCollection { { "Value2", "1337" } }; var result = SafeMap.Convert <NameValueCollection, ClassProperty <int> >(input); Assert.AreEqual(1337, result.Value); }
public void CreateMap_ClassPropertyIntToNameValueCollection_Add() { SafeMap.Configuration.SetConvertMethod <int, string>(i => i.ToString(CultureInfo.InvariantCulture)); SafeMap.CreateMap <ClassProperty <int>, NameValueCollection>( cfg => { cfg.MapSetIndexer <string>((x, key, val) => x.Add(key, val)); cfg.Map <int, string>(x => x.Value, "Value2"); }); var input = new ClassProperty <int> { Value = 1337 }; var result = SafeMap.Convert <ClassProperty <int>, NameValueCollection>(input); Assert.AreEqual("1337", result["Value2"]); }