public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "servicebus/publish")] HttpRequestMessage req, [ServiceBus("%ServiceBusTopic%", Connection = "AzureServiceBusConnectionString", EntityType = EntityType.Topic)] IAsyncCollector <string> collector, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var settings = new JsonSerializerSettings() { Formatting = Formatting.Indented, ContractResolver = new DefaultContractResolver() { NamingStrategy = new CamelCaseNamingStrategy() }, NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, }; var location = Utility.GetBasePath(); var path = "default.json"; var sink = new FileSystemSchemaSink().WithBaseLocation(location); var consumer = new SchemaConsumer().WithSink(sink); var validator = new SchemaValidator().WithSchemaConsumer(consumer); var sample = new SampleClass(); var payload = await JsonConvert.SerializeObject(sample, settings) .ValidateAsStringAsync(validator, path).ConfigureAwait(false); await collector.AddAsync(payload).ConfigureAwait(false); return(req.CreateResponse(HttpStatusCode.Created)); }
public void Given_Sink_When_Instantiated_Then_It_Should_Return_Values() { var sink = new Mock <ISchemaSink>(); var instance = new SchemaConsumer(sink.Object); instance.Sink.Should().NotBeNull(); }
public void Given_Null_Path_When_ConsumeAsync_Invoked_Then_It_Should_Throw_Exception() { var instance = new SchemaConsumer(); Func <Task> func = async() => await instance.ConsumeAsync(null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
private static ISchemaConsumer GetSchemaConsumer(Options options) { var sink = GetSchemaSink(options); var consumer = new SchemaConsumer() .WithSink(sink); return(consumer); }
public void Given_Sink_When_WithSink_Invoked_Then_It_Should_Return_Result() { var consumer = new SchemaConsumer(); var instance = new SchemaValidator(); var result = instance.WithSchemaConsumer(consumer); result.Consumer.Should().Be(consumer); }
public void Given_Sink_When_WithSink_Invoked_Then_It_Should_Return_Result() { var consumer = new SchemaConsumer(); var ex = new SchemaNotFoundException() .WithSchemaConsumer(consumer); ex.Should().BeOfType <SchemaNotFoundException>(); }
private static async Task ConsumeAsync(Options options, ISchemaSink sink) { var consumer = new SchemaConsumer() .WithSink(sink); var downloaded = await consumer.ConsumeAsync(options.Filepath).ConfigureAwait(false); Console.WriteLine($"{sink.Name}: {SchemaConsumed}"); Console.WriteLine(downloaded); }
public void Given_Null_Sink_When_ConsumeAsync_Invoked_Then_It_Should_Throw_Exception() { var path = "default.json"; var instance = new SchemaConsumer(); Func <Task> func = async() => await instance.ConsumeAsync(path).ConfigureAwait(false); func.Should().Throw <InvalidOperationException>(); }
public void Given_Sink_When_ConsumeAsync_Invoked_Then_It_Should_Throw_Exception() { var path = "default.json"; var sink = new Mock <ISchemaSink>(); sink.Setup(p => p.GetSchemaAsync(It.IsAny <string>())).Throws <InvalidOperationException>(); var instance = new SchemaConsumer() .WithSink(sink.Object); Func <Task> func = async() => await instance.ConsumeAsync(path).ConfigureAwait(false); func.Should().Throw <InvalidOperationException>(); }
public static async Task Run( [ServiceBusTrigger("%ServiceBusTopic%", "%ServiceBusTopicSubscription%", AccessRights.Manage, Connection = "AzureServiceBusConnectionString")] string message, ILogger log) { log.LogInformation($"C# ServiceBus topic trigger function processed message: {message}"); var location = Utility.GetBasePath(); var path = "default.json"; var sink = new FileSystemSchemaSink().WithBaseLocation(location); var consumer = new SchemaConsumer().WithSink(sink); var validator = new SchemaValidator().WithSchemaConsumer(consumer); var validated = await message.ValidateAsync(validator, path).ConfigureAwait(false); log.LogInformation($"Message validated against schema."); }
public async Task Given_Sink_When_ConsumeAsync_Invoked_Then_It_Should_Return_Result() { var schema = "{ \"hello\": \"world\" }"; var path = "default.json"; var sink = new Mock <ISchemaSink>(); sink.Setup(p => p.GetSchemaAsync(It.IsAny <string>())).ReturnsAsync(schema); var instance = new SchemaConsumer() .WithSink(sink.Object); var result = await instance.ConsumeAsync(path).ConfigureAwait(false); result.Should().Be(schema); }
public static extern bool CloneFilter(IntPtr last, out SchemaConsumer result);
public void Given_Default_When_Instantiated_Then_It_Should_Return_Null_Results() { var instance = new SchemaConsumer(); instance.Sink.Should().BeNull(); }