public void Given_Null_Schema_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var schema = "{ \"hello\": \"world\" }"; var instance = new SchemaProducer(); Func <Task> func = async() => await instance.ProduceAsync(schema : null, path : null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await instance.ProduceAsync(schema, path : null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
public async Task Given_TypeParameter_And_Sinks_When_ProduceAsync_Invoked_Then_It_Should_Return_Result() { var path = "default.json"; var schema = new JsonSchema(); var builder = new Mock <ISchemaBuilder>(); builder.Setup(p => p.Build(It.IsAny <Type>())).Returns(schema); var sink1 = new Mock <ISchemaSink>(); sink1.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var sink2 = new Mock <ISchemaSink>(); sink2.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var instance = new SchemaProducer() .WithBuilder(builder.Object) .WithSink(sink1.Object) .WithSink(sink2.Object); var result = await instance.ProduceAsync <FakeClass>(path).ConfigureAwait(false); result.Should().BeTrue(); }
public void Given_Type_And_Error_Sink_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var path = "default.json"; var type = typeof(FakeClass); var schema = new JsonSchema(); var builder = new Mock <ISchemaBuilder>(); builder.Setup(p => p.Build(It.IsAny <Type>())).Returns(schema); var sink1 = new Mock <ISchemaSink>(); sink1.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).Throws <Exception>(); var sink2 = new Mock <ISchemaSink>(); sink2.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var instance = new SchemaProducer() .WithBuilder(builder.Object) .WithSink(sink1.Object) .WithSink(sink2.Object); Func <Task> func = async() => await instance.ProduceAsync(type, path).ConfigureAwait(false); func.Should().Throw <AggregateException>(); }
public void Given_Null_Type_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var schema = new JsonSchema(); var builder = new Mock <ISchemaBuilder>(); builder.Setup(p => p.Build(It.IsAny <Type>())).Returns(schema); var instance = new SchemaProducer() .WithBuilder(builder.Object); Func <Task> func = async() => await instance.ProduceAsync(type : null, path : null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await instance.ProduceAsync(typeof(FakeClass), path : null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
public void Given_Schema_And_Empty_Sink_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var schema = "{ \"hello\": \"world\" }"; var path = "default.json"; var instance = new SchemaProducer(); Func <Task> func = async() => await instance.ProduceAsync(schema, path).ConfigureAwait(false); func.Should().Throw <InvalidOperationException>(); }
private static async Task ProduceAsync(ISchemaBuilder builder, Options options, params ISchemaSink[] sinks) { var producer = new SchemaProducer() .WithBuilder(builder); foreach (var sink in sinks) { producer.WithSink(sink); } var produced = await producer.ProduceAsync <SampleClass>(options.Filepath).ConfigureAwait(false); foreach (var sink in sinks) { Console.WriteLine($"{sink.Name}: {SchemaProduced}"); } }
public void Given_TypeParameter_And_Empty_Sink_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var path = "default.json"; var schema = new JsonSchema(); var builder = new Mock <ISchemaBuilder>(); builder.Setup(p => p.Build(It.IsAny <Type>())).Returns(schema); var instance = new SchemaProducer() .WithBuilder(builder.Object); Func <Task> func = async() => await instance.ProduceAsync <FakeClass>(path).ConfigureAwait(false); func.Should().Throw <InvalidOperationException>(); }
private static async Task RegisterSchemaAsync <T>(Options options) { var sink = GetSchemaSink(options); var builder = new SchemaBuilder() .WithSettings(Settings); var schema = builder.Build <T>() .ToJson(); var producer = new SchemaProducer() .WithBuilder(builder) .WithSink(sink); var produced = await producer.ProduceAsync <T>(options.Filepath) .ConfigureAwait(false); Console.WriteLine(SchemaRegistered); }
public async Task Given_Schema_And_Sinks_When_ProduceAsync_Invoked_Then_It_Should_Return_Result() { var schema = "{ \"hello\": \"world\" }"; var path = "default.json"; var sink1 = new Mock <ISchemaSink>(); sink1.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var sink2 = new Mock <ISchemaSink>(); sink2.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var instance = new SchemaProducer() .WithSink(sink1.Object) .WithSink(sink2.Object); var result = await instance.ProduceAsync(schema, path).ConfigureAwait(false); result.Should().BeTrue(); }
public void Given_Schema_And_Error_Sink_When_ProduceAsync_Invoked_Then_It_Should_Throw_Exception() { var schema = "{ \"hello\": \"world\" }"; var path = "default.json"; var sink1 = new Mock <ISchemaSink>(); sink1.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).Throws <Exception>(); var sink2 = new Mock <ISchemaSink>(); sink2.Setup(p => p.SetSchemaAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var instance = new SchemaProducer() .WithSink(sink1.Object) .WithSink(sink2.Object); Func <Task> func = async() => await instance.ProduceAsync(schema, path).ConfigureAwait(false); func.Should().Throw <AggregateException>(); }