From b89df84bb5e2706be9155c900b1ec8bd161a42fb Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sun, 13 May 2018 19:39:28 +0200 Subject: [PATCH 1/5] Version is now 0.59 --- RELEASE_NOTES.md | 6 +++++- appveyor.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a549a0785..e79b1bbea 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,8 @@ -### New in 0.58 (not released yet) +### New in 0.59 (not released yet) + +* _Nothing yet_ + +### New in 0.58.3377 (released 2018-05-15) * Minor fix: Corrected log in `CommandBus` regarding events emitted due to command diff --git a/appveyor.yml b/appveyor.yml index 361f5f9a5..897cc73e4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ init: - git config --global core.autocrlf input -version: 0.58.{build} +version: 0.59.{build} skip_tags: true From e36c8eae9c2275dff5a492a8f1eaaf4ef8632d9b Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 14 May 2018 21:06:09 +0200 Subject: [PATCH 2/5] Fix saga commands aren't published if no events are emitted --- .../Aggregates/Sagas/ThingySaga.cs | 2 +- Source/EventFlow.TestHelpers/Test.cs | 4 +- .../AggregateSagas/SagaAggregateStoreTests.cs | 63 ++++++++++++++++--- .../Sagas/AggregateSagas/AggregateSaga.cs | 10 +-- .../AggregateSagas/SagaAggregateStore.cs | 4 +- 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/Source/EventFlow.TestHelpers/Aggregates/Sagas/ThingySaga.cs b/Source/EventFlow.TestHelpers/Aggregates/Sagas/ThingySaga.cs index a354da645..8c80a2f24 100644 --- a/Source/EventFlow.TestHelpers/Aggregates/Sagas/ThingySaga.cs +++ b/Source/EventFlow.TestHelpers/Aggregates/Sagas/ThingySaga.cs @@ -110,4 +110,4 @@ public void Apply(ThingySagaCompletedEvent aggregateEvent) Complete(); } } -} \ No newline at end of file +} diff --git a/Source/EventFlow.TestHelpers/Test.cs b/Source/EventFlow.TestHelpers/Test.cs index bd58eeba6..b1490ff02 100644 --- a/Source/EventFlow.TestHelpers/Test.cs +++ b/Source/EventFlow.TestHelpers/Test.cs @@ -79,10 +79,10 @@ protected T Inject(T instance) return instance; } - protected Mock InjectMock() + protected Mock InjectMock(params object[] args) where T : class { - var mock = new Mock(); + var mock = new Mock(args); Fixture.Inject(mock.Object); return mock; } diff --git a/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/SagaAggregateStoreTests.cs b/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/SagaAggregateStoreTests.cs index f3f8a7ba5..5baafb70f 100644 --- a/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/SagaAggregateStoreTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/SagaAggregateStoreTests.cs @@ -23,14 +23,15 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using EventFlow.Aggregates; using EventFlow.Core; using EventFlow.Core.Caching; -using EventFlow.Sagas; using EventFlow.Sagas.AggregateSagas; using EventFlow.TestHelpers; +using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Sagas; using Moq; using NUnit.Framework; @@ -40,9 +41,15 @@ namespace EventFlow.Tests.UnitTests.Sagas.AggregateSagas [Category(Categories.Unit)] public class SagaAggregateStoreTests : TestsFor { + private ThingySagaId _thingySagaId; + private Mock _thingySaga; + [SetUp] public void SetUp() { + _thingySagaId = A(); + _thingySaga = InjectMock(_thingySagaId); + Inject(A()); } @@ -50,16 +57,9 @@ public void SetUp() public async Task AggregateStore_UpdateAsync_IsInvoked() { // Arrange - var aggregateStoreMock = InjectMock(); var thingySagaId = A(); var sourceId = A(); - aggregateStoreMock - .Setup(s => s.UpdateAsync( - thingySagaId, - sourceId, - It.IsAny>(), - It.IsAny())) - .ReturnsAsync(new List()); + var aggregateStoreMock = ArrangeAggregateStoreMock(thingySagaId, sourceId, A()); // Act await Sut.UpdateAsync( @@ -78,5 +78,50 @@ await Sut.UpdateAsync( It.IsAny()), Times.Once); } + + [TestCase(true)] + [TestCase(false)] + public async Task CommandBus_PublishAsync_IsInvoked(bool eventsAreEmitted) + { + // Arrange + var thingySagaId = A(); + var sourceId = A(); + ArrangeAggregateStoreMock(thingySagaId, sourceId, eventsAreEmitted); + + // Act + await Sut.UpdateAsync( + thingySagaId, + typeof(ThingySaga), + sourceId, + (s, c) => Task.FromResult(0), + CancellationToken.None); + + // Assert + _thingySaga.Verify( + s => s.PublishAsync(It.IsAny(), It.IsAny()), + Times.AtLeastOnce); + } + + private Mock ArrangeAggregateStoreMock( + ThingySagaId thingySagaId, + ISourceId sourceId, + bool returnsDomainEvents) + { + var aggregateStoreMock = InjectMock(); + var domainEvents = ManyDomainEvents(returnsDomainEvents ? 3 : 0) + .Cast() + .ToList(); + + aggregateStoreMock + .Setup(s => s.UpdateAsync( + thingySagaId, + sourceId, + It.IsAny>(), + It.IsAny())) + .Callback, CancellationToken>( + (id, sid, f, c) => f(_thingySaga.Object, CancellationToken.None).Wait(c)) + .ReturnsAsync(domainEvents); + return aggregateStoreMock; + } } } \ No newline at end of file diff --git a/Source/EventFlow/Sagas/AggregateSagas/AggregateSaga.cs b/Source/EventFlow/Sagas/AggregateSagas/AggregateSaga.cs index 0ccf3b086..97b10ec50 100644 --- a/Source/EventFlow/Sagas/AggregateSagas/AggregateSaga.cs +++ b/Source/EventFlow/Sagas/AggregateSagas/AggregateSaga.cs @@ -64,13 +64,15 @@ protected void Publish UpdateAsync( cancellationToken) .ConfigureAwait(false); - var domainEvents = await storeAggregateSagaAsync( + await storeAggregateSagaAsync( this, sagaId, sourceId, @@ -77,7 +77,7 @@ public override async Task UpdateAsync( cancellationToken) .ConfigureAwait(false); - if (!domainEvents.Any()) + if (saga is null) { return null; } From ad43abc49f11e4f5b85370891561fc2ea944b5ea Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 14 May 2018 21:07:30 +0200 Subject: [PATCH 3/5] Updated release notes --- RELEASE_NOTES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e79b1bbea..e125f2f3e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,7 @@ ### New in 0.59 (not released yet) -* _Nothing yet_ +* Fix: Commands are now correctly published when no events are emitted from a saga + after handling a domain event ### New in 0.58.3377 (released 2018-05-15) From 08aff4ec90ee02aad77712dd865d07559cf3ebe2 Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 23 May 2018 17:16:28 +0200 Subject: [PATCH 4/5] Change MSSQL Snapshot PK name --- .../Scripts/0001 - Create EventFlowSnapshots.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/EventFlow.MsSql/SnapshotStores/Scripts/0001 - Create EventFlowSnapshots.sql b/Source/EventFlow.MsSql/SnapshotStores/Scripts/0001 - Create EventFlowSnapshots.sql index 038f973eb..fa2fc9136 100644 --- a/Source/EventFlow.MsSql/SnapshotStores/Scripts/0001 - Create EventFlowSnapshots.sql +++ b/Source/EventFlow.MsSql/SnapshotStores/Scripts/0001 - Create EventFlowSnapshots.sql @@ -7,7 +7,7 @@ BEGIN [AggregateSequenceNumber] [int] NOT NULL, [Data] [nvarchar](MAX) NOT NULL, [Metadata] [nvarchar](MAX) NOT NULL, - CONSTRAINT [PK_EventFlow] PRIMARY KEY CLUSTERED + CONSTRAINT [PK_EventFlowSnapshots] PRIMARY KEY CLUSTERED ( [Id] ASC ) @@ -19,4 +19,4 @@ BEGIN [AggregateId] ASC, [AggregateSequenceNumber] ASC ) -END \ No newline at end of file +END From 1839699c5d33f3041337958246333666f62c7f2c Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 23 May 2018 17:19:50 +0200 Subject: [PATCH 5/5] Update release notes --- RELEASE_NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e125f2f3e..23ef97e2b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,8 @@ * Fix: Commands are now correctly published when no events are emitted from a saga after handling a domain event +* Minor fix: Updated name of Primary Key for MSSQL Snapshot Store to be different + from MSSQL Event Store, so both can be used in the same database without conflicts ### New in 0.58.3377 (released 2018-05-15)