Skip to content

Commit

Permalink
Merge pull request #144 from binarymash/feature/#143-Refactor-project…
Browse files Browse the repository at this point in the history
…ion-audit

Feature/#143 refactor projection audit
  • Loading branch information
binarymash committed Nov 30, 2018
2 parents fd28cb0 + 4882a25 commit d00b5ae
Show file tree
Hide file tree
Showing 45 changed files with 2,263 additions and 540 deletions.
4 changes: 2 additions & 2 deletions src/Evelyn.Client.Rest/EnvironmentStateRestProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EnvironmentState Invoke(Guid projectId, string environmentKey)
try
{
var dto = _client
.ApiStatesByProjectIdByEnvironmentNameGetAsync(projectId, environmentKey)
.ApiStatesAsync(projectId, environmentKey)
.GetAwaiter().GetResult();

var toggleStates = new List<ToggleState>();
Expand All @@ -37,7 +37,7 @@ public EnvironmentState Invoke(Guid projectId, string environmentKey)
}
}

return new EnvironmentState(dto.Version.Value, toggleStates);
return new EnvironmentState(dto.Audit.Version.Value, toggleStates);
}
catch (SwaggerException ex)
{
Expand Down
2,039 changes: 1,816 additions & 223 deletions src/Evelyn.Client.Rest/Generated/OpenApiClasses.cs

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions src/Evelyn.Client.Rest/Generated/RestApi.nswag
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"runtime": "NetCore21",
"defaultVariables": null,
"swaggerGenerator": {
"fromSwagger": {
"url": "http://localhost:2316/swagger/v0.1/swagger.json",
"output": null
}
},
"codeGenerators": {
"swaggerToCSharpClient": {
"clientBaseClass": null,
"configurationClass": null,
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateDtoTypes": true,
"injectHttpClient": false,
"disposeHttpClient": true,
"protectedMethods": [],
"generateExceptionClasses": true,
"exceptionClass": "SwaggerException",
"wrapDtoExceptions": true,
"useHttpClientCreationMethod": false,
"httpClientType": "System.Net.Http.HttpClient",
"useHttpRequestMessageCreationMethod": false,
"useBaseUrl": true,
"generateBaseUrlProperty": true,
"generateSyncMethods": false,
"exposeJsonSerializerSettings": false,
"clientClassAccessModifier": "public",
"typeAccessModifier": "public",
"generateContractsOutput": false,
"contractsNamespace": null,
"contractsOutputFilePath": null,
"parameterDateTimeFormat": "s",
"generateUpdateJsonSerializerSettingsMethod": true,
"serializeTypeInformation": false,
"queryNullValue": "",
"className": "{controller}Client",
"operationGenerationMode": "SingleClientFromPathSegments",
"additionalNamespaceUsages": [],
"additionalContractNamespaceUsages": [],
"generateOptionalParameters": false,
"generateJsonMethods": true,
"enforceFlagEnums": false,
"parameterArrayType": "System.Collections.Generic.IEnumerable",
"parameterDictionaryType": "System.Collections.Generic.IDictionary",
"responseArrayType": "System.Collections.Generic.ICollection",
"responseDictionaryType": "System.Collections.Generic.IDictionary",
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"namespace": "Evelyn.Client.Rest.Generated",
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTimeOffset",
"jsonConverters": null,
"dateTimeType": "System.DateTimeOffset",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.ICollection",
"arrayInstanceType": "System.Collections.ObjectModel.Collection",
"dictionaryType": "System.Collections.Generic.IDictionary",
"dictionaryInstanceType": "System.Collections.Generic.Dictionary",
"arrayBaseType": "System.Collections.ObjectModel.Collection",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Poco",
"generateDefaultValues": true,
"generateDataAnnotations": true,
"excludedTypeNames": [],
"handleReferences": false,
"generateImmutableArrayProperties": false,
"generateImmutableDictionaryProperties": false,
"jsonSerializerSettingsTransformationMethod": null,
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": null
}
}
}
4 changes: 2 additions & 2 deletions src/Evelyn.Client/Domain/EnvironmentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public class EnvironmentState
{
private readonly List<ToggleState> _toggleStates;

public EnvironmentState(int version, IEnumerable<ToggleState> toggleStates)
public EnvironmentState(long version, IEnumerable<ToggleState> toggleStates)
{
_toggleStates = toggleStates.ToList();
Version = version;
}

public int Version { get; private set; }
public long Version { get; private set; }

public IEnumerable<ToggleState> ToggleStates => _toggleStates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Evelyn.Core.ReadModel.EventStream.Handlers;
using Evelyn.Core.ReadModel.Projections;
using Evelyn.Core.ReadModel.Projections.EventHandlerState;
using Evelyn.Core.ReadModel.Projections.Shared;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
Expand Down Expand Up @@ -202,12 +203,14 @@ private void GivenThereIsNoEventHandlerState()

private void GivenTheEventHasNotYetBeenHandled()
{
_originalEventHandlerState = new EventHandlerStateDto(
_eventEnvelope.StreamVersion - 1,
_originalEventHandlerState = EventHandlerStateDto.Create();

var eventAudit = EventAuditDto.Create(
_dataFixture.Create<DateTimeOffset>(),
_dataFixture.Create<string>(),
_dataFixture.Create<DateTimeOffset>(),
_dataFixture.Create<string>());
_eventEnvelope.StreamVersion - 1);

_originalEventHandlerState.Processed(eventAudit);

_eventHandlerStateStore
.Get(Arg.Any<string>())
Expand All @@ -216,12 +219,14 @@ private void GivenTheEventHasNotYetBeenHandled()

private void GivenTheEventHasAlreadyBeenHandled()
{
_originalEventHandlerState = new EventHandlerStateDto(
_eventEnvelope.StreamVersion + 1,
_originalEventHandlerState = EventHandlerStateDto.Create();

var eventAudit = EventAuditDto.Create(
_dataFixture.Create<DateTimeOffset>(),
_dataFixture.Create<string>(),
_dataFixture.Create<DateTimeOffset>(),
_dataFixture.Create<string>());
_eventEnvelope.StreamVersion + 1);

_originalEventHandlerState.Processed(eventAudit);

_eventHandlerStateStore
.Get(Arg.Any<string>())
Expand Down Expand Up @@ -273,13 +278,13 @@ private void ThenAnExceptionIsThrown()
private void ThenTheStateIsCreated()
{
_eventHandlerStateStore.Received().Create(EventHandlerStateDto.StoreKey(typeof(SomeStream)), _updatedEventHandlerState);
_updatedEventHandlerState.Version.Should().Be(_eventEnvelope.StreamVersion);
_updatedEventHandlerState.Audit.Version.Should().Be(_eventEnvelope.StreamVersion);
}

private void ThenTheStateIsUpdated()
{
_eventHandlerStateStore.Received().Update(EventHandlerStateDto.StoreKey(typeof(SomeStream)), _updatedEventHandlerState);
_updatedEventHandlerState.Version.Should().Be(_eventEnvelope.StreamVersion);
_updatedEventHandlerState.Audit.Version.Should().Be(_eventEnvelope.StreamVersion);
}

private void ThenTheStateIsNotUpdated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void Nominal()
this.Given(_ => GivenThereIsNoProjection())
.When(_ => WhenWeHandleAnAccountRegisteredEvent())
.Then(_ => ThenTheProjectionIsCreatedWithTheCorrectProperties())
.And(_ => ThenTheAuditIsCreated())
.BDDfy();
}

Expand All @@ -38,12 +39,7 @@ private void ThenTheProjectionIsCreatedWithTheCorrectProperties()
ThenTheProjectionIsCreated();

UpdatedProjection.AccountId.Should().Be(Event.Id);
UpdatedProjection.Created.Should().Be(Event.OccurredAt);
UpdatedProjection.CreatedBy.Should().Be(Event.UserId);
UpdatedProjection.LastModified.Should().Be(Event.OccurredAt);
UpdatedProjection.LastModifiedBy.Should().Be(Event.UserId);
UpdatedProjection.Projects.Should().BeEmpty();
UpdatedProjection.Version.Should().Be(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void Nominal()
.And(_ => GivenOurProjectIsNotOnTheProjection())
.And(_ => GivenAnotherProjectIsOnTheProjection())
.When(_ => WhenWeHandleAProjectCreatedEvent())
.Then(_ => ThenTheProjectHadBeenAddedToTheProjection())
.Then(_ => ThenOurProjectIsAdded())
.And(_ => ThenTheAuditIsUpdated())
.BDDfy();
}

Expand All @@ -47,15 +48,9 @@ private async Task WhenWeHandleAProjectCreatedEvent()
await WhenTheEventIsHandled();
}

private void ThenTheProjectHadBeenAddedToTheProjection()
private void ThenOurProjectIsAdded()
{
UpdatedProjection.AccountId.Should().Be(OriginalProjection.AccountId);
UpdatedProjection.Created.Should().Be(OriginalProjection.Created);
UpdatedProjection.CreatedBy.Should().Be(OriginalProjection.CreatedBy);

UpdatedProjection.LastModified.Should().Be(Event.OccurredAt);
UpdatedProjection.LastModifiedBy.Should().Be(Event.UserId);
UpdatedProjection.Version.Should().Be(Event.Version);

var projects = UpdatedProjection.Projects.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void Nominal()
.And(_ => GivenOurProjectIsOnTheProjection())
.And(_ => GivenAnotherProjectIsOnTheProjection())
.When(_ => WhenWeHandleTheProjectDeletedEvent())
.Then(_ => ThenTheProjectionHasBeenUpdated())
.Then(_ => ThenOurProjectIsRemoved())
.And(_ => ThenTheAuditIsUpdated())
.BDDfy();
}

Expand All @@ -46,15 +47,9 @@ private async Task WhenWeHandleTheProjectDeletedEvent()
await WhenTheEventIsHandled();
}

