diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..8c0a1462c3 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..72a7288ed4 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..d219584041 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..757c9dc370 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..45db8d4d92 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..bdead523c5 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..6cabaab23a --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..86e402dcf6 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..82ca8bf857 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..7f688c85f3 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..3c3d4def88 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..83dc44b6d9 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..fb51f5c28b --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..7260061003 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..b7f1432a18 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..ae864320b6 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxAsyncTest.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxAsyncTest.cs deleted file mode 100644 index 593669f104..0000000000 --- a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxAsyncTest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Threading.Tasks; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.DynamoDB; - -namespace Paramore.Brighter.DynamoDB.Tests.Inbox; - -public class DynamoDBInboxAsyncTest : InboxAsyncTest -{ - private DynamoDbInbox? _inbox; - protected override IAmAnInboxAsync Inbox => _inbox!; - - protected override async Task CreateStoreAsync() - { - var tableName = await DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient); - - _inbox = new DynamoDbInbox(Const.DynamoDbClient, - new DynamoDbInboxConfiguration { TableName = tableName }); - } -} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxProvider.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxProvider.cs new file mode 100644 index 0000000000..ffe009947f --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxProvider.cs @@ -0,0 +1,64 @@ +using System.Threading.Tasks; +using Amazon.DynamoDBv2; +using Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Async; +using Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB.Sync; +using Paramore.Brighter.Inbox.DynamoDB; + +namespace Paramore.Brighter.DynamoDB.Tests.Inbox.DynamoDB; + +public class DynamoDBInboxProvider : IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + private string _tableName = ""; + + public IAmAnInboxSync CreateInbox() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + + return new DynamoDbInbox(Const.DynamoDbClient, + new DynamoDbInboxConfiguration { TableName = _tableName }); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + + return new DynamoDbInbox(Const.DynamoDbClient, + new DynamoDbInboxConfiguration { TableName = _tableName }); + } + + public void CreateStore() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + } + + public async Task CreateStoreAsync() + { + _tableName = await DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient); + } + + public void DeleteStore() + { + DeleteStoreAsync().GetAwaiter().GetResult(); + } + + public async Task DeleteStoreAsync() + { + var client = Const.DynamoDbClient; + try + { + await client.DeleteTableAsync(_tableName); + } + catch + { + // Ignoring any error during delete, it's not important at this point + } + + DynamoDbInboxTable.Reset(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxTest.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxTest.cs deleted file mode 100644 index a683f5f9e6..0000000000 --- a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDBInboxTest.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.DynamoDB; - -namespace Paramore.Brighter.DynamoDB.Tests.Inbox; - -public class DynamoDBInboxTest : InboxTests -{ - private DynamoDbInbox? _inbox; - protected override IAmAnInboxSync Inbox => _inbox!; - - protected override void CreateStore() - { - var tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) - .GetAwaiter() - .GetResult(); - - _inbox = new DynamoDbInbox(Const.DynamoDbClient, - new DynamoDbInboxConfiguration { TableName = tableName }); - } -} diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDbInboxTable.cs b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDbInboxTable.cs index a6477d1ba6..b7005ad4e3 100644 --- a/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDbInboxTable.cs +++ b/tests/Paramore.Brighter.DynamoDB.Tests/Inbox/DynamoDbInboxTable.cs @@ -1,4 +1,4 @@ -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.Model; @@ -55,4 +55,9 @@ public static async Task EnsureTableIsCreatedAsync(AmazonDynamoDBClient s_semaphoreSlim.Release(); } } + + public static void Reset() + { + s_tableName = null; + } } diff --git a/tests/Paramore.Brighter.DynamoDB.Tests/test-configuration.json b/tests/Paramore.Brighter.DynamoDB.Tests/test-configuration.json index b93cb22739..3a7d09c132 100644 --- a/tests/Paramore.Brighter.DynamoDB.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.DynamoDB.Tests/test-configuration.json @@ -1,5 +1,12 @@ { "Namespace": "Paramore.Brighter.DynamoDB.Tests", + "Inbox": { + "InboxProvider": "DynamoDBInboxProvider", + "InboxProviderAsync": "DynamoDBInboxProvider", + "Category": "DynamoDB", + "CollectionName": "DynamoDBInbox", + "Prefix": "DynamoDB" + }, "Outbox": { "Transaction": "Amazon.DynamoDBv2.Model.TransactWriteItemsRequest", "OutboxProvider": "Paramore.Brighter.DynamoDB.Tests.Outbox.DynamoDBOutboxProvider", diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..51711db224 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..bd67af4a6a --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..87085f8842 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..c77aa140a2 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..f7362e2c87 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..e4e4a23814 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..ae998af558 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..665290a1b1 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..46bd5ada84 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..20225a35b8 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..583a305b83 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..4306683d2d --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..fe0ffc2622 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..1389275f12 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..d890cd4345 --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..b0e308a04c --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDB/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; + +[Trait("Category", "DynamoDB")] + +[Collection("DynamoDBInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new DynamoDBInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxAsyncTest.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxAsyncTest.cs deleted file mode 100644 index f55b2feac7..0000000000 --- a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxAsyncTest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Threading.Tasks; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.DynamoDB.V4; - -namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox; - -public class DynamoDBInboxAsyncTest : InboxAsyncTest -{ - private DynamoDbInbox? _inbox; - protected override IAmAnInboxAsync Inbox => _inbox!; - - protected override async Task CreateStoreAsync() - { - var tableName = await DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient); - - _inbox = new DynamoDbInbox(Const.DynamoDbClient, - new DynamoDbInboxConfiguration { TableName = tableName }); - } -} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxProvider.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxProvider.cs new file mode 100644 index 0000000000..70f2c86d3e --- /dev/null +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxProvider.cs @@ -0,0 +1,64 @@ +using System.Threading.Tasks; +using Amazon.DynamoDBv2; +using Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Async; +using Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB.Sync; +using Paramore.Brighter.Inbox.DynamoDB.V4; + +namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox.DynamoDB; + +public class DynamoDBInboxProvider : IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + private string _tableName = ""; + + public IAmAnInboxSync CreateInbox() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + + return new DynamoDbInbox(Const.DynamoDbClient, + new DynamoDbInboxConfiguration { TableName = _tableName }); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + + return new DynamoDbInbox(Const.DynamoDbClient, + new DynamoDbInboxConfiguration { TableName = _tableName }); + } + + public void CreateStore() + { + _tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) + .GetAwaiter() + .GetResult(); + } + + public async Task CreateStoreAsync() + { + _tableName = await DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient); + } + + public void DeleteStore() + { + DeleteStoreAsync().GetAwaiter().GetResult(); + } + + public async Task DeleteStoreAsync() + { + var client = Const.DynamoDbClient; + try + { + await client.DeleteTableAsync(_tableName); + } + catch + { + // Ignoring any error during delete, it's not important at this point + } + + DynamoDbInboxTable.Reset(); + } +} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxTest.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxTest.cs deleted file mode 100644 index 768d5c9b24..0000000000 --- a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDBInboxTest.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.DynamoDB.V4; - -namespace Paramore.Brighter.DynamoDB.V4.Tests.Inbox; - -public class DynamoDBInboxTest : InboxTests -{ - private DynamoDbInbox? _inbox; - protected override IAmAnInboxSync Inbox => _inbox!; - - protected override void CreateStore() - { - var tableName = DynamoDbInboxTable.EnsureTableIsCreatedAsync(Const.DynamoDbClient) - .GetAwaiter() - .GetResult(); - - _inbox = new DynamoDbInbox(Const.DynamoDbClient, - new DynamoDbInboxConfiguration { TableName = tableName }); - } -} diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDbInboxTable.cs b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDbInboxTable.cs index b83dfecb07..e53f7cbbaa 100644 --- a/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDbInboxTable.cs +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/Inbox/DynamoDbInboxTable.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Amazon.DynamoDBv2; @@ -58,4 +58,9 @@ public static async Task EnsureTableIsCreatedAsync(AmazonDynamoDBClient s_semaphoreSlim.Release(); } } + + public static void Reset() + { + s_tableName = null; + } } diff --git a/tests/Paramore.Brighter.DynamoDB.V4.Tests/test-configuration.json b/tests/Paramore.Brighter.DynamoDB.V4.Tests/test-configuration.json index 6a17dd68c4..a367d6a132 100644 --- a/tests/Paramore.Brighter.DynamoDB.V4.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.DynamoDB.V4.Tests/test-configuration.json @@ -1,5 +1,12 @@ { "Namespace": "Paramore.Brighter.DynamoDB.V4.Tests", + "Inbox": { + "InboxProvider": "DynamoDBInboxProvider", + "InboxProviderAsync": "DynamoDBInboxProvider", + "Category": "DynamoDB", + "CollectionName": "DynamoDBInbox", + "Prefix": "DynamoDB" + }, "Outbox": { "Transaction": "Amazon.DynamoDBv2.Model.TransactWriteItemsRequest", "OutboxProvider": "Paramore.Brighter.DynamoDB.V4.Tests.Outbox.DynamoDBOutboxProvider", diff --git a/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxAsyncTest.cs b/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxAsyncTest.cs deleted file mode 100644 index bac35f4df0..0000000000 --- a/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxAsyncTest.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Threading.Tasks; -using Google.Cloud.Firestore.V1; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Firestore; -using Paramore.Brighter.Inbox.Firestore; - -namespace Paramore.Brighter.Gcp.Tests.Firestore.Inbox; - -public class FirestoreInboxAsyncTest : InboxAsyncTest -{ - private FirestoreInbox? _inbox; - protected override IAmAnInboxAsync Inbox => _inbox!; - - protected override Task CreateStoreAsync() - { - _inbox = new FirestoreInbox(Configuration.CreateInbox()); - return Task.CompletedTask; - } - - protected override async Task DeleteStoreAsync() - { - var config = Configuration.CreateInbox(); - var firestore = await new FirestoreConnectionProvider(config) - .GetFirestoreClientAsync(); - - foreach (var command in CreatedCommands) - { - try - { - await firestore.DeleteDocumentAsync(new DeleteDocumentRequest - { - Name = config.GetDocumentName(config.Inbox!.Name, command.Id) - }); - } - catch - { - // Ignoring any error during delete, it's not important at this point - } - } - } -} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxTest.cs b/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxTest.cs deleted file mode 100644 index e97534900a..0000000000 --- a/tests/Paramore.Brighter.Gcp.Tests/Firestore/Inbox/FirestoreInboxTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Google.Cloud.Firestore.V1; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Firestore; -using Paramore.Brighter.Inbox.Firestore; - -namespace Paramore.Brighter.Gcp.Tests.Firestore.Inbox; - -public class FirestoreInboxTest : InboxTests -{ - private FirestoreInbox? _inbox; - protected override IAmAnInboxSync Inbox => _inbox!; - - protected override void CreateStore() - { - _inbox = new FirestoreInbox(Configuration.CreateInbox()); - } - - protected override void DeleteStore() - { - var config = Configuration.CreateInbox(); - var firestore = new FirestoreConnectionProvider(config).GetFirestoreClient(); - - foreach (var command in CreatedCommands) - { - try - { - firestore.DeleteDocument(new DeleteDocumentRequest - { - Name = config.GetDocumentName(config.Inbox!.Name, command.Id) - }); - } - catch (Exception e) - { - // Ignoring any error during delete, it's not important at this point - } - } - } -} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/FirestoreInboxProvider.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/FirestoreInboxProvider.cs new file mode 100644 index 0000000000..67f7f1ba0d --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/FirestoreInboxProvider.cs @@ -0,0 +1,79 @@ +using System; +using System.Threading.Tasks; +using Google.Cloud.Firestore.V1; +using Paramore.Brighter.Firestore; +using Paramore.Brighter.Gcp.Tests.Firestore; +using Paramore.Brighter.Gcp.Tests.Helper; +using Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; +using Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; +using Paramore.Brighter.Inbox.Firestore; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore; + +public class FirestoreInboxProvider : IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + private readonly FirestoreConfiguration _configuration; + + public FirestoreInboxProvider() + { + _configuration = new FirestoreConfiguration(GatewayFactory.GetProjectId(), "brighter-firestore-database") + { + Credential = GatewayFactory.GetCredential(), + Inbox = new FirestoreCollection + { + Name = $"inbox-{Uuid.New():N}", + Ttl = TimeSpan.FromMinutes(5) + } + }; + } + + public IAmAnInboxSync CreateInbox() + { + return new FirestoreInbox(_configuration); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new FirestoreInbox(_configuration); + } + + public void CreateStore() + { + } + + public Task CreateStoreAsync() + { + return Task.CompletedTask; + } + + public void DeleteStore() + { + DeleteStoreAsync().GetAwaiter().GetResult(); + } + + public async Task DeleteStoreAsync() + { + var firestore = await new FirestoreConnectionProvider(_configuration).GetFirestoreClientAsync(); + + var documents = firestore.ListDocumentsAsync( + new ListDocumentsRequest + { + Parent = $"{_configuration.DatabasePath}/documents", + CollectionId = _configuration.Inbox!.Name, + PageSize = 1000 + } + ); + + await foreach (var document in documents) + { + try + { + await firestore.DeleteDocumentAsync(new DeleteDocumentRequest { Name = document.Name }); + } + catch + { + // Ignoring any error during delete, it's not important at this point + } + } + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..3f1e2163b7 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..1a5bfaee11 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..09c4f68d28 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..a4b43195b7 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..337d49549d --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..3b84cb8319 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..c63cdab573 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..917730be9e --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Async; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new FirestoreInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..3d7fc36e7d --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..a9a65e6e63 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..f5aa8f2a6d --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..98e3cc96b3 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..e3feefa690 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..60d814dbd7 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..3e956233a0 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..b32e76c5ca --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Firestore/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Firestore.Sync; + +[Trait("Category", "Firestore")] + +[Collection("FirestoreInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new FirestoreInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..92c7bd6b46 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..1430284e29 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..d910fc0fba --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..e699a6b6ef --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..d4d8721988 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..99b382176f --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..a9146d9d28 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..a1700074f0 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SpannerInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..1078178ec0 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..045b95b9de --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..6e82613bb6 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..3ba5ceb447 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..7fa2e6051e --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..5582d4e51c --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..8166859006 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..2f3d70a183 --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; + +[Trait("Category", "Spanner")] + +[Collection("SpannerInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SpannerInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/SpannerInboxProvider.cs b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/SpannerInboxProvider.cs new file mode 100644 index 0000000000..c6daa0b01a --- /dev/null +++ b/tests/Paramore.Brighter.Gcp.Tests/Inbox/Spanner/SpannerInboxProvider.cs @@ -0,0 +1,65 @@ +using System.Threading.Tasks; +using Google.Cloud.Spanner.Data; +using Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Async; +using Paramore.Brighter.Gcp.Tests.Inbox.Spanner.Sync; +using Paramore.Brighter.Gcp.Tests.Spanner; +using Paramore.Brighter.Inbox.Spanner; +using Paramore.Brighter.Spanner; + +namespace Paramore.Brighter.Gcp.Tests.Inbox.Spanner; + +public class SpannerInboxProvider : IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + private readonly RelationalDatabaseConfiguration _configuration = new( + Const.ConnectionString, + databaseName: "brightertests", + inboxTableName: $"{Const.TablePrefix}{Uuid.New():N}", + binaryMessagePayload: false + ); + + public IAmAnInboxSync CreateInbox() + { + return new SpannerInboxAsync(_configuration); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new SpannerInboxAsync(_configuration); + } + + public void CreateStore() + { + using var connection = new SpannerConnection(_configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = SpannerInboxBuilder.GetDDL(_configuration.InBoxTableName); + command.ExecuteNonQuery(); + } + + public async Task CreateStoreAsync() + { + await using var connection = new SpannerConnection(_configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = SpannerInboxBuilder.GetDDL(_configuration.InBoxTableName); + await command.ExecuteNonQueryAsync(); + } + + public void DeleteStore() + { + using var connection = new SpannerConnection(_configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {_configuration.InBoxTableName}"; + command.ExecuteNonQuery(); + } + + public async Task DeleteStoreAsync() + { + await using var connection = new SpannerConnection(_configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {_configuration.InBoxTableName}"; + await command.ExecuteNonQueryAsync(); + } +} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxAsyncTest.cs b/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxAsyncTest.cs deleted file mode 100644 index 1acb53953a..0000000000 --- a/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxAsyncTest.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Threading.Tasks; -using Google.Cloud.Spanner.Data; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Spanner; - -namespace Paramore.Brighter.Gcp.Tests.Spanner.Inbox; - -[Trait("Category", "Spanner")] -public class SpannerInboxAsyncTest : RelationalDatabaseInboxAsyncTests -{ - protected override string DefaultConnectingString => Const.ConnectionString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new SpannerInboxAsync(configuration); - } - - protected override async Task CreateInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new SpannerConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = SpannerInboxBuilder.GetDDL(configuration.InBoxTableName); - await command.ExecuteNonQueryAsync(); - } - - protected override async Task DeleteInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new SpannerConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - await command.ExecuteNonQueryAsync(); - } -} diff --git a/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxTest.cs b/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxTest.cs deleted file mode 100644 index edffe3a067..0000000000 --- a/tests/Paramore.Brighter.Gcp.Tests/Spanner/Inbox/SpannerInboxTest.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Google.Cloud.Spanner.Data; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Spanner; - -namespace Paramore.Brighter.Gcp.Tests.Spanner.Inbox; - -[Trait("Category", "Spanner")] -public class SpannerInboxTest : RelationalDatabaseInboxTests -{ - protected override string DefaultConnectingString => Const.ConnectionString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new SpannerInboxAsync(configuration); - } - - protected override void CreateInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new SpannerConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = SpannerInboxBuilder.GetDDL(configuration.InBoxTableName); - command.ExecuteNonQuery(); - } - - protected override void DeleteInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new SpannerConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - command.ExecuteNonQuery(); - } -} diff --git a/tests/Paramore.Brighter.Gcp.Tests/test-configuration.json b/tests/Paramore.Brighter.Gcp.Tests/test-configuration.json index ec032f21f7..1b40bf55bd 100644 --- a/tests/Paramore.Brighter.Gcp.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.Gcp.Tests/test-configuration.json @@ -56,6 +56,20 @@ "ReceiveMessageTimeoutInMilliseconds": 5000 } }, + "Inboxes": { + "Firestore": { + "InboxProvider": "FirestoreInboxProvider", + "InboxProviderAsync": "FirestoreInboxProvider", + "Category": "Firestore", + "CollectionName": "FirestoreInbox" + }, + "Spanner": { + "InboxProvider": "SpannerInboxProvider", + "InboxProviderAsync": "SpannerInboxProvider", + "Category": "Spanner", + "CollectionName": "SpannerInbox" + } + }, "Outboxes": { "Firestore": { "Transaction": "Paramore.Brighter.Firestore.FirestoreTransaction", diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..473ba8b31a --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..534ad5c239 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..2ffec8c73d --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..87ca18f819 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..ab507be3c0 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..24031faa12 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..21de837090 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..85a9827c64 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..4732340bf1 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..9130fbbb50 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..ca3456d0ef --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..45a96e41a1 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..bf6f6041d3 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..80009af543 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..f4720c07d9 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..34b2f41b5c --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/MSSQLBinaryInboxProvider.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/MSSQLBinaryInboxProvider.cs new file mode 100644 index 0000000000..591677449a --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLBinary/MSSQLBinaryInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText; +using Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Async; +using Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary.Sync; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLBinary; + +public class MSSQLBinaryInboxProvider : MSSQLInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public MSSQLBinaryInboxProvider() : base(true) + { + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..4513f79a1c --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..92be5d3a64 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..c698f2767c --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..1925c17e3a --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..353d827796 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..acd8b3fa3c --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..3a68dd76ef --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..d802c92680 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..7a0022455d --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..3ad94297b9 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..9e15faa2e5 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..7da38680a1 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..3c39ce2827 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..7c3c5dcddf --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..a31553bd7b --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..48775e3363 --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +[Trait("Category", "MSSQL")] + +[Collection("MSSQLTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MSSQLTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLInboxProviderBase.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLInboxProviderBase.cs new file mode 100644 index 0000000000..156c38668a --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLInboxProviderBase.cs @@ -0,0 +1,69 @@ +using System.Threading.Tasks; +using Microsoft.Data.SqlClient; +using Paramore.Brighter.Inbox.MsSql; +using Paramore.Brighter.MsSql; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText; + +public abstract class MSSQLInboxProviderBase +{ + protected RelationalDatabaseConfiguration _configuration; + + protected MSSQLInboxProviderBase(bool binaryMessagePayload) + { + _configuration = new RelationalDatabaseConfiguration(Configuration.DefaultConnectingString, + databaseName: "brightertests", + inboxTableName: $"{Configuration.TablePrefix}{Uuid.New():N}", + binaryMessagePayload: binaryMessagePayload); + } + + public IAmAnInboxSync CreateInbox() + { + return new MsSqlInbox(_configuration); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new MsSqlInbox(_configuration); + } + + public void CreateStore() + { + Configuration.EnsureDatabaseExists(_configuration.ConnectionString); + + using var connection = new SqlConnection(_configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = SqlInboxBuilder.GetDDL(_configuration.InBoxTableName, _configuration.BinaryMessagePayload); + command.ExecuteNonQuery(); + } + + public async Task CreateStoreAsync() + { + await Configuration.EnsureDatabaseExistsAsync(_configuration.ConnectionString); + + await using var connection = new SqlConnection(_configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = SqlInboxBuilder.GetDDL(_configuration.InBoxTableName, _configuration.BinaryMessagePayload); + await command.ExecuteNonQueryAsync(); + } + + public void DeleteStore() + { + using var connection = new SqlConnection(_configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {_configuration.InBoxTableName}"; + command.ExecuteNonQuery(); + } + + public async Task DeleteStoreAsync() + { + await using var connection = new SqlConnection(_configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {_configuration.InBoxTableName}"; + await command.ExecuteNonQueryAsync(); + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLTextInboxProvider.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLTextInboxProvider.cs new file mode 100644 index 0000000000..b2ef5fe3ba --- /dev/null +++ b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MSSQLText/MSSQLTextInboxProvider.cs @@ -0,0 +1,11 @@ +using Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Async; +using Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText.Sync; + +namespace Paramore.Brighter.MSSQL.Tests.Inbox.MSSQLText; + +public class MSSQLTextInboxProvider : MSSQLInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public MSSQLTextInboxProvider() : base(false) + { + } +} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxAsyncTest.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxAsyncTest.cs deleted file mode 100644 index 3945dee68d..0000000000 --- a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxAsyncTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.MSSQL.Tests.Inbox; - -public class MsSqlBinaryInboxAsyncTest : MsSqlTextInboxAsyncTest -{ - protected override bool BinaryMessagePayload => false; -} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxTest.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxTest.cs deleted file mode 100644 index 59a7b1e589..0000000000 --- a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlBinaryInboxTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.MSSQL.Tests.Inbox; - -public class MsSqlBinaryInboxTest : MsSqlTextInboxTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxAsyncTest.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxAsyncTest.cs deleted file mode 100644 index 74259be521..0000000000 --- a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxAsyncTest.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Data.SqlClient; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MsSql; - -namespace Paramore.Brighter.MSSQL.Tests.Inbox; - -public class MsSqlTextInboxAsyncTest : RelationalDatabaseInboxAsyncTests -{ - protected override string DefaultConnectingString => Tests.Configuration.DefaultConnectingString; - protected override string TableNamePrefix => Tests.Configuration.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new MsSqlInbox(configuration); - } - - protected override async Task CreateInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await Tests.Configuration.EnsureDatabaseExistsAsync(configuration.ConnectionString); - await Tests.Configuration.CreateTableAsync(configuration.ConnectionString, SqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload)); - } - - protected override async Task DeleteInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await Tests.Configuration.DeleteTableAsync(configuration.ConnectionString, configuration.InBoxTableName); - } -} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxTest.cs b/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxTest.cs deleted file mode 100644 index d16c30d82d..0000000000 --- a/tests/Paramore.Brighter.MSSQL.Tests/Inbox/MsSqlTextInboxTest.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.Data.SqlClient; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MsSql; - -namespace Paramore.Brighter.MSSQL.Tests.Inbox; - -public class MsSqlTextInboxTest : RelationalDatabaseInboxTests -{ - protected override string DefaultConnectingString => Tests.Configuration.DefaultConnectingString; - protected override string TableNamePrefix => Tests.Configuration.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new MsSqlInbox(configuration); - } - - protected override void CreateInboxTable(RelationalDatabaseConfiguration configuration) - { - Tests.Configuration.EnsureDatabaseExists(configuration.ConnectionString); - Tests.Configuration.CreateTable(configuration.ConnectionString, SqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload)); - } - - protected override void DeleteInboxTable(RelationalDatabaseConfiguration configuration) - { - Tests.Configuration.DeleteTable(configuration.ConnectionString, configuration.InBoxTableName); - } -} diff --git a/tests/Paramore.Brighter.MSSQL.Tests/test-configuration.json b/tests/Paramore.Brighter.MSSQL.Tests/test-configuration.json index c800e220a1..2ccd906348 100644 --- a/tests/Paramore.Brighter.MSSQL.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.MSSQL.Tests/test-configuration.json @@ -1,5 +1,21 @@ { "Namespace": "Paramore.Brighter.MSSQL.Tests", + "Inboxes": { + "Text": { + "InboxProvider": "MSSQLTextInboxProvider", + "InboxProviderAsync": "MSSQLTextInboxProvider", + "Category": "MSSQL", + "CollectionName": "MSSQLTextInbox", + "Prefix": "MSSQLText" + }, + "Binary": { + "InboxProvider": "MSSQLBinaryInboxProvider", + "InboxProviderAsync": "MSSQLBinaryInboxProvider", + "Category": "MSSQL", + "CollectionName": "MSSQLBinaryInbox", + "Prefix": "MSSQLBinary" + } + }, "Outboxes": { "Text": { "Transaction": "System.Data.Common.DbTransaction", diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..fac1437fc4 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..c0ec86e512 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..eea95bbe90 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..acc00b68b1 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..61ee672491 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..d28128fec9 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..17dfa9a0a7 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..a775a0fa68 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MongoDbInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..3c2b6a857e --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..b863ea44b6 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..80e6543c38 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..92aeb07d1f --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..20084fc0a2 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..9175c9faee --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..1d7ade7b0c --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..f785ea381c --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +[Trait("Category", "MongoDB")] + +[Collection("MongoDbInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MongoDbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxAsyncTest.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxAsyncTest.cs deleted file mode 100644 index 1e2cc09290..0000000000 --- a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxAsyncTest.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading.Tasks; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MongoDb; - -namespace Paramore.Brighter.MongoDb.Tests.Inbox; - -public class MongoDbInboxAsyncTest : InboxAsyncTest -{ - private string? _collectionName; - private MongoDbInbox? _inbox; - protected override IAmAnInboxAsync Inbox => _inbox!; - - protected override Task CreateStoreAsync() - { - _collectionName = $"Inbox{Uuid.New():N}"; - _inbox = new MongoDbInbox(new MongoDbConfiguration(Const.Client, Const.DatabaseName) - { - Inbox = new MongoDbCollectionConfiguration - { - Name = _collectionName - } - }); - - return base.CreateStoreAsync(); - } - - protected override async Task DeleteStoreAsync() - { - var client = Const.Client; - await client.GetDatabase(Const.DatabaseName).DropCollectionAsync(_collectionName!); - } -} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxProvider.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxProvider.cs new file mode 100644 index 0000000000..30553176f6 --- /dev/null +++ b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxProvider.cs @@ -0,0 +1,59 @@ +using System.Threading.Tasks; +using MongoDB.Driver; +using Const = Paramore.Brighter.MongoDb.Tests.Const; +using MongoDbConfiguration = Paramore.Brighter.MongoDb.MongoDbConfiguration; +using MongoDbCollectionConfiguration = Paramore.Brighter.MongoDb.MongoDbCollectionConfiguration; +using Paramore.Brighter.Inbox.MongoDb; +using Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Async; +using Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb.Sync; + +namespace Paramore.Brighter.MongoDB.Tests.Inbox.MongoDb; + +public class MongoDbInboxProvider : IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + private readonly string _collectionName = $"Inbox{Uuid.New():N}"; + + public IAmAnInboxSync CreateInbox() + { + return new MongoDbInbox(new MongoDbConfiguration(Const.Client, Const.DatabaseName) + { + Inbox = new MongoDbCollectionConfiguration + { + Name = _collectionName + } + }); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new MongoDbInbox(new MongoDbConfiguration(Const.Client, Const.DatabaseName) + { + Inbox = new MongoDbCollectionConfiguration + { + Name = _collectionName + } + }); + } + + public void CreateStore() + { + // The collection is created automatically when the first command is added. + } + + public Task CreateStoreAsync() + { + return Task.CompletedTask; + } + + public void DeleteStore() + { + var database = Const.Client.GetDatabase(Const.DatabaseName); + database.DropCollection(_collectionName); + } + + public async Task DeleteStoreAsync() + { + var database = Const.Client.GetDatabase(Const.DatabaseName); + await database.DropCollectionAsync(_collectionName); + } +} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxTest.cs b/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxTest.cs deleted file mode 100644 index 40cc297d19..0000000000 --- a/tests/Paramore.Brighter.MongoDb.Tests/Inbox/MongoDbInboxTest.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading.Tasks; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MongoDb; - -namespace Paramore.Brighter.MongoDb.Tests.Inbox; - -public class MongoDbInboxTest : InboxTests -{ - private string? _collectionName; - private MongoDbInbox? _inbox; - protected override IAmAnInboxSync Inbox => _inbox!; - - protected override void CreateStore() - { - _collectionName = $"Inbox{Uuid.New():N}"; - _inbox = new MongoDbInbox(new MongoDbConfiguration(Const.Client, Const.DatabaseName) - { - Inbox = new MongoDbCollectionConfiguration - { - Name = _collectionName - } - }); - - base.CreateStore(); - } - - protected override void DeleteStore() - { - var client = Const.Client; - client.GetDatabase(Const.DatabaseName).DropCollection(_collectionName!); - } -} diff --git a/tests/Paramore.Brighter.MongoDb.Tests/test-configuration.json b/tests/Paramore.Brighter.MongoDb.Tests/test-configuration.json index 4f7d288b5c..71b67fa438 100644 --- a/tests/Paramore.Brighter.MongoDb.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.MongoDb.Tests/test-configuration.json @@ -1,5 +1,12 @@ { "Namespace": "Paramore.Brighter.MongoDB.Tests", + "Inbox": { + "InboxProvider": "MongoDbInboxProvider", + "InboxProviderAsync": "MongoDbInboxProvider", + "Category": "MongoDB", + "CollectionName": "MongoDbInbox", + "Prefix": "MongoDb" + }, "Outbox": { "Transaction": "global::MongoDB.Driver.IClientSessionHandle", "OutboxProvider": "Paramore.Brighter.MongoDb.Tests.Outbox.MongoDbOutboxProvider", diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..c9e757519c --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..e677aba069 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..b8d71b0f01 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..417645a346 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..3bfe0ccec5 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..a1a6f77830 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..e33ecc73f8 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..add4df3880 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..0dde9477ba --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..a55f44708e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..ab8fa4773d --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..f9343535d2 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..a837dd70ba --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..fd681f1eb5 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..5c035768df --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..6249a5a67e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/MySqlBinaryInboxProvider.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/MySqlBinaryInboxProvider.cs new file mode 100644 index 0000000000..094b8cbf3d --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Binary/MySqlBinaryInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.MySQL.Tests.Inbox.Text; +using Paramore.Brighter.MySQL.Tests.Inbox.Binary.Async; +using Paramore.Brighter.MySQL.Tests.Inbox.Binary.Sync; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Binary; + +public class MySqlBinaryInboxProvider : MySqlInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public MySqlBinaryInboxProvider() : base(true, false) + { + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..dda39842c9 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..96a2b99f9e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..3f783d511e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..2b1527277e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..eb8d0403e1 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..46584dc8f2 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..510aa1064e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..aed20ee538 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlJsonInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..a791e605cd --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..70ff2e89d1 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..ceba68513f --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..cc70b9f62d --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..0c11519a8e --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..14f3c94709 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..074971d23b --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..cffa4d5711 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlJsonInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/MySqlJsonInboxProvider.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/MySqlJsonInboxProvider.cs new file mode 100644 index 0000000000..9080e40ed1 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Json/MySqlJsonInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.MySQL.Tests.Inbox.Text; +using Paramore.Brighter.MySQL.Tests.Inbox.Json.Async; +using Paramore.Brighter.MySQL.Tests.Inbox.Json.Sync; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Json; + +public class MySqlJsonInboxProvider : MySqlInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public MySqlJsonInboxProvider() : base(false, true) + { + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxAsyncTest.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxAsyncTest.cs deleted file mode 100644 index a69d48a7ef..0000000000 --- a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxAsyncTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.MySQL.Tests.Inbox; - -public class MySqlBinaryInboxAsyncTest : MySqlTextInboxAsyncTest -{ - protected override bool BinaryMessagePayload => false; -} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxTest.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxTest.cs deleted file mode 100644 index f79b420cf5..0000000000 --- a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlBinaryInboxTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.MySQL.Tests.Inbox; - -public class MySqlBinaryInboxTest : MySqlTextInboxTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlJsonInboxTest.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlJsonInboxTest.cs deleted file mode 100644 index 219e00587b..0000000000 --- a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlJsonInboxTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -// The MIT License (MIT) -// Copyright © 2014 Ian Cooper -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace Paramore.Brighter.MySQL.Tests.Inbox; - -public class MySqlJsonInboxTest:MySqlTextInboxTest -{ - protected override bool JsonMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxAsyncTest.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxAsyncTest.cs deleted file mode 100644 index 3ae2289e12..0000000000 --- a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxAsyncTest.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Threading.Tasks; -using MySqlConnector; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MySql; - -namespace Paramore.Brighter.MySQL.Tests.Inbox; - -public class MySqlTextInboxAsyncTest : RelationalDatabaseInboxAsyncTests -{ - protected override string DefaultConnectingString => Const.DefaultConnectingString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - => new MySqlInbox(configuration); - - protected override async Task CreateInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new MySqlConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = MySqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload); - await command.ExecuteNonQueryAsync(); - } - - protected override async Task DeleteInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new MySqlConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - await command.ExecuteNonQueryAsync(); - } -} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxTest.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxTest.cs deleted file mode 100644 index 9b85db1cbf..0000000000 --- a/tests/Paramore.Brighter.MySQL.Tests/Inbox/MySqlTextInboxTest.cs +++ /dev/null @@ -1,34 +0,0 @@ -using MySqlConnector; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.MySql; - -namespace Paramore.Brighter.MySQL.Tests.Inbox; - -public class MySqlTextInboxTest : RelationalDatabaseInboxTests -{ - protected override string DefaultConnectingString => Const.DefaultConnectingString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - => new MySqlInbox(configuration); - - protected override void CreateInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new MySqlConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = MySqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload, JsonMessagePayload); - command.ExecuteNonQuery(); - } - - protected override void DeleteInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new MySqlConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - command.ExecuteNonQuery(); - } -} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..138ea25a73 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..1537780c1f --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..8430492b26 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..fbf0775c56 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..acb40911ac --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..52675ba445 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..78545e5881 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..82795cbec8 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..c113f5035d --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..3534e17934 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..35358fe972 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..9621dcff86 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..231e2ced56 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..f43ac2ec29 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..51e0f9c90c --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..12b9f3db93 --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "MySQL")] + +[Collection("MySqlTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new MySqlTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlInboxProviderBase.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlInboxProviderBase.cs new file mode 100644 index 0000000000..ec6dee013b --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlInboxProviderBase.cs @@ -0,0 +1,65 @@ +using System.Threading.Tasks; +using MySqlConnector; +using Paramore.Brighter.Inbox.MySql; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text; + +public abstract class MySqlInboxProviderBase +{ + protected RelationalDatabaseConfiguration Configuration; + + protected MySqlInboxProviderBase(bool binaryMessagePayload, bool jsonMessagePayload) + { + Configuration = new RelationalDatabaseConfiguration(Const.DefaultConnectingString, + databaseName: "brightertests", + inboxTableName: $"{Const.TablePrefix}{Uuid.New():N}", + binaryMessagePayload: binaryMessagePayload, + jsonMessagePayload: jsonMessagePayload); + } + + public void CreateStore() + { + using var connection = new MySqlConnection(Configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = MySqlInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload, Configuration.JsonMessagePayload); + command.ExecuteNonQuery(); + } + + public void DeleteStore() + { + using var connection = new MySqlConnection(Configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + command.ExecuteNonQuery(); + } + + public IAmAnInboxSync CreateInbox() + { + return new MySqlInbox(Configuration); + } + + public async Task CreateStoreAsync() + { + using var connection = new MySqlConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + using var command = connection.CreateCommand(); + command.CommandText = MySqlInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload, Configuration.JsonMessagePayload); + await command.ExecuteNonQueryAsync(); + } + + public async Task DeleteStoreAsync() + { + using var connection = new MySqlConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + await command.ExecuteNonQueryAsync(); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new MySqlInbox(Configuration); + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlTextInboxProvider.cs b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlTextInboxProvider.cs new file mode 100644 index 0000000000..c2ea58ae3a --- /dev/null +++ b/tests/Paramore.Brighter.MySQL.Tests/Inbox/Text/MySqlTextInboxProvider.cs @@ -0,0 +1,11 @@ +using Paramore.Brighter.MySQL.Tests.Inbox.Text.Async; +using Paramore.Brighter.MySQL.Tests.Inbox.Text.Sync; + +namespace Paramore.Brighter.MySQL.Tests.Inbox.Text; + +public class MySqlTextInboxProvider : MySqlInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public MySqlTextInboxProvider() : base(false, false) + { + } +} diff --git a/tests/Paramore.Brighter.MySQL.Tests/test-configuration.json b/tests/Paramore.Brighter.MySQL.Tests/test-configuration.json index 19cd4d765c..dbb8cc3bee 100644 --- a/tests/Paramore.Brighter.MySQL.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.MySQL.Tests/test-configuration.json @@ -1,5 +1,25 @@ { "Namespace": "Paramore.Brighter.MySQL.Tests", + "Inboxes": { + "Text": { + "InboxProvider": "MySqlTextInboxProvider", + "InboxProviderAsync": "MySqlTextInboxProvider", + "Category": "MySQL", + "CollectionName": "MySqlTextInbox" + }, + "Binary": { + "InboxProvider": "MySqlBinaryInboxProvider", + "InboxProviderAsync": "MySqlBinaryInboxProvider", + "Category": "MySQL", + "CollectionName": "MySqlBinaryInbox" + }, + "Json": { + "InboxProvider": "MySqlJsonInboxProvider", + "InboxProviderAsync": "MySqlJsonInboxProvider", + "Category": "MySQL", + "CollectionName": "MySqlJsonInbox" + } + }, "Outboxes": { "Text": { "Transaction": "System.Data.Common.DbTransaction", diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..85523e3e64 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..e78fb8124e --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..5ca791ab12 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..ee2f477fbe --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..794f239320 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..2416a43d7d --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..d1399703c4 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..20a980ff5e --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..4656e23a92 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..7845ceb554 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..19c045ea0b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..4f5291e4a6 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..d32cab0dc2 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..756f08d69d --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..f373a9bec7 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..a67302551b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/PostgresBinaryInboxProvider.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/PostgresBinaryInboxProvider.cs new file mode 100644 index 0000000000..280f81cf3b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Binary/PostgresBinaryInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Async; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary.Sync; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Binary; + +public class PostgresBinaryInboxProvider : PostgresInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public PostgresBinaryInboxProvider() : base(true, false) + { + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..8c7b092636 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..34b8dd147d --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..0c2da4657f --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..c4f4554265 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..e7a944ac85 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..b2f0faa86f --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..7772f35648 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..530f35092f --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..bfb0a54ab4 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..8861fe9d81 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..4072808a64 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..014a47e80d --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..e58c4bd54c --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..4e74ce49b6 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..2427902480 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..029247f297 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/PostgresJsonInboxProvider.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/PostgresJsonInboxProvider.cs new file mode 100644 index 0000000000..0ceb8dd417 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Json/PostgresJsonInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Async; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Json.Sync; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Json; + +public class PostgresJsonInboxProvider : PostgresInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public PostgresJsonInboxProvider() : base(false, true) + { + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..a75f56c82b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..986f79f62a --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..d9366c7d54 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..40e7c5a9c9 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..c705e23f88 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..f4455e9378 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..569759685a --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..fab561603e --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..9812313b87 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..fd91c7ae36 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..7d0bfabecc --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..88bd70aeaa --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..d0f8302161 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..592bf11955 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..9915dcb7c1 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..46cecc3a13 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresJsonbInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresJsonbInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/PostgresJsonbInboxProvider.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/PostgresJsonbInboxProvider.cs new file mode 100644 index 0000000000..8a1c10dbb9 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Jsonb/PostgresJsonbInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Async; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb.Sync; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Jsonb; + +public class PostgresJsonbInboxProvider : PostgresInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public PostgresJsonbInboxProvider() : base(true, true) + { + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxAsyncTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxAsyncTest.cs deleted file mode 100644 index 78adaf98bb..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxAsyncTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresBinaryInboxAsyncTest : PostgresTextInboxAsyncTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxTest.cs deleted file mode 100644 index bb1e5f499b..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresBinaryInboxTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresBinaryInboxTest : PostgresTextInboxTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxAsyncTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxAsyncTest.cs deleted file mode 100644 index 71aaad1207..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxAsyncTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -// The MIT License (MIT) -// Copyright © 2014 Ian Cooper -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresJsonInboxAsyncTest : PostgresTextInboxAsyncTest -{ - protected override bool JsonMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxTest.cs deleted file mode 100644 index 93efa91f4a..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonInboxTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -// The MIT License (MIT) -// Copyright © 2014 Ian Cooper -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresJsonInboxTest : PostgresTextInboxTest -{ - protected override bool JsonMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxAsyncTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxAsyncTest.cs deleted file mode 100644 index b922210228..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxAsyncTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -// The MIT License (MIT) -// Copyright © 2014 Ian Cooper -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresJsonbInboxAsyncTest : PostgresTextInboxAsyncTest -{ - protected override bool BinaryMessagePayload => true; - protected override bool JsonMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxTest.cs deleted file mode 100644 index 6950d2045e..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresJsonbInboxTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -// The MIT License (MIT) -// Copyright © 2014 Ian Cooper -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresJsonbInboxTest : PostgresTextInboxTest -{ - protected override bool BinaryMessagePayload => true; - protected override bool JsonMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxAsyncTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxAsyncTest.cs deleted file mode 100644 index 2073ecff0c..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxAsyncTest.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading.Tasks; -using Npgsql; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Postgres; - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresTextInboxAsyncTest : RelationalDatabaseInboxAsyncTests -{ - protected override string DefaultConnectingString => Const.ConnectionString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new PostgreSqlInbox(configuration); - } - - protected override async Task CreateInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new NpgsqlConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = PostgreSqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload, JsonMessagePayload); - await command.ExecuteNonQueryAsync(); - } - - protected override async Task DeleteInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await using var connection = new NpgsqlConnection(configuration.ConnectionString); - await connection.OpenAsync(); - await using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - await command.ExecuteNonQueryAsync(); - } -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxTest.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxTest.cs deleted file mode 100644 index 677fc937dc..0000000000 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/PostgresTextInboxTest.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Npgsql; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Postgres; - -namespace Paramore.Brighter.PostgresSQL.Tests.Inbox; - -public class PostgresTextInboxTest : RelationalDatabaseInboxTests -{ - protected override string DefaultConnectingString => Const.ConnectionString; - protected override string TableNamePrefix => Const.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new PostgreSqlInbox(configuration); - } - - protected override void CreateInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new NpgsqlConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = PostgreSqlInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload, JsonMessagePayload); - command.ExecuteNonQuery(); - } - - protected override void DeleteInboxTable(RelationalDatabaseConfiguration configuration) - { - using var connection = new NpgsqlConnection(configuration.ConnectionString); - connection.Open(); - using var command = connection.CreateCommand(); - command.CommandText = $"DROP TABLE {configuration.InBoxTableName}"; - command.ExecuteNonQuery(); - } -} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..9d6b754f76 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..d6e16df2db --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..ae7afcac73 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..f16c82123c --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..ff58351828 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..5675edec2b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..82e36bcf6e --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..fea45f9151 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..8db50f97f7 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..a61f25e6bf --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..cf188a7616 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..fbc953a9bd --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..0bf01c0be5 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..e7bd780c95 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..91640ebd2b --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..e65e80a61a --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +[Trait("Category", "PostgresSql")] + +[Collection("PostgresTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new PostgresTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresInboxProviderBase.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresInboxProviderBase.cs new file mode 100644 index 0000000000..51eca9c959 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresInboxProviderBase.cs @@ -0,0 +1,65 @@ +using Npgsql; +using Paramore.Brighter.Inbox.Postgres; +using System.Threading.Tasks; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; + +public abstract class PostgresInboxProviderBase +{ + protected RelationalDatabaseConfiguration Configuration; + + protected PostgresInboxProviderBase(bool binaryMessagePayload, bool jsonMessagePayload) + { + Configuration = new RelationalDatabaseConfiguration(Const.ConnectionString, + databaseName: "brightertests", + inboxTableName: $"{Const.TablePrefix}{Uuid.New():N}", + binaryMessagePayload: binaryMessagePayload, + jsonMessagePayload: jsonMessagePayload); + } + + public void CreateStore() + { + using var connection = new NpgsqlConnection(Configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = PostgreSqlInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload, Configuration.JsonMessagePayload); + command.ExecuteNonQuery(); + } + + public void DeleteStore() + { + using var connection = new NpgsqlConnection(Configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + command.ExecuteNonQuery(); + } + + public IAmAnInboxSync CreateInbox() + { + return new PostgreSqlInbox(Configuration); + } + + public async Task CreateStoreAsync() + { + await using var connection = new NpgsqlConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = PostgreSqlInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload, Configuration.JsonMessagePayload); + await command.ExecuteNonQueryAsync(); + } + + public async Task DeleteStoreAsync() + { + await using var connection = new NpgsqlConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + await command.ExecuteNonQueryAsync(); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new PostgreSqlInbox(Configuration); + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresTextInboxProvider.cs b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresTextInboxProvider.cs new file mode 100644 index 0000000000..30f0d2d526 --- /dev/null +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/Inbox/Text/PostgresTextInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Async; +using Paramore.Brighter.PostgresSQL.Tests.Inbox.Text.Sync; + +namespace Paramore.Brighter.PostgresSQL.Tests.Inbox.Text; + +public class PostgresTextInboxProvider : PostgresInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public PostgresTextInboxProvider() : base(false, false) + { + } +} diff --git a/tests/Paramore.Brighter.PostgresSQL.Tests/test-configuration.json b/tests/Paramore.Brighter.PostgresSQL.Tests/test-configuration.json index 8531da2aaa..ed50a341db 100644 --- a/tests/Paramore.Brighter.PostgresSQL.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.PostgresSQL.Tests/test-configuration.json @@ -1,5 +1,31 @@ { "Namespace": "Paramore.Brighter.PostgresSQL.Tests", + "Inboxes": { + "Text": { + "InboxProvider": "PostgresTextInboxProvider", + "InboxProviderAsync": "PostgresTextInboxProvider", + "Category": "PostgresSql", + "CollectionName": "PostgresTextInbox" + }, + "Binary": { + "InboxProvider": "PostgresBinaryInboxProvider", + "InboxProviderAsync": "PostgresBinaryInboxProvider", + "Category": "PostgresSql", + "CollectionName": "PostgresBinaryInbox" + }, + "Json": { + "InboxProvider": "PostgresJsonInboxProvider", + "InboxProviderAsync": "PostgresJsonInboxProvider", + "Category": "PostgresSql", + "CollectionName": "PostgresJsonInbox" + }, + "Jsonb": { + "InboxProvider": "PostgresJsonbInboxProvider", + "InboxProviderAsync": "PostgresJsonbInboxProvider", + "Category": "PostgresSql", + "CollectionName": "PostgresJsonbInbox" + } + }, "Outboxes": { "Text": { "Transaction": "System.Data.Common.DbTransaction", diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..d555adb2d3 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..c4c343e945 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..00c9f2a7e5 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..c919935259 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..c263c8d470 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..3d4c7e800f --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..387c855791 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..5661498a67 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..3c53f6faec --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..38419f0369 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..0bf29ae259 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..2eb55070a9 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..6343da76a0 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..c2fe7ec2a1 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..b4bfb45264 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..ab555b5317 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteBinaryInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteBinaryInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/SqliteBinaryInboxProvider.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/SqliteBinaryInboxProvider.cs new file mode 100644 index 0000000000..ae7dfeaa71 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Binary/SqliteBinaryInboxProvider.cs @@ -0,0 +1,12 @@ +using Paramore.Brighter.Sqlite.Tests.Inbox.Text; +using Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Async; +using Paramore.Brighter.Sqlite.Tests.Inbox.Binary.Sync; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Binary; + +public class SqliteBinaryInboxProvider : SqliteInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public SqliteBinaryInboxProvider() : base(true) + { + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxAsyncTest.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxAsyncTest.cs deleted file mode 100644 index a82fd691ef..0000000000 --- a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxAsyncTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.Sqlite.Tests.Inbox; - -public class SqliteBinaryInboxAsyncTest : SqliteTextInboxAsyncTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxTest.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxTest.cs deleted file mode 100644 index ac2dec7c88..0000000000 --- a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteBinaryInboxTest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Paramore.Brighter.Sqlite.Tests.Inbox; - -public class SqliteBinaryInboxTest : SqliteTextInboxTest -{ - protected override bool BinaryMessagePayload => true; -} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxAsyncTest.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxAsyncTest.cs deleted file mode 100644 index ff9b41267f..0000000000 --- a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxAsyncTest.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Data.Sqlite; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Sqlite; - -namespace Paramore.Brighter.Sqlite.Tests.Inbox; - -public class SqliteTextInboxAsyncTest : RelationalDatabaseInboxAsyncTests -{ - protected override string DefaultConnectingString => Tests.Configuration.ConnectionString; - protected override string TableNamePrefix => Tests.Configuration.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new SqliteInbox(configuration); - } - - protected override async Task CreateInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await Tests.Configuration.CreateTableAsync(configuration.ConnectionString, SqliteInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload)); - } - - protected override async Task DeleteInboxTableAsync(RelationalDatabaseConfiguration configuration) - { - await Tests.Configuration.DeleteTableAsync(configuration.ConnectionString, configuration.InBoxTableName); - } -} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxTest.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxTest.cs deleted file mode 100644 index 9e644be6f5..0000000000 --- a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/SqliteTextInboxTest.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.Data.Sqlite; -using Paramore.Brighter.Base.Test.Inbox; -using Paramore.Brighter.Inbox.Sqlite; - -namespace Paramore.Brighter.Sqlite.Tests.Inbox; - -public class SqliteTextInboxTest : RelationalDatabaseInboxTests -{ - protected override string DefaultConnectingString => Tests.Configuration.ConnectionString; - protected override string TableNamePrefix => Tests.Configuration.TablePrefix; - protected override bool BinaryMessagePayload => false; - protected override bool JsonMessagePayload => false; - - protected override RelationalDatabaseInbox CreateInbox(RelationalDatabaseConfiguration configuration) - { - return new SqliteInbox(configuration); - } - - protected override void CreateInboxTable(RelationalDatabaseConfiguration configuration) - { - Tests.Configuration.CreateTable(configuration.ConnectionString, SqliteInboxBuilder.GetDDL(configuration.InBoxTableName, BinaryMessagePayload)); - } - - protected override void DeleteInboxTable(RelationalDatabaseConfiguration configuration) - { - Tests.Configuration.DeleteTable(configuration.ConnectionString, configuration.InBoxTableName); - } -} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs new file mode 100644 index 0000000000..19e68cd40c --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/IAmAnInboxProviderAsync.cs @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs new file mode 100644 index 0000000000..b8f68a5e47 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..e92d9e3e3c --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs new file mode 100644 index 0000000000..c3e6f52258 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs new file mode 100644 index 0000000000..8ea80cb87d --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs new file mode 100644 index 0000000000..c65b16a6d4 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..6a6962e8a8 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs new file mode 100644 index 0000000000..7486ce6b1a --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteTextInboxProvider(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs new file mode 100644 index 0000000000..82e4ed20c8 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/IAmAnInboxProviderSync.cs @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs new file mode 100644 index 0000000000..f49a5d857a --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..c055d6417a --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs new file mode 100644 index 0000000000..4f9c5c86cb --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs new file mode 100644 index 0000000000..f5373f1aa7 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs new file mode 100644 index 0000000000..076ec4d4b4 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..cbbbb03885 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs new file mode 100644 index 0000000000..f153f85d31 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/Generated/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +[Trait("Category", "Sqlite")] + +[Collection("SqliteTextInbox")] +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new SqliteTextInboxProvider(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteInboxProviderBase.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteInboxProviderBase.cs new file mode 100644 index 0000000000..39c4e2b83d --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteInboxProviderBase.cs @@ -0,0 +1,74 @@ +using System.Threading.Tasks; +using Microsoft.Data.Sqlite; +using Paramore.Brighter.Inbox.Sqlite; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text; + +public abstract class SqliteInboxProviderBase +{ + protected RelationalDatabaseConfiguration Configuration; + + protected SqliteInboxProviderBase(bool binaryMessagePayload) + { + Configuration = new RelationalDatabaseConfiguration(Tests.Configuration.ConnectionString, + databaseName: "brightertests", + inboxTableName: $"{Tests.Configuration.TablePrefix}{Uuid.New():N}", + binaryMessagePayload: binaryMessagePayload); + } + + public void CreateStore() + { + using var connection = new SqliteConnection(Configuration.ConnectionString); + connection.Open(); + using (var walCommand = connection.CreateCommand()) + { + walCommand.CommandText = "PRAGMA journal_mode=WAL;"; + walCommand.ExecuteNonQuery(); + } + using var command = connection.CreateCommand(); + command.CommandText = SqliteInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload); + command.ExecuteNonQuery(); + } + + public void DeleteStore() + { + using var connection = new SqliteConnection(Configuration.ConnectionString); + connection.Open(); + using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + command.ExecuteNonQuery(); + } + + public IAmAnInboxSync CreateInbox() + { + return new SqliteInbox(Configuration); + } + + public async Task CreateStoreAsync() + { + await using var connection = new SqliteConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + await using (var walCommand = connection.CreateCommand()) + { + walCommand.CommandText = "PRAGMA journal_mode=WAL;"; + await walCommand.ExecuteNonQueryAsync(); + } + await using var command = connection.CreateCommand(); + command.CommandText = SqliteInboxBuilder.GetDDL(Configuration.InBoxTableName, Configuration.BinaryMessagePayload); + await command.ExecuteNonQueryAsync(); + } + + public async Task DeleteStoreAsync() + { + await using var connection = new SqliteConnection(Configuration.ConnectionString); + await connection.OpenAsync(); + await using var command = connection.CreateCommand(); + command.CommandText = $"DROP TABLE {Configuration.InBoxTableName}"; + await command.ExecuteNonQueryAsync(); + } + + public IAmAnInboxAsync CreateInboxAsync() + { + return new SqliteInbox(Configuration); + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteTextInboxProvider.cs b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteTextInboxProvider.cs new file mode 100644 index 0000000000..f7863bf015 --- /dev/null +++ b/tests/Paramore.Brighter.Sqlite.Tests/Inbox/Text/SqliteTextInboxProvider.cs @@ -0,0 +1,11 @@ +using Paramore.Brighter.Sqlite.Tests.Inbox.Text.Async; +using Paramore.Brighter.Sqlite.Tests.Inbox.Text.Sync; + +namespace Paramore.Brighter.Sqlite.Tests.Inbox.Text; + +public class SqliteTextInboxProvider : SqliteInboxProviderBase, IAmAnInboxProviderSync, IAmAnInboxProviderAsync +{ + public SqliteTextInboxProvider() : base(false) + { + } +} diff --git a/tests/Paramore.Brighter.Sqlite.Tests/test-configuration.json b/tests/Paramore.Brighter.Sqlite.Tests/test-configuration.json index dc336e5884..b71d51f65a 100644 --- a/tests/Paramore.Brighter.Sqlite.Tests/test-configuration.json +++ b/tests/Paramore.Brighter.Sqlite.Tests/test-configuration.json @@ -1,5 +1,19 @@ { "Namespace": "Paramore.Brighter.Sqlite.Tests", + "Inboxes": { + "Text": { + "InboxProvider": "SqliteTextInboxProvider", + "InboxProviderAsync": "SqliteTextInboxProvider", + "Category": "Sqlite", + "CollectionName": "SqliteTextInbox" + }, + "Binary": { + "InboxProvider": "SqliteBinaryInboxProvider", + "InboxProviderAsync": "SqliteBinaryInboxProvider", + "Category": "Sqlite", + "CollectionName": "SqliteBinaryInbox" + } + }, "Outboxes": { "Text": { "Transaction": "System.Data.Common.DbTransaction", diff --git a/tools/Paramore.Brighter.Test.Generator/Configuration/InboxConfiguration.cs b/tools/Paramore.Brighter.Test.Generator/Configuration/InboxConfiguration.cs new file mode 100644 index 0000000000..dbd2b0c1ba --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Configuration/InboxConfiguration.cs @@ -0,0 +1,64 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +namespace Paramore.Brighter.Test.Generator.Configuration; + +/// +/// Represents the configuration for generating inbox tests. +/// +public class InboxConfiguration +{ + /// + /// Gets or sets the prefix to use for the generated test class names. + /// + public string Prefix { get; set; } = string.Empty; + + /// + /// Gets or sets the inbox provider implementation to test for the synchronous variant. + /// If null or empty, the synchronous test suite is not generated. + /// + public string? InboxProvider { get; set; } + + /// + /// Gets or sets the inbox provider implementation to test for the asynchronous variant. + /// If null or empty, the asynchronous test suite is not generated. + /// + public string? InboxProviderAsync { get; set; } + + /// + /// Gets or sets the namespace for the generated inbox test code. If null, uses the parent configuration's namespace. + /// + public string? Namespace { get; set; } + + /// + /// Gets or sets the test category to apply to generated test classes. + /// + public string? Category { get; set; } + + /// + /// Gets or sets the xUnit collection name to apply to generated test classes. + /// + public string? CollectionName { get; set; } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Configuration/TestConfiguration.cs b/tools/Paramore.Brighter.Test.Generator/Configuration/TestConfiguration.cs index e6df245a28..97ee3ffb93 100644 --- a/tools/Paramore.Brighter.Test.Generator/Configuration/TestConfiguration.cs +++ b/tools/Paramore.Brighter.Test.Generator/Configuration/TestConfiguration.cs @@ -1,4 +1,4 @@ -#region Licence +#region Licence /* The MIT License (MIT) Copyright © 2014 Ian Cooper @@ -76,4 +76,17 @@ public class TestConfiguration /// Use this when testing multiple gateway implementations (e.g., RabbitMQ, AWS SNS/SQS, Azure Service Bus). /// public Dictionary? MessagingGateways { get; set; } + + /// + /// Gets or sets the inbox configuration for generating inbox tests. + /// Use this for a single inbox implementation, or use for multiple implementations. + /// + public InboxConfiguration? Inbox { get; set; } + + /// + /// Gets or sets a dictionary of named inbox configurations for generating multiple inbox tests. + /// The key is used as the prefix for generated test class names if the configuration doesn't specify one. + /// Use this when testing multiple inbox implementations (e.g., Text, Binary). + /// + public Dictionary? Inboxes { get; set; } } diff --git a/tools/Paramore.Brighter.Test.Generator/Generators/InboxGenerator.cs b/tools/Paramore.Brighter.Test.Generator/Generators/InboxGenerator.cs new file mode 100644 index 0000000000..1d8f236320 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Generators/InboxGenerator.cs @@ -0,0 +1,129 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Paramore.Brighter.Test.Generator.Configuration; + +namespace Paramore.Brighter.Test.Generator.Generators; + +/// +/// Generates inbox test code from Liquid templates based on +/// The logger instance used for diagnostic output during generation. +public class InboxGenerator(ILogger logger) : BaseGenerator(logger) +{ + /// + /// Generates inbox test files for the configured inbox(es) in the provided + /// The root test configuration containing inbox settings and destination folder. + public async Task GenerateAsync(TestConfiguration configuration) + { + if (configuration.Inbox != null) + { + await GenerateInboxAsync(configuration, configuration.Inbox); + } + else if (configuration.Inboxes != null) + { + foreach (var (key, inboxConfiguration) in configuration.Inboxes) + { + logger.LogInformation("Generating inbox test for {InboxName}", key); + await GenerateInboxAsync(configuration, inboxConfiguration, key); + } + } + else + { + logger.LogInformation("No inbox configured"); + } + } + + private async Task GenerateInboxAsync( + TestConfiguration configuration, + InboxConfiguration inboxConfiguration, + string? key = null) + { + var prefix = inboxConfiguration.Prefix; + if (string.IsNullOrEmpty(prefix)) + { + prefix = key; + } + + if (string.IsNullOrEmpty(prefix)) + { + logger.LogWarning("Inbox configuration has no prefix and no key was provided; skipping"); + return; + } + + inboxConfiguration.Prefix = $".{prefix}"; + + if (!string.IsNullOrEmpty(inboxConfiguration.InboxProvider)) + { + await GenerateAsync( + configuration, + Path.Combine("Inbox", prefix, "Generated", "Sync"), + Path.Combine("Inbox", "Sync"), + inboxConfiguration + ); + } + + if (!string.IsNullOrEmpty(inboxConfiguration.InboxProviderAsync)) + { + await GenerateAsync( + configuration, + Path.Combine("Inbox", prefix, "Generated", "Async"), + Path.Combine("Inbox", "Async"), + inboxConfiguration + ); + } + } + + /// + /// + /// Applies default values from the root + protected override Task GenerateAsync( + TestConfiguration configuration, + string prefix, + string templateFolderName, + object model, + Func? ignore = null) + { + if (model is InboxConfiguration inboxConfiguration) + { + if (string.IsNullOrEmpty(inboxConfiguration.Namespace)) + { + inboxConfiguration.Namespace = configuration.Namespace; + } + } + + return base.GenerateAsync(configuration, prefix, templateFolderName, model, ignore); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Paramore.Brighter.Test.Generator.csproj b/tools/Paramore.Brighter.Test.Generator/Paramore.Brighter.Test.Generator.csproj index 1ad0c93e92..f2e22ebb8a 100644 --- a/tools/Paramore.Brighter.Test.Generator/Paramore.Brighter.Test.Generator.csproj +++ b/tools/Paramore.Brighter.Test.Generator/Paramore.Brighter.Test.Generator.csproj @@ -1,4 +1,4 @@ - + Exe @@ -37,6 +37,18 @@ Always + + Always + + + + Always + + + + Always + + diff --git a/tools/Paramore.Brighter.Test.Generator/Program.cs b/tools/Paramore.Brighter.Test.Generator/Program.cs index b12b2b6afa..53097facc4 100644 --- a/tools/Paramore.Brighter.Test.Generator/Program.cs +++ b/tools/Paramore.Brighter.Test.Generator/Program.cs @@ -1,4 +1,4 @@ -#region Licence +#region Licence /* The MIT License (MIT) Copyright © 2014 Ian Cooper @@ -43,7 +43,7 @@ THE SOFTWARE. */ }; var command = new RootCommand( - "Generates test code for Brighter shared and outbox components from a configuration file" + "Generates test code for Brighter shared, inbox, outbox, and messaging gateway components from a configuration file" ); command.Options.Add(configurationFileOptions); @@ -91,6 +91,7 @@ THE SOFTWARE. */ } await new SharedGenerator(factory.CreateLogger()).GenerateAsync(configuration); + await new InboxGenerator(factory.CreateLogger()).GenerateAsync(configuration); await new OutboxGenerator(factory.CreateLogger()).GenerateAsync(configuration); await new MessagingGatewayGenerator( factory.CreateLogger() diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/IAmAnInboxProviderAsync.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/IAmAnInboxProviderAsync.cs.liquid new file mode 100644 index 0000000000..a7691f0ec9 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/IAmAnInboxProviderAsync.cs.liquid @@ -0,0 +1,54 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderAsync +{ + /// + /// Creates the inbox data store. + /// + Task CreateStoreAsync(); + + /// + /// Deletes the inbox data store. + /// + Task DeleteStoreAsync(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxAsync CreateInboxAsync(); +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs.liquid new file mode 100644 index 0000000000..a60f7a6440 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async.cs.liquid @@ -0,0 +1,50 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + var loadedCommand = await inbox.GetAsync(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs.liquid new file mode 100644 index 0000000000..3034097eb2 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async.cs.liquid @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs.liquid new file mode 100644 index 0000000000..95a9ec83af --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async.cs.liquid @@ -0,0 +1,49 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + await inbox.AddAsync(command, contextKey, null); + await inbox.AddAsync(command, contextKey, null); + + // Assert + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs.liquid new file mode 100644 index 0000000000..af9fdfb4f9 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async.cs.liquid @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False_Async() + { + // Arrange + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act + var exists = await inbox.ExistsAsync(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs.liquid new file mode 100644 index 0000000000..52a2aa43d7 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async.cs.liquid @@ -0,0 +1,48 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, contextKey, null); + + // Act + var exists = await inbox.ExistsAsync(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs.liquid new file mode 100644 index 0000000000..ef10373f5c --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async.cs.liquid @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInboxAsync(); + await inbox.AddAsync(command, Uuid.NewAsString(), null); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(command.Id, Uuid.NewAsString(), null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs.liquid new file mode 100644 index 0000000000..fc4e5e84d3 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Async/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async.cs.liquid @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System.Threading.Tasks; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Async; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IAsyncLifetime +{ + private readonly IAmAnInboxProviderAsync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new {{ InboxProviderAsync }}(); + } + + [Fact] + public async Task When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException_Async() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInboxAsync(); + + // Act & Assert + await Assert.ThrowsAsync>(async () => await inbox.GetAsync(commandId, contextKey, null)); + } + + public async Task InitializeAsync() + { + await _inboxProvider.CreateStoreAsync(); + } + + public async Task DisposeAsync() + { + await _inboxProvider.DeleteStoreAsync(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/IAmAnInboxProviderSync.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/IAmAnInboxProviderSync.cs.liquid new file mode 100644 index 0000000000..b253c6a008 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/IAmAnInboxProviderSync.cs.liquid @@ -0,0 +1,52 @@ +#region Licence + +/* The MIT License (MIT) +Copyright © 2014 Ian Cooper + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#endregion + +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; + +/// +/// Provider for managing inbox storage and creating inbox instances. +/// +public interface IAmAnInboxProviderSync +{ + /// + /// Creates the inbox data store. + /// + void CreateStore(); + + /// + /// Deletes the inbox data store. + /// + void DeleteStore(); + + /// + /// Creates a new inbox instance for storing and retrieving commands. + /// + /// A new + IAmAnInboxSync CreateInbox(); +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs.liquid new file mode 100644 index 0000000000..bd2b597c6d --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved.cs.liquid @@ -0,0 +1,46 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingACommandToTheInboxItCanBeRetrieved : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingACommandToTheInboxItCanBeRetrieved() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Command_To_The_Inbox_It_Can_Be_Retrieved() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + var loadedCommand = inbox.Get(command.Id, contextKey, null); + + // Assert + Assert.NotNull(loadedCommand); + Assert.Equal(command.Value, loadedCommand.Value); + Assert.Equal(command.Id, loadedCommand.Id); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs.liquid new file mode 100644 index 0000000000..e018e467a0 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw.cs.liquid @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithDifferentContextKeyItShouldNotThrow() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Different_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, Uuid.NewAsString(), null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs.liquid new file mode 100644 index 0000000000..3c6bf59bc9 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw.cs.liquid @@ -0,0 +1,45 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenAddingADuplicateCommandWithSameContextKeyItShouldNotThrow() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Adding_A_Duplicate_Command_With_Same_Context_Key_It_Should_Not_Throw() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + + // Act + inbox.Add(command, contextKey, null); + inbox.Add(command, contextKey, null); + + // Assert + var exists = inbox.Exists(command.Id, contextKey, null); + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs.liquid new file mode 100644 index 0000000000..b1c4e72f49 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False.cs.liquid @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfANonExistentCommandExistsItShouldReturnFalse() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_A_Non_Existent_Command_Exists_It_Should_Return_False() + { + // Arrange + var inbox = _inboxProvider.CreateInbox(); + + // Act + var exists = inbox.Exists(Uuid.NewAsString(), Uuid.NewAsString(), null); + + // Assert + Assert.False(exists, "A command should not exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs.liquid new file mode 100644 index 0000000000..ba517dd776 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True.cs.liquid @@ -0,0 +1,44 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenCheckingIfAnExistingCommandExistsItShouldReturnTrue() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Checking_If_An_Existing_Command_Exists_It_Should_Return_True() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, contextKey, null); + + // Act + var exists = inbox.Exists(command.Id, contextKey, null); + + // Assert + Assert.True(exists, $"A command with '{command.Id.Value}' Id should exist"); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs.liquid new file mode 100644 index 0000000000..599a16ee7c --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException.cs.liquid @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingACommandWithWrongContextKeyItShouldThrowRequestNotFoundException() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Command_With_Wrong_Context_Key_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var command = new MyCommand { Value = Uuid.NewAsString() }; + var inbox = _inboxProvider.CreateInbox(); + inbox.Add(command, Uuid.NewAsString(), null); + + // Act & Assert + Assert.Throws>(() => inbox.Get(command.Id, Uuid.NewAsString(), null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +} diff --git a/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs.liquid b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs.liquid new file mode 100644 index 0000000000..510b555cd4 --- /dev/null +++ b/tools/Paramore.Brighter.Test.Generator/Templates/Inbox/Sync/When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException.cs.liquid @@ -0,0 +1,41 @@ +// +// This file is auto-generated by Paramore.Brighter.Test.Generator +// + +using System; +using Paramore.Brighter.Base.Test.Requests; +using Paramore.Brighter.Inbox.Exceptions; +using Xunit; + +namespace {{ Namespace }}.Inbox{{ Prefix }}.Sync; +{% if Category != null %} +[Trait("Category", "{{Category}}")]{% endif %} +{% if CollectionName != null %} +[Collection("{{CollectionName}}")]{% endif %} +public class WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException : IDisposable +{ + private readonly IAmAnInboxProviderSync _inboxProvider; + + public WhenGettingANonExistentCommandItShouldThrowRequestNotFoundException() + { + _inboxProvider = new {{ InboxProvider }}(); + _inboxProvider.CreateStore(); + } + + [Fact] + public void When_Getting_A_Non_Existent_Command_It_Should_Throw_RequestNotFoundException() + { + // Arrange + var contextKey = Uuid.NewAsString(); + var commandId = Uuid.NewAsString(); + var inbox = _inboxProvider.CreateInbox(); + + // Act & Assert + Assert.Throws>(() => inbox.Get(commandId, contextKey, null)); + } + + public void Dispose() + { + _inboxProvider.DeleteStore(); + } +}