public void Register_ClrType_InferSchemaTypes() { // arrange var typeInterceptor = new AggregateTypeInterceptor(); typeInterceptor.SetInterceptors(new[] { new IntrospectionTypeInterceptor() }); IDescriptorContext context = DescriptorContext.Create( typeInterceptor: typeInterceptor); var typeRegistry = new TypeRegistry(context.TypeInterceptor); var typeInitializer = new TypeInitializer( context, typeRegistry, new List <ITypeReference> { context.TypeInspector.GetTypeRef(typeof(Foo), TypeContext.Output) }, null, t => { return(t switch { ObjectType <Foo> => RootTypeKind.Query, _ => RootTypeKind.None }); });
public void Register_SchemaType_ClrTypeExists() { // arrange var typeInterceptor = new AggregateTypeInterceptor(); typeInterceptor.SetInterceptors(new[] { new IntrospectionTypeInterceptor() }); IDescriptorContext context = DescriptorContext.Create( typeInterceptor: typeInterceptor); var typeRegistry = new TypeRegistry(context.TypeInterceptor); var typeInitializer = new TypeInitializer( context, typeRegistry, new List <ITypeReference> { context.TypeInspector.GetTypeRef(typeof(FooType), TypeContext.Output) }, null, t => t is FooType ? RootTypeKind.Query : RootTypeKind.None); // act typeInitializer.Initialize(() => null, new SchemaOptions()); // assert var exists = typeRegistry.TryGetType( context.TypeInspector.GetTypeRef(typeof(FooType), TypeContext.Output), out RegisteredType type); Assert.True(exists); var fooType = Assert.IsType <FooType>(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => t.Type.Print()); exists = typeRegistry.TryGetType( context.TypeInspector.GetTypeRef(typeof(BarType), TypeContext.Output), out type); Assert.True(exists); var barType = Assert.IsType <BarType>(type.Type).Fields.ToDictionary( t => t.Name.ToString(), t => t.Type.Print()); new { fooType, barType }.MatchSnapshot(); }