private void ThenTheProjectionHasBeenUpdated()
private void ThenOurProjectIsRemoved()
{
UpdatedProjection.AccountId.Should().Be(OriginalProjection.AccountId);
UpdatedProjection.Created.Should().Be(OriginalProjection.Created);
UpdatedProjection.CreatedBy.Should().Be(OriginalProjection.CreatedBy);

UpdatedProjection.LastModified.Should().Be(Event.OccurredAt);
UpdatedProjection.LastModifiedBy.Should().Be(Event.UserId);
UpdatedProjection.Version.Should().Be(Event.Version);

var projects = UpdatedProjection.Projects.ToList();
projects.Count.Should().Be(OriginalProjection.Projects.Count() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using AutoFixture;
using Core.ReadModel.Projections.AccountProjects;
using Evelyn.Core.ReadModel.Projections.Shared;
using Xunit;

public class AccountProjectsDtoSpecs : DtoHarness<AccountProjectsDto>
Expand All @@ -11,15 +12,12 @@ public class AccountProjectsDtoSpecs : DtoHarness<AccountProjectsDto>
public void Serialization()
{
var accountProjects = AccountProjectsDto.Create(
DataFixture.Create<Guid>(),
DataFixture.Create<DateTimeOffset>(),
DataFixture.Create<string>());
DataFixture.Create<EventAuditDto>(),
DataFixture.Create<Guid>());

accountProjects.AddProject(
DataFixture.Create<EventAuditDto>(),
DataFixture.Create<Guid>(),
DataFixture.Create<string>(),
DataFixture.Create<int>(),
DataFixture.Create<DateTimeOffset>(),
DataFixture.Create<string>());

AssertSerializationOf(accountProjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void Nominal()
.And(_ => GivenOurProjectIsOnTheProjection())
.And(_ => GivenAnotherProjectIsOnTheProjection())
.When(_ => WhenWeHandleAProjectCreatedEvent())
.Then(_ => ThenOurProjectNameHasBeenUpdated())
.Then(_ => ThenOurProjectNameIsUpdated())
.And(_ => ThenTheAuditIsUpdatedExcludingVersion())
.BDDfy();
}

Expand All @@ -47,18 +48,11 @@ private async Task WhenWeHandleAProjectCreatedEvent()
await WhenTheEventIsHandled();
}

private void ThenOurProjectNameHasBeenUpdated()
private void ThenOurProjectNameIsUpdated()
{
UpdatedProjection.AccountId.Should().Be(OriginalProjection.AccountId);
UpdatedProjection.Created.Should().Be(OriginalProjection.Created);
UpdatedProjection.CreatedBy.Should().Be(OriginalProjection.CreatedBy);

UpdatedProjection.LastModified.Should().Be(OriginalProjection.LastModified);
UpdatedProjection.LastModifiedBy.Should().Be(OriginalProjection.LastModifiedBy);
UpdatedProjection.Version.Should().Be(OriginalProjection.Version);

var projects = UpdatedProjection.Projects.ToList();

projects.Count.Should().Be(OriginalProjection.Projects.Count());

foreach (var originalProject in OriginalProjection.Projects.Where(p => p.Id != Event.Id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using AutoFixture;
using Evelyn.Core.ReadModel.Projections.AccountProjects;
using Evelyn.Core.ReadModel.Projections.Shared;
using Evelyn.Core.WriteModel;
using NSubstitute;

Expand Down Expand Up @@ -38,20 +39,16 @@ protected void GivenOurProjectIsOnTheProjection()
{
ProjectId = DataFixture.Create<Guid>();
OriginalProjection.AddProject(
DataFixture.Create<EventAuditDto>(),
ProjectId,
DataFixture.Create<string>(),
DataFixture.Create<int>(),
DataFixture.Create<DateTimeOffset>(),
DataFixture.Create<string>());
}

protected void GivenAnotherProjectIsOnTheProjection()
{
OriginalProjection.AddProject(
DataFixture.Create<EventAuditDto>(),
DataFixture.Create<Guid>(),
DataFixture.Create<string>(),
DataFixture.Create<int>(),
DataFixture.Create<DateTimeOffset>(),
DataFixture.Create<string>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void Nominal()
this.Given(_ => GivenThereIsNoProjection())
.When(_ => WhenWeHandleAProjectCreatedEvent())
.Then(_ => ThenTheProjectionIsCreated())
.And(_ => ThenTheAuditIsCreated())
.BDDfy();
}

Expand All @@ -36,12 +37,6 @@ private async Task WhenWeHandleAProjectCreatedEvent()
private void ThenTheProjectionIsCreated()
{
UpdatedProjection.ProjectId.Should().Be(Event.Id);
UpdatedProjection.Created.Should().Be(Event.OccurredAt);
UpdatedProjection.CreatedBy.Should().Be(Event.UserId);

UpdatedProjection.LastModified.Should().Be(Event.OccurredAt);
UpdatedProjection.LastModifiedBy.Should().Be(Event.UserId);
UpdatedProjection.Version.Should().Be(0);

UpdatedProjection.Key.Should().Be(Event.Key);
UpdatedProjection.Name.Should().Be(Event.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void Nominal()
this.Given(_ => GivenThereIsNoProjection())
.When(_ => WhenWeHandleAnEnvironmentStateAddedEvent())
.Then(_ => ThenTheProjectionIsCreated())
.And(_ => ThenTheAuditIsCreated())
.BDDfy();
}

Expand All @@ -39,11 +40,6 @@ private void ThenTheProjectionIsCreated()
{
ProjectionStore.Received().Create(EnvironmentStateDto.StoreKey(ProjectId, EnvironmentKey), UpdatedProjection);

UpdatedProjection.Created.Should().Be(Event.OccurredAt);
UpdatedProjection.CreatedBy.Should().Be(Event.UserId);
UpdatedProjection.LastModified.Should().Be(Event.OccurredAt);
UpdatedProjection.LastModifiedBy.Should().Be(Event.UserId);
UpdatedProjection.Version.Should().Be(Event.Version);
UpdatedProjection.ToggleStates.Should().BeEquivalentTo(Event.ToggleStates);
}
}
Expand Down

0 comments on commit d00b5ae

Please sign in to comment.