public void From_TypedEntity_With_Relations_To_NodeVersion() { //Arrange var mapper = new ManualMapper(new FakeLookupHelper(), new FakeHiveProvider()); mapper.Configure(); var entityParent = HiveModelCreationHelper.MockTypedEntity(false); entityParent.Id = HiveId.ConvertIntToGuid(1); var entityChild = HiveModelCreationHelper.MockTypedEntity(false); entityChild.Id = HiveId.ConvertIntToGuid(2); entityParent.Relations.Add(FixedRelationTypes.ContentTreeRelationType, entityChild); //Act var resultParent = mapper.Map <TypedEntity, NodeVersion>(entityParent); //var resultChild = mapper.Map<TypedEntity, NodeVersion>(entityChild); //Assert Assert.AreEqual(entityParent.EntitySchema.Alias, resultParent.AttributeSchemaDefinition.Alias); Assert.AreEqual(entityParent.Attributes.Count, resultParent.Attributes.Count); Assert.AreEqual(entityParent.Relations.Count(), resultParent.Node.OutgoingRelations.Count); Assert.AreEqual(entityParent.Relations.Single().Source.Id, resultParent.Node.OutgoingRelations.First().StartNode.Id); Assert.AreEqual(entityParent.Relations.Single().Destination.Id, resultParent.Node.OutgoingRelations.First().EndNode.Id); //BUG: If you call entityChild.Relations.Count() an infinite loop occurs :( //Assert.AreEqual(entityChild.Relations.Count(), resultChild.Node.IncomingRelations.Count); }
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); }
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)); }
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)); }
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); }
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); }
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); }
public void From_AttributeSchemaDefinition_With_Relations_To_EntitySchema() { //Arrange var mapper = new ManualMapper(new FakeLookupHelper(), new FakeHiveProvider()); mapper.Configure(); var entityParent = new AttributeSchemaDefinition() { Id = Guid.NewGuid(), Alias = "test-parent" }; var entityChild = new AttributeSchemaDefinition() { Id = Guid.NewGuid(), Alias = "test-child" }; entityParent.OutgoingRelations.Add(new NodeRelation() { StartNode = entityParent, EndNode = entityChild, NodeRelationType = new NodeRelationType() { Alias = FixedRelationTypes.SchemaTreeRelationType.RelationName, Id = FixedRelationTypes.SchemaTreeRelationType.RelationName.EncodeAsGuid() } }); //Act var resultParent = mapper.Map <AttributeSchemaDefinition, EntitySchema>(entityParent); //var resultChild = mapper.Map<TypedEntity, NodeVersion>(entityChild); //Assert Assert.AreEqual(entityParent.Alias, resultParent.Alias); Assert.AreEqual(entityParent.OutgoingRelations.Count(), resultParent.Relations.Count()); Assert.AreEqual(entityParent.OutgoingRelations.Single().StartNode.Id, (Guid)resultParent.Relations.Single().Source.Id.Value); Assert.AreEqual(entityParent.OutgoingRelations.Single().EndNode.Id, (Guid)resultParent.Relations.Single().Destination.Id.Value); //BUG: If you call entityChild.Relations.Count() an infinite loop occurs :( //Assert.AreEqual(entityChild.Relations.Count(), resultChild.Node.IncomingRelations.Count); }
public void From_EntitySchema_With_Relations_To_AttributeSchemaDefinition() { //Arrange var mapper = new ManualMapper(new FakeLookupHelper(), new FakeHiveProvider()); mapper.Configure(); var entityParent = HiveModelCreationHelper.MockEntitySchema("test-schema-parent", "parent"); entityParent.Id = HiveId.ConvertIntToGuid(1); var entityChild = HiveModelCreationHelper.MockEntitySchema("test-schema-child", "child"); entityChild.Id = HiveId.ConvertIntToGuid(2); entityParent.Relations.Add(FixedRelationTypes.SchemaTreeRelationType, entityChild); //Act var resultParent = mapper.Map <EntitySchema, AttributeSchemaDefinition>(entityParent); //var resultChild = mapper.Map<EntitySchema, AttributeSchemaDefinition>(entityChild); //Assert Assert.AreEqual(entityParent.Alias, resultParent.Alias); Assert.AreEqual(entityParent.Name.ToString(), resultParent.Name); Assert.AreEqual(entityParent.AttributeDefinitions.Count, resultParent.AttributeDefinitions.Count); Assert.AreEqual(entityParent.AttributeTypes.Count, resultParent.AttributeDefinitions.Select(x => x.AttributeType).DistinctBy(x => x.Alias).Count()); Assert.AreEqual(entityParent.Relations.Count(), resultParent.OutgoingRelations.Count); Assert.AreEqual(entityParent.Relations.Single().Source.Id, resultParent.OutgoingRelations.First().StartNode.Id); Assert.AreEqual(entityParent.Relations.Single().Destination.Id, resultParent.OutgoingRelations.First().EndNode.Id); //BUG: If you call entityChild.Relations.Count() an infinite loop occurs :( //Assert.AreEqual(entityChild.Relations.Count(), resultChild.OutgoingRelations.Count); }
public IList <Model.Entities.Person> ManualMapping() => ManualMapper.Map(_items);