public void QueueExtension_WhenAddedBeforeType_IsAssignedAfterTypeIsAdded() { var collection = new SchemaTypeCollection(); var template = GraphQLProviders.TemplateProvider.ParseType(typeof(TypeExtensionController)) as IGraphControllerTemplate; var graphType = this.MakeGraphType(typeof(TwoPropertyObject), TypeKind.OBJECT) as IObjectGraphType; // queue the extension var extension = template.Extensions.FirstOrDefault(); var field = this.MakeGraphField(extension); collection.EnsureGraphFieldExtension(typeof(TwoPropertyObject), field); // ensure no types exists or were added Assert.AreEqual(0, collection.Count); Assert.AreEqual(1, collection.QueuedExtensionFieldCount); var fieldCount = graphType.Fields.Count; // ensure the type is added, the queue is emptied and hte total fields on the graph type // is correct collection.EnsureGraphType(graphType, typeof(TwoPropertyObject)); Assert.AreEqual(1, collection.Count); Assert.AreEqual(0, collection.QueuedExtensionFieldCount); Assert.AreEqual(fieldCount + 1, graphType.Fields.Count); }
public void QueueExtension_WhenAddedAfterType_IsAddedToTheTypeAndNotQueued() { var collection = new SchemaTypeCollection(); var template = GraphQLProviders.TemplateProvider.ParseType(typeof(TypeExtensionController)) as IGraphControllerTemplate; var twoObjectGraphType = this.MakeGraphType(typeof(TwoPropertyObject), TypeKind.OBJECT) as IObjectGraphType; var fieldCount = twoObjectGraphType.Fields.Count; collection.EnsureGraphType(twoObjectGraphType, typeof(TwoPropertyObject)); // queue the extension var extension = template.Extensions.FirstOrDefault(); var field = this.MakeGraphField(extension); collection.EnsureGraphFieldExtension(typeof(TwoPropertyObject), field); // ensure the type is added, the queue remains empty and the total fields on the graph type // is correct Assert.AreEqual(1, collection.Count); Assert.AreEqual(0, collection.QueuedExtensionFieldCount); Assert.AreEqual(fieldCount + 1, twoObjectGraphType.Fields.Count); }