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 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); }