public void BaseClassMappingAndInheritedClassMappingIsRespected() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.CreateMap<SourceBase, DestinationBase>(customMapping: src => new DestinationBase { Test = src.ID }); mapper.CreateMap<SecondSourceInherited, SecondDestinationInherited>(customMapping: src => new SecondDestinationInherited { Bar = src.Foo }); var result = mapper.Map<SecondSourceInherited, SecondDestinationInherited>(new SecondSourceInherited { ID = 10, Foo = "test" }); Assert.AreEqual(10, result.Test); Assert.AreEqual("test", result.Bar); }
public void ClearMapCacheIsRespected() { var mapper = new MemberMapper(); mapper.CreateMap<SourceType, DestinationType>(customMapping: src => new { ID = src.ID * 10, Name = src.Name + src.Name }); var source = new SourceType { ID = 10, Name = "x" }; var result = mapper.Map<DestinationType>(source); Assert.AreEqual(100, result.ID); Assert.AreEqual("xx", result.Name); mapper.ClearMapCache(); result = mapper.Map<DestinationType>(source); Assert.AreEqual(10, result.ID); Assert.AreEqual("x", result.Name); }
public void MappingConditionIsRespectedForNestedMembers() { var mapper = new MemberMapper(); mapper.CreateMapProposal<SourceType, DestinationType>() .ForMember(dest => dest.Nested).OnlyIf(src => src.ID == 0) .FinalizeMap(); var source = new SourceType { ID = 10, Name = "X", Nested = new NestedSourceType { Foo = "Bla" } }; var result = mapper.Map<SourceType, DestinationType>(source); Assert.IsNull(result.Nested); source.ID = 0; result = mapper.Map<SourceType, DestinationType>(source); Assert.AreEqual("Bla", result.Nested.Foo); }
public void WithListStringToWithListString() { var mapper = new MemberMapper(); mapper.Options.Debug.DebugInformationEnabled = true; var source = new WithListofString { Foo = new List<string> { "test" } }; var result = mapper.Map(source, new WithListofString()); Assert.IsTrue(object.ReferenceEquals(source.Foo, result.Foo)); var x = result; result.Foo = x.Foo; var newResult = mapper.Map(source, result); Assert.IsTrue(object.ReferenceEquals(result, newResult)); Assert.IsTrue(object.ReferenceEquals(result.Foo, newResult.Foo)); Assert.AreEqual(1, newResult.Foo.Count); var otherSource = new WithListofString { Foo = new List<string> { "test1" } }; mapper.Map(otherSource, result); Assert.IsTrue(object.ReferenceEquals(result.Foo, newResult.Foo)); Assert.AreEqual(2, result.Foo.Count); }
public void DefaultNestingDepthWorksAsExpected() { var mapper = new MemberMapper(); var nested = new NestedA { Bar = "A", Nested = new NestedB { Bar = "B", Nested = new[] { new NestedC { Bar = "C", Nested = new NestedD { Bar = "D" } } } } }; var clone = mapper.DeepClone(nested); Assert.IsNotNull(clone.Nested); Assert.IsNotNull(clone.Nested.Nested); Assert.IsNull(clone.Nested.Nested.Single().Nested); }
public void CustomMappingIsRespected() { var mapper = new MemberMapper(); mapper.CreateMap<Customer, SimpleCustomerDto>(customMapping: c => new { FullName = c.FirstName + " " + c.LastName.ToString(), AddressLine = c.Address.Street + " " + c.Address.HouseNumber, EmailAddress = c.EmailAddress.Address }); var customer = new Customer { FirstName = "Test", LastName = "Test", EmailAddress = new EmailAddress { Address = "*****@*****.**" }, CustomerID = 1, Address = new Address { Street = "test", HouseNumber = "10", ZipCode = "1111AB", City = "test" } }; var dto = mapper.Map<Customer, SimpleCustomerDto>(customer); }
public void ChangedNestingDepthWorksAsExpected() { var mapper = new MemberMapper(); var nested = new NestedA { Bar = "A", Nested = new NestedB { Bar = "B", Nested = new[] { new NestedC { Bar = "C", Nested = new NestedD { Bar = "D" } } } } }; mapper.Options.Cloning.MaxCloneDepth = 1; var clone = mapper.DeepClone(nested); Assert.IsNotNull(clone.Nested); Assert.IsNull(clone.Nested.Nested); }
//[TestMethod] public void MappingConditionIsRespectedForNestedCollectionMembers() { var mapper = new MemberMapper(); int i = 10; mapper.CreateMapProposal<SourceTypeCollection, DestinationTypeCollection>() .ForMember(dest => dest.Nested).OnlyIf(src => i == 0) .FinalizeMap(); var source = new SourceTypeCollection { Nested = new List<NestedSourceType> { new NestedSourceType { Foo = "Bla" } } }; var result = mapper.Map<SourceTypeCollection, DestinationTypeCollection>(source); Assert.IsNull(result.Nested); //i = 0; result = mapper.Map<SourceTypeCollection, DestinationTypeCollection>(source); Assert.AreEqual("Bla", result.Nested.Single().Foo); }
public void ComplexTypeMappingRespectsExistingMapping() { var mapper = new MemberMapper(); var proposed = mapper.CreateMap(typeof(ComplexSourceType), typeof(ComplexDestinationType), (s, p, option) => { if (s.Name == "Name") { option.IgnoreMember(); } }); proposed.FinalizeMap(); var source = new ComplexSourceType { ID = 5, Complex = new NestedSourceType { ID = 10, Name = "test" } }; var destination = mapper.Map<ComplexSourceType, ComplexDestinationType>(source); Assert.AreEqual(destination.ID, 5); Assert.IsNotNull(destination.Complex); Assert.AreNotEqual(destination.Complex.Name, source.Complex.Name); }
/// <summary> /// Returns a mapper for a certain profile, and creates it if the mapper does not exist yet. /// </summary> /// <param name="profile">The profile for which you want to have a mapper.</param> /// <returns></returns> public IMemberMapper this[string profile] { get { IMemberMapper mapper; if (!mappers.TryGetValue(profile, out mapper)) { mapper = new MemberMapper { Profile = profile }; mapper.MapRepository = this.MapRepository; mapper.Options = this.Options; lock (mappers) { if (!mappers.ContainsKey(profile)) { CreateMapper(profile, mapper); } } } return mapper; } set { CreateMapper(profile, value); } }
public void NestedPropertyWithCustomMappingWorks() { var mapper = new MemberMapper(); mapper.CreateMap<Address, AddressDto>(src => new AddressDto { CountryName = src.Country.Name }); var projection = mapper.Project<CustomerSingleAddress, CustomerSingleAddressDto>(); var method = projection.Compile(); var result = method(new CustomerSingleAddress { Address = new Address { Country = new Country { Name = "X" } } }); Assert.AreEqual("X", result.Address.CountryName); }
public void RecursiveRelationshipsAreMappedCorrectly() { var map = new MemberMapper(); var source = new SourceType { ID = 10, Children = new List<SourceType> { new SourceType { ID = 11, }, new SourceType { ID = 12, Children = new List<SourceType> { new SourceType { ID = 13 } } } } }; var result = map.Map<SourceType, DestinationType>(source); }
public void DecimalToIntWorks() { var mapper = new MemberMapper(); mapper.Map <DecimalType, IntType>(new DecimalType { Foo = 10m }); }
public void InvokingMapWithoutParameterAsMapWithParameterThrows() { var mapper = new MemberMapper(); mapper.CreateMap<SourceType, DestinationType>(); var result = mapper.Map(new SourceType(), new DestinationType(), 1); }
public void IntIsMappedToEnum() { var mapper = new MemberMapper(); var result = mapper.Map<IntClass, EnumClass>(new IntClass { Foo = 2 }); Assert.AreEqual(Foo.B, result.Foo); }
public void GetMapForMapWithParameterThrowsForMapWithoutParameter() { var mapper = new MemberMapper(); mapper.CreateMap <SourceType, DestinationType>(); mapper.GetMap <SourceType, DestinationType, int>(); }
public void GetMapWorks() { var mapper = new MemberMapper(); mapper.CreateMap <SourceType, DestinationType>(); Assert.IsNotNull(mapper.GetMap <SourceType, DestinationType>()); }
public void HasMapWorks() { var mapper = new MemberMapper(); mapper.CreateMap <SourceType, DestinationType>(); Assert.IsTrue(mapper.HasMap <SourceType, DestinationType>()); }
public void UsingNonGenericMapAsGenericWorks() { var mapper = new MemberMapper(); mapper.CreateMap(typeof(SourceType), typeof(DestinationType)); var result = mapper.Map <SourceType, DestinationType>(new SourceType()); }
public void NonGenericMapForMapWithParameterThrowsForMapWithoutParameter() { var mapper = new MemberMapper(); mapper.CreateMap(typeof(SourceType), typeof(DestinationType)); mapper.Map <SourceType, DestinationType, int>(new SourceType(), 0); }
public void EnumIsMappedToInt() { var mapper = new MemberMapper(); var result = mapper.Map<EnumClass, IntClass>(new EnumClass { Foo = Foo.B }); Assert.AreEqual(2, result.Foo); }
public Column(QuerySource.Table table, SqlField field, MemberMapper mapper) { Field = field; Table = table; Mapper = mapper; ParsingTracer.WriteLine(this); }
public MembersPaged Search(int pageIndex, int pageSize, string searchTerm, out int totalRecords) { var members = _memberService.GetAll(pageIndex, pageSize, out totalRecords) .Where(x => x.Username.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0); var mappedMembers = MemberMapper.MapMember(members.Select(x => x.Id).ToList()); return(MemberMapper.MapPagedMember(mappedMembers, pageIndex, pageSize, totalRecords)); }
public void MapForMapWithParameterThrowsForMapWithoutParameter() { var mapper = new MemberMapper(); mapper.CreateMap<SourceType, DestinationType>(); mapper.Map<SourceType, DestinationType, int>(new SourceType(), 0); }
public void ThrowsWhenTypesAreIncompatibleOnNestedMember() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.CreateMap <IncompatibleSourceWithNested, IncompatibleDestinationWithNested>(); }
public void NonNullableGetsMappedToNullableNonPrimitiveVT() { var mapper = new MemberMapper(); var result = mapper.Map<NonNullableSourceNonPrimitiveVT, NullableDestinationNonPrimitiveVT>(new NonNullableSourceNonPrimitiveVT { ID = 10 }); Assert.AreEqual(10, result.ID.Value); }
public void FlattenHierarchyIgnoresMethods() { var mapper = new MemberMapper(); var result = mapper.Map(new MethodContainer { Method = new MethodSource() }, new MethodDto()); Assert.AreEqual(0, result.MethodID); }
public void DictionaryToIDictionaryIsReferenceEqual() { var mapper = new MemberMapper(); var source = new DictionaryClass { Foo = new Dictionary<int, string>() }; var result = mapper.Map(source, new IDictionaryClass()); Assert.IsTrue(object.ReferenceEquals(source.Foo, result.Foo)); }
public void GetMapWorks() { var mapper = new MemberMapper(); mapper.CreateMap<SourceType, DestinationType>(); Assert.IsNotNull(mapper.GetMap<SourceType, DestinationType>()); }
public void FlattenHierarchyWorks() { var mapper = new MemberMapper(); var result = mapper.Map(new CompanyContainer { Company = new Company { ID = 10 } }, new CompanyDto()); Assert.AreEqual(10, result.CompanyID); }
public void HasMapWorks() { var mapper = new MemberMapper(); mapper.CreateMap<SourceType, DestinationType>(); Assert.IsTrue(mapper.HasMap<SourceType, DestinationType>()); }
public void NonNullableToNullableWithProjectionsWorksAsExpected() { var mapper = new MemberMapper(); var result = mapper.Project<EnumSourceType, EnumDestinationType>().Compile()(new EnumSourceType { Foo = FooEnum.B }); Assert.AreEqual(FooEnum.B, result.Foo); }
public void DoesNotThrowWhenTypesAreIncompatibleButPropertyGetsIgnoredOnNestedMember() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.CreateMapProposal <IncompatibleSourceWithNested, IncompatibleDestinationWithNested>() .ForMember(s => s.Foo.Test).Ignore().FinalizeMap(); }
public void Option_AllowNullReferenceExceptionWhenSourceIsNull_Works() { SourceType source = null; var mapper = new MemberMapper(); mapper.Options.Safety.IfSourceIsNull = SourceObjectNullOptions.AllowNullReferenceExceptionWhenSourceIsNull; mapper.Map<SourceType, DestinationType>(source); }
/// <summary> /// Visits an <see cref="MemberMapper"/> and adds it's differences to the <see cref="DiagnosticBag{CompatDifference}"/>. /// </summary> /// <param name="member">The mapper to visit.</param> public override void Visit(MemberMapper member) { if (member == null) { throw new ArgumentNullException(nameof(member)); } AddDifferences(member); }
public void PrivateSetterDoesNotCauseUnexpectedException() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; var result = mapper.Map <SourceType, DestinationType>(new SourceType { Foo = 1 }); }
//[TestMethod] public void AutoConvertWorks() { var mapper = new MemberMapper(); mapper.CreateMap <SourceType, DestinationType>(src => new { Bar = src.Foo }); }
public IList <Member> GetLatestUsers(int amountToTake) { var ids = _memberService.GetMembersByMemberType(AppConstants.MemberTypeAlias) .OrderByDescending(x => x.CreateDate) .Take(amountToTake) .Select(x => x.Id); return(MemberMapper.MapMember(ids.ToList())); }
public void Test4() { ObjectMapper om = Map.GetObjectMapper(typeof(Object5)); MemberMapper mm1 = om["Object3.Object2.Field1", true]; MemberMapper mm2 = om["Object3.Object4.Str1", true]; Assert.IsNotNull(mm1); Assert.IsNotNull(mm2); }
public void Can_change_MemberMapper() { var memberMapper = new MemberMapper(new FieldMatcher()); var model = new Model(); model.SetMemberMapper(memberMapper); Assert.Same(memberMapper, model.GetMemberMapper()); }
public void FlattenHierarchyOnlyUsesAvailableGetters() { var mapper = new MemberMapper(); var result = mapper.Map(new CompanyContainer { Company = new Company { ID = 10, Name = "Test" } }, new CompanyDto()); Assert.AreEqual(10, result.CompanyID); Assert.AreEqual(null, result.CompanyName); }
public List <Member> GetUnAuthorisedMembers() { // Get members that last activity date is valid var ids = _memberService.GetAllMembers() .Where(x => !x.IsApproved && !x.IsLockedOut) .Select(x => x.Id); return(MemberMapper.MapMember(ids.ToList())); }
public void DoesNotThrowWhenTypesAreIncompatibleButPropertyGetsIgnoredOnNestedMember() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.CreateMapProposal<IncompatibleSourceWithNested, IncompatibleDestinationWithNested>() .ForMember(s => s.Foo.Test).Ignore().FinalizeMap(); }
public IList <Member> GetActiveMembers() { // Get members that last activity date is valid var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers); var ids = _memberService.GetMembersByPropertyValue(AppConstants.PropMemberLastActiveDate, date, ValuePropertyMatchType.GreaterThan) .Where(x => x.IsApproved && !x.IsLockedOut) .Select(x => x.Id); return(MemberMapper.MapMember(ids.ToList())); }
public void ConversionFunctionIsValidatedOnArgumentType() { var mapper = new MemberMapper(); mapper.CreateMap<Source, Destination>(options: (ctx, options) => { Expression<Func<string, int>> func = (s => s.Length); options.Convert(func); }); }
public void NullableToNullableWorksNonPrimitiveVT() { var mapper = new MemberMapper(); var result = mapper.Map <NullableSourceNonPrimitiveVT, NullableSourceNonPrimitiveVT>(new NullableSourceNonPrimitiveVT { ID = 10 }); Assert.AreEqual(10, result.ID); }
public void SettingProfileSetsIt() { var profiles = new MapCollection(); var mapper = new MemberMapper(); profiles["create"] = mapper; Assert.AreEqual(mapper, profiles["create"]); }
public void ConversionFunctionIsValidatedOnArgumentCount() { var mapper = new MemberMapper(); mapper.CreateMap <Source, Destination>(options: (ctx, options) => { Expression <Func <string, string, string, int> > func = ((s, y, z) => s.Length); options.Convert(func); }); }
public void DynamicInvokeWithSourceNullThrows() { var mapper = new MemberMapper(); mapper.Options.Safety.IfSourceIsNull = SourceObjectNullOptions.AllowNullReferenceExceptionWhenSourceIsNull; SourceType type = null; var result = mapper.Map <DestinationType>(type); }
public void DeepCloneThrowsIfOptionIsTurnedOff() { var mapper = new MemberMapper(); mapper.Options.Conventions.MakeCloneIfDestinationIsTheSameAsSource = false; var source = new SourceType { Name = "test", Value = 1, Values = new[] { 1 } }; var result = mapper.DeepClone(source); }
public void NullableToNullableWorks() { var mapper = new MemberMapper(); var result = mapper.Map <NullableSource, NullableSource>(new NullableSource { ID = 10 }); Assert.AreEqual(10, result.ID); }
public void NullableWithNullValueGetsMappedToNonNullable() { var mapper = new MemberMapper(); var result = mapper.Map <NullableSource, NonNullableDestination>(new NullableSource { ID = null }); Assert.AreEqual(default(int), result.ID); }
public void NonNullableGetsMappedToNullable() { var mapper = new MemberMapper(); var result = mapper.Map <NonNullableSource, NullableDestination>(new NonNullableSource { ID = 10 }); Assert.AreEqual(10, result.ID.Value); }
public void NullableToNonNullableWithProjectionsWorksAsExpectedWithSourceNotNull() { var mapper = new MemberMapper(); var result = mapper.Project <EnumDestinationType, EnumSourceType>().Compile()(new EnumDestinationType { Foo = FooEnum.B }); Assert.AreEqual(FooEnum.B, result.Foo); }
/// <summary> /// Gets the FAQ categories. /// </summary> /// <param name="auditLogBO">The audit log bo.</param> /// <returns></returns> public async Task <IEnumerable <MemberFaqCategoryBO> > GetFaqCategories(AuditLogBO auditLogBO) { var memFaqCategoryRepository = _unitOfWork.GetRepository <Faqcategory>(); var memFaqCategories = await memFaqCategoryRepository.GetPagedListAsync(a => a, s => s.PortalId == (int)Portals.MemberPortal, pageIndex : BrokerConstants.PAGE_INDEX, pageSize : BrokerConstants.PAGE_SIZE); //await AuditMapper.AuditLogging(auditLogBO, null, AuditAction.Select, null); return(MemberMapper.Map(memFaqCategories).OrderBy(s => s.CatgId).ToList()); }
public void MappingFunctionIsSetCorrectly() { var mapper = new MemberMapper(); var map = mapper.CreateMap(typeof(Source), typeof(Destination)); Assert.IsNotNull(map.MappingFunction); Assert.IsNotNull(map as MemberMap <Source, Destination>); Assert.IsNotNull(((MemberMap <Source, Destination>)map).MappingFunction); }
private static void PrimaryKeyMapper(Type memberType, MemberInfo memberInfo, MemberMapper mMapper) { var key = memberInfo.GetCustomAttribute <PrimaryKeyAttribute>(true); if (key != null) { mMapper.AutoId = key.AutoAssigned; mMapper.FieldName = _internalIdPropertyName; } }
public void Option_AllowNullReferenceExceptionWhenSourceIsNull_Works() { SourceType source = null; var mapper = new MemberMapper(); mapper.Options.Safety.IfSourceIsNull = SourceObjectNullOptions.AllowNullReferenceExceptionWhenSourceIsNull; mapper.Map <SourceType, DestinationType>(source); }
public void AsProjectableFirstThrowsWhenLessThanOne() { var mapper = new MemberMapper(); var source = new List<SourceType> { }; var result = source.AsQueryable().AsProjectable().First(mapper.Project<SourceType, DestinationType>()); }
public void NullableWithNonNullValueGetsMappedToNonNullableNonPrimitiveVT() { var mapper = new MemberMapper(); var result = mapper.Map <NullableSourceNonPrimitiveVT, NonNullableDestinationNonPrimitiveVT>(new NullableSourceNonPrimitiveVT { ID = 10 }); Assert.AreEqual(10, result.ID); }