-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop-v0' into CustomQueueName
- Loading branch information
Showing
28 changed files
with
1,413 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-2020 Rasmus Mikkelsen | ||
// Copyright (c) 2015-2020 eBay Software Foundation | ||
// https://github.com/eventflow/EventFlow | ||
// | ||
// 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. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Configuration; | ||
using EventFlow.EntityFramework.Extensions; | ||
using EventFlow.EntityFramework.Tests.Model; | ||
using EventFlow.EntityFramework.Tests.MsSql.IncludeTests; | ||
using EventFlow.EntityFramework.Tests.MsSql.IncludeTests.Commands; | ||
using EventFlow.EntityFramework.Tests.MsSql.IncludeTests.Queries; | ||
using EventFlow.Extensions; | ||
using EventFlow.TestHelpers; | ||
using EventFlow.TestHelpers.MsSql; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace EventFlow.EntityFramework.Tests.MsSql | ||
{ | ||
[Category(Categories.Integration)] | ||
public class EfMsSqlReadStoreIncludeTests : IntegrationTest | ||
{ | ||
private IMsSqlDatabase _testDatabase; | ||
|
||
protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions) | ||
{ | ||
_testDatabase = MsSqlHelpz.CreateDatabase("eventflow"); | ||
|
||
return eventFlowOptions | ||
.RegisterServices(sr => sr.Register(c => _testDatabase.ConnectionString)) | ||
.ConfigureEntityFramework(EntityFrameworkConfiguration.New) | ||
.AddDbContextProvider<TestDbContext, MsSqlDbContextProvider>() | ||
.ConfigureForReadStoreIncludeTest() | ||
.AddDefaults(typeof(EfMsSqlReadStoreIncludeTests).Assembly) | ||
.CreateResolver(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_testDatabase.DisposeSafe("Failed to delete database"); | ||
} | ||
|
||
[Test] | ||
public async Task ReadModelContainsPersonNameAfterCreation() | ||
{ | ||
// Arrange | ||
var id = PersonId.New; | ||
|
||
// Act | ||
await CommandBus | ||
.PublishAsync(new CreatePersonCommand(id, "Bob"), CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
var readModel = await QueryProcessor | ||
.ProcessAsync(new PersonGetQuery(id), CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
// Assert | ||
readModel.Should().NotBeNull(); | ||
readModel.Name.Should().Be("Bob"); | ||
readModel.Addresses.Should().BeNullOrEmpty(); | ||
} | ||
|
||
[Test] | ||
public async Task ReadModelContainsPersonAddressesAfterAdd() | ||
{ | ||
// Arrange | ||
var id = PersonId.New; | ||
await CommandBus | ||
.PublishAsync(new CreatePersonCommand(id, "Bob"), CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
// Act | ||
var address1 = new Address(AddressId.New, "Smith street 4.", "1234", "New York", "US"); | ||
await CommandBus | ||
.PublishAsync(new AddAddressCommand(id, | ||
address1), | ||
CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
var address2 = new Address(AddressId.New, "Musterstraße 42.", "6541", "Berlin", "DE"); | ||
await CommandBus | ||
.PublishAsync(new AddAddressCommand(id, | ||
address2), | ||
CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
var readModel = await QueryProcessor | ||
.ProcessAsync(new PersonGetQuery(id), CancellationToken.None) | ||
.ConfigureAwait(false); | ||
|
||
// Assert | ||
readModel.Should().NotBeNull(); | ||
readModel.NumberOfAddresses.Should().Be(2); | ||
readModel.Addresses.Should().HaveCount(2); | ||
readModel.Addresses.Should().ContainEquivalentOf(address1); | ||
readModel.Addresses.Should().ContainEquivalentOf(address2); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Source/EventFlow.EntityFramework.Tests/MsSql/IncludeTests/Address.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-2020 Rasmus Mikkelsen | ||
// Copyright (c) 2015-2020 eBay Software Foundation | ||
// https://github.com/eventflow/EventFlow | ||
// | ||
// 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. | ||
|
||
using EventFlow.Entities; | ||
|
||
namespace EventFlow.EntityFramework.Tests.MsSql.IncludeTests | ||
{ | ||
public class Address : Entity<AddressId> | ||
{ | ||
public string Street { get; set; } | ||
public string PostalCode { get; set; } | ||
public string City { get; set; } | ||
public string Country { get; set; } | ||
|
||
public Address(AddressId id, string street, string postalCode, string city, string country) : base(id) | ||
{ | ||
Street = street; | ||
PostalCode = postalCode; | ||
City = city; | ||
Country = country; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Source/EventFlow.EntityFramework.Tests/MsSql/IncludeTests/AddressId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-2020 Rasmus Mikkelsen | ||
// Copyright (c) 2015-2020 eBay Software Foundation | ||
// https://github.com/eventflow/EventFlow | ||
// | ||
// 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. | ||
|
||
using EventFlow.Core; | ||
|
||
namespace EventFlow.EntityFramework.Tests.MsSql.IncludeTests | ||
{ | ||
public class AddressId : Identity<AddressId> | ||
{ | ||
public AddressId(string value) : base(value) | ||
{ | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Source/EventFlow.EntityFramework.Tests/MsSql/IncludeTests/Commands/AddAddressCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-2020 Rasmus Mikkelsen | ||
// Copyright (c) 2015-2020 eBay Software Foundation | ||
// https://github.com/eventflow/EventFlow | ||
// | ||
// 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. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Commands; | ||
|
||
namespace EventFlow.EntityFramework.Tests.MsSql.IncludeTests.Commands | ||
{ | ||
public class AddAddressCommand : Command<PersonAggregate, PersonId> | ||
{ | ||
public Address PersonAddress { get; } | ||
|
||
public AddAddressCommand(PersonId aggregateId, Address personAddress) : base(aggregateId) | ||
{ | ||
PersonAddress = personAddress; | ||
} | ||
} | ||
|
||
public class AddAddressCommandHandler : CommandHandler<PersonAggregate, PersonId, AddAddressCommand> | ||
{ | ||
public override Task ExecuteAsync(PersonAggregate aggregate, AddAddressCommand command, CancellationToken cancellationToken) | ||
{ | ||
aggregate.AddAddress(command.PersonAddress); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Source/EventFlow.EntityFramework.Tests/MsSql/IncludeTests/Commands/CreatePersonCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-2020 Rasmus Mikkelsen | ||
// Copyright (c) 2015-2020 eBay Software Foundation | ||
// https://github.com/eventflow/EventFlow | ||
// | ||
// 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. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Commands; | ||
|
||
namespace EventFlow.EntityFramework.Tests.MsSql.IncludeTests.Commands | ||
{ | ||
public class CreatePersonCommand : Command<PersonAggregate,PersonId> | ||
{ | ||
public string Name { get; } | ||
|
||
public CreatePersonCommand(PersonId aggregateId, string name) | ||
:base(aggregateId) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
|
||
public class CreatePersonCommandHandler : CommandHandler<PersonAggregate, PersonId, CreatePersonCommand> | ||
{ | ||
public override Task ExecuteAsync(PersonAggregate aggregate, CreatePersonCommand command, CancellationToken cancellationToken) | ||
{ | ||
aggregate.Create(command.Name); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.