public async Task CompilationFailsWhenEnvironmentNotFound() { var config = new PreparedConfiguration( new ConfigurationIdentifier( new EnvironmentIdentifier("Foo", "Bar"), new StructureIdentifier("Foo", 42), 4711)); var store = new Mock <IDomainObjectStore>(MockBehavior.Strict); store.Setup(s => s.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>(), It.IsAny <long>())) .ReturnsAsync(() => Result.Error <ConfigEnvironment>(string.Empty, ErrorCode.DbQueryError)) .Verifiable("Environment not retrieved"); var compiler = new Mock <IConfigurationCompiler>(MockBehavior.Strict); var parser = new Mock <IConfigurationParser>(MockBehavior.Strict); var translator = new Mock <IJsonTranslator>(MockBehavior.Strict); var result = await config.Compile(store.Object, compiler.Object, parser.Object, translator.Object); Assert.True(result.IsError); store.Verify(); }
public async Task CompilationThrowsOnInvalidArguments() { var config = new PreparedConfiguration( new ConfigurationIdentifier( new EnvironmentIdentifier("Foo", "Bar"), new StructureIdentifier("Foo", 42), 4711)); var store = new Mock <IDomainObjectStore>(MockBehavior.Strict); var compiler = new Mock <IConfigurationCompiler>(MockBehavior.Strict); var parser = new Mock <IConfigurationParser>(MockBehavior.Strict); var translator = new Mock <IJsonTranslator>(MockBehavior.Strict); await Assert.ThrowsAsync <ArgumentNullException>(() => config.Compile(null, null, null, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => config.Compile(store.Object, compiler.Object, parser.Object, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => config.Compile(store.Object, compiler.Object, null, translator.Object)); await Assert.ThrowsAsync <ArgumentNullException>(() => config.Compile(store.Object, null, parser.Object, translator.Object)); await Assert.ThrowsAsync <ArgumentNullException>(() => config.Compile(null, compiler.Object, parser.Object, translator.Object)); }
public async Task CompilationFailsWhenStructureNotFound() { var config = new PreparedConfiguration( new ConfigurationIdentifier( new EnvironmentIdentifier("Foo", "Bar"), new StructureIdentifier("Foo", 42), 4711)); var store = new Mock <IDomainObjectStore>(MockBehavior.Strict); store.Setup(s => s.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>(), It.IsAny <long>())) .ReturnsAsync((ConfigEnvironment env, string id, long version) => { env.ApplyEvent(new ReplayedEvent { UtcTime = DateTime.UtcNow, Version = 1, DomainEvent = new EnvironmentKeysImported(env.Identifier, new[] { ConfigKeyAction.Set("Foo", "Bar", "", ""), ConfigKeyAction.Set("Jar", "Jar", "", "") }) }); return(Result.Success(env)); }) .Verifiable("Environment not retrieved"); store.Setup(s => s.ReplayObject(It.IsAny <ConfigStructure>(), It.IsAny <string>(), It.IsAny <long>())) .ReturnsAsync(() => Result.Error <ConfigStructure>(string.Empty, ErrorCode.DbQueryError)) .Verifiable("Structure not retrieved"); var compiler = new Mock <IConfigurationCompiler>(MockBehavior.Strict); var parser = new Mock <IConfigurationParser>(MockBehavior.Strict); var translator = new Mock <IJsonTranslator>(MockBehavior.Strict); var result = await config.Compile(store.Object, compiler.Object, parser.Object, translator.Object); Assert.True(result.IsError); store.Verify(); }
public async Task NoThrowOnCompilationException() { var config = new PreparedConfiguration( new ConfigurationIdentifier( new EnvironmentIdentifier("Foo", "Bar"), new StructureIdentifier("Foo", 42), 4711)); var store = new Mock <IDomainObjectStore>(MockBehavior.Strict); store.Setup(s => s.ReplayObject(It.IsAny <ConfigEnvironment>(), It.IsAny <string>(), It.IsAny <long>())) .ReturnsAsync((ConfigEnvironment env, string id, long version) => { env.ApplyEvent(new ReplayedEvent { UtcTime = DateTime.UtcNow, Version = 1, DomainEvent = new EnvironmentKeysImported(env.Identifier, new[] { ConfigKeyAction.Set("Foo", "Bar", "", ""), ConfigKeyAction.Set("Jar", "Jar", "", "") }) }); return(Result.Success(env)); }) .Verifiable("Environment not retrieved"); store.Setup(s => s.ReplayObject(It.IsAny <ConfigStructure>(), It.IsAny <string>(), It.IsAny <long>())) .ReturnsAsync((ConfigStructure str, string id, long version) => { str.ApplyEvent(new ReplayedEvent { UtcTime = DateTime.UtcNow, Version = 1, DomainEvent = new StructureCreated(str.Identifier, new Dictionary <string, string> { { "Ref", "{{Foo}}{{Jar}}" } }, new Dictionary <string, string>()) }); return(Result.Success(str)); }) .Verifiable("Structure not retrieved"); var compiler = new Mock <IConfigurationCompiler>(MockBehavior.Strict); compiler.Setup(c => c.Compile(It.IsAny <EnvironmentCompilationInfo>(), It.IsAny <StructureCompilationInfo>(), It.IsAny <IConfigurationParser>())) .Throws <Exception>() .Verifiable(); var parser = new Mock <IConfigurationParser>(MockBehavior.Strict); var translator = new Mock <IJsonTranslator>(MockBehavior.Strict); var result = await config.Compile(store.Object, compiler.Object, parser.Object, translator.Object); Assert.True(result.IsError); store.Verify(); compiler.Verify(); }