-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-projection Feature/#89 add toggle states projection
- Loading branch information
Showing
10 changed files
with
311 additions
and
49 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
105 changes: 105 additions & 0 deletions
105
....Core.Tests/ReadModel/Projections/ToggleState/ProjectEvents/EnvironmentStateAddedSpecs.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,105 @@ | ||
namespace Evelyn.Core.Tests.ReadModel.Projections.ToggleState.ProjectEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using Evelyn.Core.WriteModel.Project.Events; | ||
using FluentAssertions; | ||
using TestStack.BDDfy; | ||
using Xunit; | ||
using Projections = Evelyn.Core.ReadModel.Projections; | ||
|
||
public class EnvironmentStateAddedSpecs : ProjectionBuilderHarness<EnvironmentStateAdded> | ||
{ | ||
[Fact] | ||
public void ProjectionDoesNotExist() | ||
{ | ||
this.Given(_ => GivenThereAreNoProjections()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateAddedEvent()) | ||
.Then(_ => ThenAProjectionIsCreatedWithTheNewEnvironmentState()) | ||
.Then(_ => ThenTheProjectionAuditIsSet()) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void Nominal() | ||
{ | ||
this.Given(_ => GivenTheProjectionExists()) | ||
.And(_ => GivenTheProjectAlreadyHasAToggleState()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateAddedEvent()) | ||
.Then(_ => ThenTheNewToggleStateIsAdded()) | ||
.And(_ => ThenTheProjectionAuditIsSet()) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void ProjectionAlreadyBuilt() | ||
{ | ||
this.Given(_ => GivenTheProjectionExists()) | ||
.And(_ => GivenTheProjectAlreadyHasAToggleState()) | ||
.And(_ => GivenTheProjectionStreamVersionIsTheSameAsTheNextEvent()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateAddedEvent()) | ||
.Then(_ => ThenTheStoredProjectionIsUnchanged()) | ||
.BDDfy(); | ||
} | ||
|
||
protected override async Task HandleEventImplementation() | ||
{ | ||
await ProjectionBuilder.Handle(StreamPosition, Event, StoppingToken); | ||
} | ||
|
||
private void GivenTheProjectAlreadyHasAToggleState() | ||
{ | ||
OriginalProjection.ToggleState.AddEnvironmentState( | ||
DataFixture.Create<Projections.EventAudit>(), | ||
DataFixture.Create<string>(), | ||
DataFixture.Create<string>()); | ||
} | ||
|
||
private void GivenTheProjectionStreamVersionIsTheSameAsTheNextEvent() | ||
{ | ||
StreamPosition = OriginalProjection.Audit.StreamPosition; | ||
} | ||
|
||
private async Task WhenWeHandleAnEnvironmentStateAddedEvent() | ||
{ | ||
Event = new EnvironmentStateAdded( | ||
DataFixture.Create<string>(), | ||
ProjectId, | ||
EnvironmentKey, | ||
DataFixture.Create<DateTimeOffset>(), | ||
DataFixture.CreateMany<KeyValuePair<string, string>>(1)); | ||
|
||
await WhenTheEventIsHandled(); | ||
} | ||
|
||
private void ThenAProjectionIsCreatedWithTheNewEnvironmentState() | ||
{ | ||
var environmentStates = UpdatedProjection.ToggleState.EnvironmentStates.ToList(); | ||
environmentStates.Count.Should().Be(1); | ||
|
||
environmentStates.Should().Contain(ts => | ||
ts.Key == Event.EnvironmentKey && | ||
ts.Value == Event.ToggleStates.ToList()[0].Value); | ||
} | ||
|
||
private void ThenTheNewToggleStateIsAdded() | ||
{ | ||
var environmentStates = UpdatedProjection.ToggleState.EnvironmentStates.ToList(); | ||
environmentStates.Count.Should().Be(OriginalProjection.ToggleState.EnvironmentStates.Count() + 1); | ||
|
||
foreach (var environmentState in OriginalProjection.ToggleState.EnvironmentStates) | ||
{ | ||
environmentStates.Should().Contain(ts => | ||
ts.Key == environmentState.Key && | ||
ts.Value == environmentState.Value); | ||
} | ||
|
||
environmentStates.Should().Contain(ts => | ||
ts.Key == Event.EnvironmentKey && | ||
ts.Value == Event.ToggleStates.ToList()[0].Value); | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...ore.Tests/ReadModel/Projections/ToggleState/ProjectEvents/EnvironmentStateDeletedSpecs.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,87 @@ | ||
namespace Evelyn.Core.Tests.ReadModel.Projections.ToggleState.ProjectEvents | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using Evelyn.Core.ReadModel.Projections.ToggleState; | ||
using Evelyn.Core.WriteModel.Project.Events; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using TestStack.BDDfy; | ||
using Xunit; | ||
using Projections = Evelyn.Core.ReadModel.Projections; | ||
|
||
public class EnvironmentStateDeletedSpecs : ProjectionBuilderHarness<EnvironmentStateDeleted> | ||
{ | ||
[Fact] | ||
public void ProjectionDoesNotExist() | ||
{ | ||
this.Given(_ => GivenThereAreNoProjections()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateDeletedEvent()) | ||
.Then(_ => ThenAnExceptionIsThrown()) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void MultipleToggleStatesExist() | ||
{ | ||
this.Given(_ => GivenTheProjectionExists()) | ||
.And(_ => GivenTheProjectionHasStateForOurEnvironment()) | ||
.And(_ => GivenTheProjectionHasStateForAnotherEnvironment()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateDeletedEvent()) | ||
.Then(_ => ThenTheEnvironmentStateIsRemoved()) | ||
.And(_ => ThenTheProjectionAuditIsSet()) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void LastToggleStateIsDeleted() | ||
{ | ||
this.Given(_ => GivenTheProjectionExists()) | ||
.And(_ => GivenTheProjectionHasStateForOurEnvironment()) | ||
.When(_ => WhenWeHandleAnEnvironmentStateDeletedEvent()) | ||
.Then(_ => ThenTheProjectionIsDeleted()) | ||
.BDDfy(); | ||
} | ||
|
||
protected override async Task HandleEventImplementation() | ||
{ | ||
await ProjectionBuilder.Handle(StreamPosition, Event, StoppingToken); | ||
} | ||
|
||
private async Task WhenWeHandleAnEnvironmentStateDeletedEvent() | ||
{ | ||
Event = new EnvironmentStateDeleted( | ||
DataFixture.Create<string>(), | ||
ProjectId, | ||
EnvironmentKey, | ||
DataFixture.Create<DateTimeOffset>(), | ||
new List<string>() { ToggleKey }); | ||
|
||
await WhenTheEventIsHandled(); | ||
} | ||
|
||
private void ThenTheProjectionIsDeleted() | ||
{ | ||
ProjectionStore.Received().Delete(Projection.StoreKey(ProjectId, ToggleKey)); | ||
} | ||
|
||
private void ThenTheEnvironmentStateIsRemoved() | ||
{ | ||
var environmentStates = UpdatedProjection.ToggleState.EnvironmentStates.ToList(); | ||
environmentStates.Count.Should().Be(OriginalProjection.ToggleState.EnvironmentStates.Count() - 1); | ||
|
||
foreach (var environmentState in OriginalProjection.ToggleState.EnvironmentStates) | ||
{ | ||
if (environmentState.Key != Event.EnvironmentKey) | ||
{ | ||
environmentStates.Should().Contain(ts => | ||
ts.Key == environmentState.Key && | ||
ts.Value == environmentState.Value); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.