public void Register_ClrType_InferSchemaTypes() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeRegistrar = new TypeRegistrar( serviceProvider, initialTypes); // act typeRegistrar.Complete(); // assert typeRegistrar.Registerd .Select(t => t.Value.Type) .OfType <IHasClrType>() .ToDictionary( t => t.GetType().GetTypeName(), t => t.ClrType.GetTypeName()) .MatchSnapshot(new SnapshotNameExtension("registered")); typeRegistrar.ClrTypes.ToDictionary( t => t.Key.ToString(), t => t.Value.ToString()) .MatchSnapshot(new SnapshotNameExtension("clr")); }
public void AddExtensionsFromFile() { // arrange var builder = new MockStitchingBuilder(); // act builder.AddExtensionsFromFile( IOPath.Combine("__resources__", "Contract.graphql")) .AddExtensionsFromFile( IOPath.Combine("__resources__", "Customer.graphql")); // assert var services = new EmptyServiceProvider(); var merger = new SchemaMerger(); var list = new List <string>(); foreach (LoadSchemaDocument item in builder.Extensions) { list.Add(SchemaSyntaxSerializer.Serialize( item.Invoke(services))); } list.MatchSnapshot(); }
public void AddSchema_2() { // arrange Schema customerSchema = Schema.Create( CustomerSchemaFactory.ConfigureSchema); Schema contractSchema = Schema.Create( ContractSchemaFactory.ConfigureSchema); var builder = new MockStitchingBuilder(); // act builder.AddSchema("customer", customerSchema) .AddSchema("contract", contractSchema); // assert var services = new EmptyServiceProvider(); var merger = new SchemaMerger(); foreach (KeyValuePair <NameString, ExecutorFactory> item in builder.Executors) { ISchema schema = item.Value.Invoke(services).Schema; merger.AddSchema(item.Key, SchemaSerializer.SerializeSchema(schema)); } SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot(); }
public void Initializer_SchemaOptions_Are_Null() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, DescriptorContext.Create(), new Dictionary <string, object>(), initialTypes, new List <Type>(), new AggregateTypeInitializationInterceptor(), null, t => t is ObjectType <Foo>); // act Action action = () => typeInitializer.Initialize(() => null, null); // assert Assert.Throws <ArgumentNullException>(action); }
public void Create_OptionsNull_ArgumentException() { // arrange var service = new EmptyServiceProvider(); // act Action action = () => DescriptorContext.Create(null, service); // assert Assert.Throws <ArgumentNullException>(action); }
public OrderController() { _dbContext = ApplicationDbContext.Create(); var services = new EmptyServiceProvider(); var options = new EasyQueryOptions(services); options.UseEntity((_, __) => _dbContext.Orders); //create EasyQuery manager which generates LINQ queries _eqManager = new EasyQueryManagerLinq <Order>(services, options); }
public void Create_ConventionsNull_ArgumentException() { // arrange var service = new EmptyServiceProvider(); var options = new SchemaOptions(); // act Action action = () => DescriptorContext.Create(options, service, null); // assert Assert.Throws <ArgumentNullException>(action); }
public void UseGraphQLHttpGetSchema_BuilderServices_BuilderIsNull() { // arrange IServiceProvider services = new EmptyServiceProvider(); // act Action action = () => HttpGetSchemaApplicationBuilderExtensions .UseGraphQLHttpGetSchema(null, services); // assert Assert.Throws <ArgumentNullException>(action); }
public void Create_OptionsNull_ArgumentException() { // arrange var service = new EmptyServiceProvider(); var conventions = new Dictionary <Type, IConvention>(); // act Action action = () => DescriptorContext.Create( null, service, conventions, new Dictionary <string, object>()); // assert Assert.Throws <ArgumentNullException>(action); }
public void Create_ConventionsNull_ArgumentException() { // arrange var service = new EmptyServiceProvider(); var options = new SchemaOptions(); // act Action action = () => DescriptorContext.Create( options, service, null, new Dictionary <string, object>(), new SchemaBuilder.LazySchema()); // assert Assert.Throws <ArgumentNullException>(action); }
public void UseGraphQLHttpGet_BuilderServicesOptions_BuilderIsNull() { // arrange IServiceProvider services = new EmptyServiceProvider(); var options = new HttpGetMiddlewareOptions(); // act Action action = () => HttpGetApplicationBuilderExtensions .UseGraphQLHttpGet(null, services, options); // assert Assert.Throws <ArgumentNullException>(action); }
public void UseGraphQLHttpGetSchema_BuilderServicesOptions_OptionsIsNull() { // arrange IAppBuilder builder = Mock.Of <IAppBuilder>(); IServiceProvider services = new EmptyServiceProvider(); // act Action action = () => HttpGetSchemaApplicationBuilderExtensions .UseGraphQLHttpGetSchema(builder, services, null); // assert Assert.Throws <ArgumentNullException>(action); }
public void Register_ClrType_InferSchemaTypes() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(TypeReference.Create( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, DescriptorContext.Create(), initialTypes, new List <Type>(), new AggregateTypeInitializationInterceptor(), null, t => t is ObjectType <Foo>); // act typeInitializer.Initialize(() => null, new SchemaOptions()); // assert bool exists = typeInitializer.DiscoveredTypes.TryGetType( TypeReference.Create( typeof(ObjectType <Foo>), TypeContext.Output), out RegisteredType type); Assert.True(exists); Dictionary <string, string> fooType = Assert.IsType <ObjectType <Foo> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)); exists = typeInitializer.DiscoveredTypes.TryGetType( TypeReference.Create(typeof(ObjectType <Bar>), TypeContext.Output), out type); Assert.True(exists); Dictionary <string, string> barType = Assert.IsType <ObjectType <Bar> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)); new { fooType, barType }.MatchSnapshot(); }
public void Register_ClrType_InferSchemaTypes() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeInitializer = new TypeInitializer( serviceProvider, DescriptorContext.Create(), initialTypes, new List <Type>(), new Dictionary <string, object>(), null, t => t is ObjectType <Foo>); // act typeInitializer.Initialize(() => null, new SchemaOptions()); // assert bool exists = typeInitializer.Types.TryGetValue( new ClrTypeReference( typeof(ObjectType <Foo>), TypeContext.Output), out RegisteredType type); Assert.True(exists); Assert.IsType <ObjectType <Foo> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("FooType")); exists = typeInitializer.Types.TryGetValue( new ClrTypeReference(typeof(ObjectType <Bar>), TypeContext.Output), out type); Assert.True(exists); Assert.IsType <ObjectType <Bar> >(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => TypeVisualizer.Visualize(t.Type)) .MatchSnapshot(new SnapshotNameExtension("BarType")); }
public void Upgrade_Type_From_GenericType() { // arrange var initialTypes = new HashSet <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(ObjectType <Foo>), TypeContext.Output)); initialTypes.Add(new ClrTypeReference( typeof(FooType), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var clrTypeReferences = new Dictionary <IClrTypeReference, ITypeReference>(); var typeDiscoverer = new TypeDiscoverer( initialTypes, clrTypeReferences, DescriptorContext.Create(), new Dictionary <string, object>(), new AggregateTypeInitializationInterceptor(), serviceProvider); // act DiscoveredTypes result = typeDiscoverer.DiscoverTypes(); // assert Assert.Empty(result.Errors); result.Types .Select(t => t.Type) .OfType <IHasClrType>() .ToDictionary( t => t.GetType().GetTypeName(), t => t.ClrType.GetTypeName()) .MatchSnapshot(new SnapshotNameExtension("registered")); clrTypeReferences.ToDictionary( t => t.Key.ToString(), t => t.Value.ToString()) .MatchSnapshot(new SnapshotNameExtension("clr")); }
public void Register_ClrType_InferSchemaTypes() { // arrange var initialTypes = new HashSet <ITypeReference>(); initialTypes.Add(TypeReference.Create( typeof(Foo), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var clrTypeReferences = new Dictionary <ClrTypeReference, ITypeReference>(); var typeDiscoverer = new TypeDiscoverer( initialTypes, clrTypeReferences, DescriptorContext.Create(), new AggregateTypeInitializationInterceptor(), serviceProvider); // act DiscoveredTypes result = typeDiscoverer.DiscoverTypes(); // assert Assert.Empty(result.Errors); new { registered = result.Types .Select(t => t.Type) .OfType <IHasRuntimeType>() .ToDictionary( t => t.GetType().GetTypeName(), t => t.RuntimeType.GetTypeName()), clr = clrTypeReferences.ToDictionary( t => t.Key.ToString(), t => t.Value.ToString()) }.MatchSnapshot(); }
public void AddSchemaFromString() { // arrange var builder = new MockStitchingBuilder(); // act builder.AddSchemaFromString("contract", FileResource.Open("Contract.graphql")) .AddSchemaFromString("customer", FileResource.Open("Customer.graphql")); // assert var services = new EmptyServiceProvider(); var merger = new SchemaMerger(); foreach (KeyValuePair <NameString, LoadSchemaDocument> item in builder.Schemas) { merger.AddSchema(item.Key, item.Value.Invoke(services)); } SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot(); }
public void Register_SchemaType_ClrTypeExists() { // arrange var initialTypes = new List <ITypeReference>(); initialTypes.Add(new ClrTypeReference( typeof(FooType), TypeContext.Output)); var serviceProvider = new EmptyServiceProvider(); var typeRegistrar = new TypeRegistrar( serviceProvider, DescriptorContext.Create(), initialTypes, new Dictionary <ITypeReference, ITypeReference>(), new Dictionary <string, object>(), new AggregateTypeInitilizationInterceptor()); // act typeRegistrar.Complete(); // assert typeRegistrar.Registerd .Select(t => t.Value.Type) .OfType <IHasClrType>() .ToDictionary( t => t.GetType().GetTypeName(), t => t.ClrType.GetTypeName()) .MatchSnapshot(new SnapshotNameExtension("registered")); typeRegistrar.ClrTypes.ToDictionary( t => t.Key.ToString(), t => t.Value.ToString()) .MatchSnapshot(new SnapshotNameExtension("clr")); }