public void WithSourceAddress() { var factory = MappingBuilder.DiscoverIn <Employee>().BuildFactory(); var mapper = factory.Create <Employee, EmployeeView>(); var source = new Employee { FirstName = "Homer", LastName = "Simpson", Age = 40, IsMale = true, HomeAddress = new Address { HouseNumber = 742, Street = "Evergreen Terrace", Town = "Springfield" } }; var target = mapper.Map(source); target.FirstName.ShouldBe(source.FirstName); target.LastName.ShouldBe(source.LastName); target.Age.ShouldBe(source.Age); target.IsMale.ShouldBe(source.IsMale); target.HomeAddress.ShouldBe("742 Evergreen Terrace, Springfield"); }
private ObjectsMapperBaseImpl BuildObjectsMapper( string MapperTypeName, Type from, Type to, IMappingConfigurator mappingConfigurator) { TypeBuilder typeBuilder = DynamicAssemblyManager.DefineMapperType(MapperTypeName); CreateTargetInstanceBuilder.BuildCreateTargetInstanceMethod(to, typeBuilder); var mappingBuilder = new MappingBuilder( this, from, to, typeBuilder, mappingConfigurator ); mappingBuilder.BuildCopyImplMethod(); ObjectsMapperBaseImpl result = (ObjectsMapperBaseImpl)Activator.CreateInstance(typeBuilder.CreateType()); result.Initialize(this, from, to, mappingConfigurator, mappingBuilder.storedObjects.ToArray()); return(result); }
public void MappingBuilder_SameAssemblyAddedTwice_AndDiscoverIn_ThrowsException() { var exception = Should.Throw<ArgumentException>(() => MappingBuilder.DiscoverIn<MappingBuilderTests>().AndDiscoverIn<MappingFactoryTests>()); exception.Message.ShouldStartWith("Already added mappings in assembly HyperMap.Tests"); }
public void StringMappingTest() { const string title = "My Title"; var mapping = new MappingBuilder <CaseFile>() .ForCreate() .Map(x => x.Title) .ForUpdate() .Map(x => x.Title) .GetMapping(); var obj = new CaseFile { Title = title }; var createValues = mapping.GetCreateValues(obj); var updateValues = mapping.GetUpdateValues(obj); Assert.IsNotNull(createValues); Assert.IsTrue(createValues.Count == 1); Assert.AreEqual(title, (string)createValues["Title"]); Assert.IsNotNull(updateValues); Assert.IsTrue(updateValues.Count == 1); Assert.AreEqual(title, (string)updateValues["Title"]); }
public void IntegerMappingTest() { const int status = 3; var mapping = new MappingBuilder <CaseFile>() .ForCreate() .Map(x => x.Status) .ForUpdate() .Map(x => x.Status) .GetMapping(); var obj = new CaseFile { Status = 3 }; var createValues = mapping.GetCreateValues(obj); var updateValues = mapping.GetUpdateValues(obj); Assert.IsNotNull(createValues); Assert.IsTrue(createValues.Count == 1); Assert.AreEqual(status, (int)createValues["Status"]); Assert.IsNotNull(updateValues); Assert.IsTrue(updateValues.Count == 1); Assert.AreEqual(status, (int)updateValues["Status"]); }
public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_ReturnsMappingFactory() { var services = new ServiceCollection(); var factory = MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services); factory.ShouldNotBeNull(); }
public void Issue_Should_Map_To_Redmine_Issue() { var redmineRepository = new RedmineRepository(); var mapper = MappingBuilder.Build(); var testIssue = MakeTestIssue(); var redmineIssue = mapper.Map <Issue>(testIssue); var commonIssue = mapper.Map <CommonRemineEntities.Issue>(redmineIssue); }
private void DefaultMappings() { var mappingBuilder = new MappingBuilder(new[] { new MappingFromFluent(null) }); mappingBuilder.FromAssemblyOf <IFluentMapsVisitor>(); foreach (var source in mappingBuilder.Sources) { SharedComponent(source, source.Description); } }
private MappingBuilder ResumeUploadRequest(string uploadLocationPath, long position, long length) { MappingBuilder builder = put(urlEqualTo(uploadLocationPath)).withHeader("Content-Length", equalTo(Convert.ToString(length - position))); if (position > 0) { builder = builder.withHeader("Content-Range", equalTo(format("bytes %d-%d/%d", position, length - 1, length))); } return(builder); }
public void MappingBuilder_WithCustomNamespace_BuildFactory_ReturnsFactory() { var options = new CompilerOptions { AssemblyName = "Test.Mappings" }; var factory = MappingBuilder.DiscoverIn<MappingBuilderTests>().BuildFactory(options); factory.ShouldNotBeNull(); }
private void DefaultMappings() { var mappingBuilder = new MappingBuilder(new[] { new MappingFromAttributes(_log) }); mappingBuilder.FromAssemblyOf <ITypedEntity>(); mappingBuilder.AddMapping(typeof(ITypedEntity).GetTypeInfo().Assembly, new InternalsMappingsSource(typeof(ITypedEntity).GetTypeInfo().Assembly)); foreach (var source in mappingBuilder.Sources) { _container.RegisterInstance(source, source.Description); } }
public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_AddsMappersIntoCollection() { var services = new ServiceCollection(); MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services); var provider = services.BuildServiceProvider(); var mapper2 = provider.GetService <IMapper <User, UserView> >(); mapper2.ShouldNotBeNull(); }
protected override void ScenarioSetup() { var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict); entityMapping.SetupGet(instance => instance.Type).Returns(typeof(IProduct)); MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >())) .Returns(new Dictionary <Type, IEntityMapping>() { { typeof(IProduct), entityMapping.Object } }); }
public void MappingFactoryExtensions_WithMappingFactory_RegisterWith_CollectionInstanceMatchesFactory() { var services = new ServiceCollection(); var factory = MappingBuilder.DiscoverIn <User>().BuildFactory().RegisterWith(services); var mapper1 = factory.Create <User, UserView>(); var provider = services.BuildServiceProvider(); var mapper2 = provider.GetService <IMapper <User, UserView> >(); mapper2.ShouldBe(mapper1); }
private void BuildMappingAssemblies(MappingBuilder builder, IEnumerable <Assembly> mappingAssemblies) { if (mappingAssemblies == null) { return; } foreach (var assembly in mappingAssemblies) { builder.FromAssembly(assembly); } }
private Mapping <SqlStorageModel <TEntity>, SqlStorageField <TEntity>, TypeModel <TView>, PropertyField> BuildMapping() { lock (_syncLock) { if (_mapping != null) { return(_mapping); } var builder = new MappingBuilder <SqlStorageModel <TEntity>, SqlStorageField <TEntity>, TypeModel <TView>, PropertyField>(this); return(builder.Build()); } }
protected override void OnMapping(MappingBuilder builder) { builder.Entity<Assignment>() .PropertyName(_ => _.Parent_id, "ParentAssignment_id") .PropertyValue(_ => _.AssignmentType, "AssignmentTypeCode", (string code) => (AssignmentType)Enum.Parse(typeof(AssignmentType), code)) ; //.Create(reader=>new Assignment(){Assignment_id = (int)reader["Assignment_id"]}) //.IgnoreProperty(_ => _.Title) //.IgnoreProperty(_ => _.Parent_id) //.IgnoreProperty(_ => _.AssignmentType) }
public void KeyNotFoundTest() { var mapping = new MappingBuilder <CaseFile>() .ForCreate() .Map(x => x.Title) .GetMapping(); var obj = new CaseFile { Status = 3 }; mapping.GetUpdateValues(obj); //only create mapping created, so this should fail }
public void WithSourceEnum() { var factory = MappingBuilder.DiscoverIn <Login>().BuildFactory(); var mapper = factory.Create <Login, LoginView>(); var source = new Login { Name = "homer.simpson", States = LoginStates.Locked }; var target = mapper.Map(source); target.Name.ShouldBe(source.Name); target.State.ShouldBe(source.States.ToString()); }
/// <summary>Exposes the method to register mapping repositories.</summary> /// <param name="buildMappings">Delegate method to be used for building mappings.</param> /// <returns>This <see cref="EntityContextFactory" /> </returns> public EntityContextFactory WithMappings(Action <MappingBuilder> buildMappings) { var mappingBuilder = new MappingBuilder(_container.GetAllInstances <IMappingFrom>()); _container.Invalidate(); buildMappings.Invoke(mappingBuilder); foreach (var source in mappingBuilder.Sources) { _container.RegisterInstance(source, source.Description); } return(this); }
public MappingBuilder <T> AddTypeMapping <T>() where T : ControlTagHelper { Type typeOfT = typeof(T); if (this.MappingBuilders.ContainsKey(typeOfT)) { return((MappingBuilder <T>) this.MappingBuilders[typeOfT]); } var mappingBuilder = new MappingBuilder <T>(); this.MappingBuilders.Add(typeOfT, mappingBuilder); return(mappingBuilder); }
public void WithCustomConverter() { var factory = MappingBuilder.DiscoverIn <Address>().BuildFactory(); var mapper = factory.Create <Address, SingleLineAddressView>(); var source = new Address { HouseNumber = 742, Street = "Evergreen Terrace", Town = "Springfield" }; var target = mapper.Map(source); target.Display.ShouldBe("742 Evergreen Terrace, Springfield"); }
public void KeyNotFoundTest() { var mapping = new MappingBuilder <CaseFile>() .ForCreate() .Map(x => x.Title) .GetMapping(); var obj = new CaseFile() { Status = 3 }; //only create mapping created, so this should fail Assert.That(() => mapping.GetUpdateValues(obj), Throws.TypeOf <KeyNotFoundException>()); }
public override ISet <Item> Create() { var mapping = MappingBuilder .WithIndex(Guid.NewGuid().ToString()) .WithKeyField("GuidProperty") .Build(); var settings = new ConnectionSettings(new Uri("http://127.0.0.1:9200")) .DefaultIndex("tests"); return(new DelayedSetDecorator <Item>( new ElasticsearchSet <Item>( new ElasticClient(settings), mapping), 1000)); }
protected override void ScenarioSetup() { var entityMapping = new Mock <IEntityMapping>(MockBehavior.Strict); entityMapping.SetupGet(instance => instance.Type).Returns(typeof(IProduct)); var classMapping = new Mock <IStatementMapping>(MockBehavior.Strict); classMapping.SetupGet(instance => instance.Term).Returns(new Iri(ExpectedClass)); classMapping.SetupGet(instance => instance.Graph).Returns((Iri)null); entityMapping.SetupGet(instance => instance.Classes).Returns(new[] { classMapping.Object }); MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >())) .Returns(new Dictionary <Type, IEntityMapping>() { { typeof(IProduct), entityMapping.Object } }); }
public void WithDefaultConverters() { var factory = MappingBuilder.DiscoverIn <Address>().BuildFactory(); var mapper = factory.Create <Address, AddressView>(); var source = new Address { HouseNumber = 742, Street = "Evergreen Terrace", Town = "Springfield" }; var target = mapper.Map(source); target.HouseNumber.ShouldBe(source.HouseNumber.ToString()); target.Street.ShouldBe(source.Street); target.Town.ShouldBe(source.Town); }
protected override void ScenarioSetup() { MappingBuilder.Setup(instance => instance.BuildMappings(It.IsAny <IEnumerable <IMappingSource> >(), It.IsAny <IDictionary <Type, ICollection <ITermMappingProvider> > >())) .Returns(new Dictionary <Type, IEntityMapping>() { { typeof(IComplexEntity), CreateEntityMapping <IComplexEntity>(new Iri("ComplexEntity")) }, { typeof(IProduct), CreateEntityMapping <IProduct>(new Iri("Product")) } }); var entitySource = new Mock <IEntitySource>(MockBehavior.Strict); var changeDetector = new Mock <IChangeDetector>(MockBehavior.Strict); var context = new Mock <DefaultEntityContext>(MockBehavior.Strict, entitySource.Object, MappingsRepository, changeDetector.Object); context.SetupGet(instance => instance.Mappings).Returns(() => MappingsRepository); var entity = new Entity(new Iri(), context.Object); entity.CastedTypes.Add(typeof(IProduct)); Entity = entity; }
public void WithList() { var factory = MappingBuilder.DiscoverIn <Customer>().BuildFactory(); var mapper = factory.Create <Customer, CustomerListView>(); var source = new Customer { Name = "Homer Simpson", Orders = new[] { new Order { Id = 101, Description = "Slippers", Quantity = 1 }, new Order { Id = 201, Description = "Socks", Quantity = 3 } } }; var target = mapper.Map(source); target.Name.ShouldBe(source.Name); var firstSourceOrder = source.Orders.First(); var firstTargetOrder = target.Orders.First(); firstTargetOrder.Id.ShouldBe(firstSourceOrder.Id); firstTargetOrder.Description.ShouldBe(firstSourceOrder.Description); firstTargetOrder.Quantity.ShouldBe(firstSourceOrder.Quantity); var secondSourceOrder = source.Orders.First(); var secondTargetOrder = target.Orders.First(); secondTargetOrder.Id.ShouldBe(secondSourceOrder.Id); secondTargetOrder.Description.ShouldBe(secondSourceOrder.Description); secondTargetOrder.Quantity.ShouldBe(secondSourceOrder.Quantity); }
private static void BuildType(INamedTypeSymbol source, INamedTypeSymbol destination, ImmutableArray <string> propertyNames, Compilation compilation, IndentedTextWriter indentWriter, NamespaceGatherer namespaces) { indentWriter.WriteLine($"public static partial class {source.Name}MapToExtensions"); indentWriter.WriteLine("{"); indentWriter.Indent++; var constructors = destination.Constructors.Where(_ => _.DeclaredAccessibility == Accessibility.Public || destination.ContainingAssembly.ExposesInternalsTo(compilation.Assembly) && _.DeclaredAccessibility == Accessibility.Friend).ToArray(); for (var i = 0; i < constructors.Length; i++) { var constructor = constructors[i]; MappingBuilder.BuildMapExtensionMethod(source, destination, propertyNames, constructor, namespaces, indentWriter); if (i < constructors.Length - 1) { indentWriter.WriteLine(); } } indentWriter.Indent--; indentWriter.WriteLine("}"); }
private static void DefaultMappings(MappingBuilder mappings) { mappings.Fluent.FromAssemblyOf<ITypedEntity>(); mappings.Attributes.FromAssemblyOf<ITypedEntity>(); }
protected override void BuildMappings(MappingBuilder m) { m.Fluent.FromAssemblyOf<AnimalMap>(); m.AddMapping(GetType().Assembly, Mappings); }
/// <summary>Exposes the method to register mapping repositories.</summary> /// <param name="buildMappings">Delegate method to be used for building mappings.</param> /// <returns>This <see cref="EntityContextFactory" /> </returns> public EntityContextFactory WithMappings(Action<MappingBuilder> buildMappings) { var mappingBuilder = new MappingBuilder(_mappingsRepository); buildMappings.Invoke(mappingBuilder); return this; }
protected virtual void BuildMappings(MappingBuilder m) { m.FromAssemblyOf<IAnimal>(); m.AddMapping(GetType().Assembly, Mappings); }
protected virtual void BuildMappings(MappingBuilder m) { m.FromAssemblyOf <IAnimal>(); m.AddMapping(GetType().GetTypeInfo().Assembly, Mappings); }
public MappingFromFluent(MappingBuilder mappingBuilder) : base(mappingBuilder) { }
protected override void BuildMappings(MappingBuilder m) { base.BuildMappings(m); m.FromAssemblyOf <AnimalMap>(); }
public MappingFromAttributes(MappingBuilder mappingBuilder) : base(mappingBuilder) { }