/// <summary> /// This is a generic endpoint definition generator, you can override it in your test class if you want to send something different. /// </summary> /// <param name="schemaBuilder"></param> /// <returns></returns> protected virtual async Task <EndpointClientDefinition> CreateEndpointDefinition(ISchemaBuilder schemaBuilder) { var endpoint = new EndpointClientDefinition(typeof(TResult), await schemaBuilder.GetSchema(typeof(TResult))); var endpointDoc = new EndpointDoc(); endpointDoc.RequestSchema = await schemaBuilder.GetSchema(typeof(TInput)); endpoint.AddLink(new EndpointClientLinkDefinition("Save", endpointDoc, false)); return(endpoint); }
protected override async Task <EndpointClientDefinition> CreateEndpointDefinition(ISchemaBuilder schemaBuilder) { var endpoint = new EndpointClientDefinition(typeof(EntryPoint), await schemaBuilder.GetSchema(typeof(EntryPoint))); var endpointDoc = new EndpointDoc(); endpointDoc.ResponseSchema = await schemaBuilder.GetSchema(typeof(EntryPoint)); endpoint.AddLink(new EndpointClientLinkDefinition("self", endpointDoc, false)); return(endpoint); }
protected virtual async Task CreateAsyncMocks() { mockup.Add <IValidSchemaTypeManager>(s => { var mock = new Mock <IValidSchemaTypeManager>(); mock.Setup(i => i.IsValid(It.IsAny <Type>())).Returns(true); return(mock.Object); }); mockup.Add <JsonSchemaGenerator>(s => new JsonSchemaGenerator(HalcyonConvention.DefaultJsonSchemaGeneratorSettings)); mockup.Add <ISchemaBuilder>(s => new SchemaBuilder(s.Get <JsonSchemaGenerator>(), s.Get <IValidSchemaTypeManager>())); //This is setup outside the mock callbacks, so we can do async properly //The get must be after the registrations EndpointClientDefinition endpoint = null; mockup.TryAdd <IClientGenerator>(s => { if (endpoint == null) { throw new InvalidOperationException("This should not happen. EndpointClientDefinition not yet resolved and is null."); } var mock = new Mock <IClientGenerator>(); IEnumerable <EndpointClientDefinition> mockEndpoints = new List <EndpointClientDefinition>() { endpoint }; mock.Setup(i => i.GetEndpointDefinitions()).Returns(Task.FromResult(mockEndpoints)); return(mock.Object); }); var schemaBuilder = mockup.Get <ISchemaBuilder>(); endpoint = await CreateEndpointDefinition(schemaBuilder); }