diff --git a/build.cake b/build.cake index 561b308..dee5341 100644 --- a/build.cake +++ b/build.cake @@ -28,7 +28,7 @@ var netFrameworkUnitTestAssemblies = new [] @"./src/Evelyn.Storage.EventStore.Tests/bin/"+compileConfig+"/net461/Evelyn.Storage.EventStore.Tests.dll", }; var openCoverSettings = new OpenCoverSettings(); -var minCodeCoverage = 89d; +var minCodeCoverage = 90d; var coverallsRepoToken = "coveralls-repo-token-evelyn"; // integration testing diff --git a/src/Evelyn.Core.Tests/ReadModel/EnvironmentDetails/ProjectionBuilderSpecs.cs b/src/Evelyn.Core.Tests/ReadModel/EnvironmentDetails/ProjectionBuilderSpecs.cs index b177adc..71bcfcf 100644 --- a/src/Evelyn.Core.Tests/ReadModel/EnvironmentDetails/ProjectionBuilderSpecs.cs +++ b/src/Evelyn.Core.Tests/ReadModel/EnvironmentDetails/ProjectionBuilderSpecs.cs @@ -60,7 +60,9 @@ public void EnvironmentExists() .And(_ => GivenTheProjectIsInTheRepository()) .When(_ => WhenWeInvokeTheProjectionBuilder()) .Then(_ => ThenTheCreatedDateIsSet()) + .And(_ => ThenTheCreatedByIsSet()) .And(_ => ThenTheLastModifiedDateIsSet()) + .And(_ => ThenTheLastModifiedByIsSet()) .And(_ => ThenTheProjectIdIsSet()) .And(_ => ThenTheEnvironmentKeyIsSet()) .BDDfy(); @@ -136,11 +138,21 @@ private void ThenTheCreatedDateIsSet() Dto.Created.Should().Be(_expectedEnvironment.Created); } + private void ThenTheCreatedByIsSet() + { + Dto.CreatedBy.Should().Be(_expectedEnvironment.CreatedBy); + } + private void ThenTheLastModifiedDateIsSet() { Dto.LastModified.Should().Be(_expectedEnvironment.LastModified); } + private void ThenTheLastModifiedByIsSet() + { + Dto.LastModifiedBy.Should().Be(_expectedEnvironment.LastModifiedBy); + } + private void ThenTheProjectIdIsSet() { Dto.ProjectId.Should().Be(_projectId); diff --git a/src/Evelyn.Core.Tests/ReadModel/EnvironmentState/ProjectionBuilderSpecs.cs b/src/Evelyn.Core.Tests/ReadModel/EnvironmentState/ProjectionBuilderSpecs.cs index 89171e9..7dd1df9 100644 --- a/src/Evelyn.Core.Tests/ReadModel/EnvironmentState/ProjectionBuilderSpecs.cs +++ b/src/Evelyn.Core.Tests/ReadModel/EnvironmentState/ProjectionBuilderSpecs.cs @@ -27,9 +27,7 @@ public class ProjectionBuilderSpecs : ProjectionBuilderSpecs WhenWeInvokeTheProjectionBuilderForTheEnvironmentState()) .Then(_ => ThenTheEnvironmentVersionIsSet()) .And(_ => ThenTheCreatedDateIsSet()) + .And(_ => ThenTheCreatedByIsSet()) .And(_ => ThenTheLastModifiedDateIsSet()) + .And(_ => ThenTheLastModifiedByIsSet()) .And(_ => ThenAllTheToggleStatesAreSet()) .BDDfy(); } @@ -104,9 +104,7 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles() { _projectId = DataFixture.Create(); _environmentKey = DataFixture.Create(); - _toggle1Key = DataFixture.Create(); - _toggle2Key = DataFixture.Create(); - _toggle3Key = DataFixture.Create(); + _toggleKey = DataFixture.Create(); _projectEvents.Add(DataFixture.Build() .With(ev => ev.Version, 0) @@ -128,14 +126,14 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles() _projectEvents.Add(DataFixture.Build() .With(ev => ev.Version, 3) .With(ev => ev.Id, _projectId) - .With(ev => ev.Key, _toggle1Key) + .With(ev => ev.Key, _toggleKey) .Create()); _projectEvents.Add(new ToggleStateAdded( DataFixture.Create(), _projectId, _environmentKey, - _toggle1Key, + _toggleKey, DataFixture.Create().ToString(), DateTimeOffset.UtcNow) { @@ -145,14 +143,14 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles() _projectEvents.Add(DataFixture.Build() .With(ev => ev.Version, 5) .With(ev => ev.Id, _projectId) - .With(ev => ev.Key, _toggle1Key) + .With(ev => ev.Key, _toggleKey) .Create()); _projectEvents.Add(new ToggleStateAdded( DataFixture.Create(), _projectId, _environmentKey, - _toggle1Key, + _toggleKey, DataFixture.Create().ToString(), DateTimeOffset.UtcNow) { @@ -197,11 +195,21 @@ private void ThenTheCreatedDateIsSet() Dto.Created.Should().Be(_expectedEnvironmentState.Created); } + private void ThenTheCreatedByIsSet() + { + Dto.CreatedBy.Should().Be(_expectedEnvironmentState.CreatedBy); + } + private void ThenTheLastModifiedDateIsSet() { Dto.LastModified.Should().Be(_expectedEnvironmentState.LastModified); } + private void ThenTheLastModifiedByIsSet() + { + Dto.LastModifiedBy.Should().Be(_expectedEnvironmentState.LastModifiedBy); + } + private void ThenAllTheToggleStatesAreSet() { Dto.ToggleStates.Count().Should().Be(_expectedEnvironmentState.ToggleStates.Count()); diff --git a/src/Evelyn.Core.Tests/ReadModel/ProjectDetails/ProjectionBuilderSpecs.cs b/src/Evelyn.Core.Tests/ReadModel/ProjectDetails/ProjectionBuilderSpecs.cs index 3068e9b..b5e2357 100644 --- a/src/Evelyn.Core.Tests/ReadModel/ProjectDetails/ProjectionBuilderSpecs.cs +++ b/src/Evelyn.Core.Tests/ReadModel/ProjectDetails/ProjectionBuilderSpecs.cs @@ -46,7 +46,9 @@ public void EnvironmentExists() .And(_ => GivenTheProjectIsInTheRepository()) .When(_ => WhenWeInvokeTheProjectionBuilder()) .Then(_ => ThenTheCreatedDateIsSet()) + .And(_ => ThenTheCreatedByIsSet()) .And(_ => ThenTheLastModifiedDateIsSet()) + .And(_ => ThenTheLastModifiedByIsSet()) .And(_ => ThenTheVersionIsSet()) .And(_ => ThenTheIdIsSet()) .And(_ => ThenTheNameIsSet()) @@ -131,11 +133,21 @@ private void ThenTheCreatedDateIsSet() Dto.Created.Should().Be(_project.Created); } + private void ThenTheCreatedByIsSet() + { + Dto.CreatedBy.Should().Be(_project.CreatedBy); + } + private void ThenTheLastModifiedDateIsSet() { Dto.LastModified.Should().Be(_project.LastModified); } + private void ThenTheLastModifiedByIsSet() + { + Dto.LastModifiedBy.Should().Be(_project.LastModifiedBy); + } + private void ThenTheVersionIsSet() { Dto.Version.Should().Be(_project.Version); diff --git a/src/Evelyn.Core.Tests/ReadModel/ToggleDetails/ProjectionBuilderSpecs.cs b/src/Evelyn.Core.Tests/ReadModel/ToggleDetails/ProjectionBuilderSpecs.cs index 298bd6d..a93969d 100644 --- a/src/Evelyn.Core.Tests/ReadModel/ToggleDetails/ProjectionBuilderSpecs.cs +++ b/src/Evelyn.Core.Tests/ReadModel/ToggleDetails/ProjectionBuilderSpecs.cs @@ -59,7 +59,9 @@ public void ToggleExists() .And(_ => GivenTheProjectIsInTheRepository()) .When(_ => WhenWeInvokeTheProjectionBuilder()) .Then(_ => ThenTheCreatedDateIsSet()) + .And(_ => ThenTheCreatedByIsSet()) .And(_ => ThenTheLastModifiedDateIsSet()) + .And(_ => ThenTheLastModifiedByIsSet()) .And(_ => ThenTheProjectIdIsSet()) .And(_ => ThenTheToggleKeyIsSet()) .And(_ => ThenTheToggleNameIsSet()) @@ -136,11 +138,21 @@ private void ThenTheCreatedDateIsSet() Dto.Created.Should().Be(_expectedToggle.Created); } + private void ThenTheCreatedByIsSet() + { + Dto.CreatedBy.Should().Be(_expectedToggle.CreatedBy); + } + private void ThenTheLastModifiedDateIsSet() { Dto.LastModified.Should().Be(_expectedToggle.LastModified); } + private void ThenTheLastModifiedByIsSet() + { + Dto.LastModifiedBy.Should().Be(_expectedToggle.LastModifiedBy); + } + private void ThenTheProjectIdIsSet() { Dto.ProjectId.Should().Be(_projectId); diff --git a/src/Evelyn.Core/ReadModel/EnvironmentDetails/EnvironmentDetailsDto.cs b/src/Evelyn.Core/ReadModel/EnvironmentDetails/EnvironmentDetailsDto.cs index a019652..ffa612b 100644 --- a/src/Evelyn.Core/ReadModel/EnvironmentDetails/EnvironmentDetailsDto.cs +++ b/src/Evelyn.Core/ReadModel/EnvironmentDetails/EnvironmentDetailsDto.cs @@ -4,8 +4,8 @@ public class EnvironmentDetailsDto : DtoRoot { - public EnvironmentDetailsDto(Guid projectId, string key, DateTimeOffset created, DateTimeOffset lastModified) - : base(created, string.Empty, lastModified, string.Empty) + public EnvironmentDetailsDto(Guid projectId, string key, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy) + : base(created, createdBy, lastModified, lastModifiedBy) { Key = key; ProjectId = projectId; diff --git a/src/Evelyn.Core/ReadModel/EnvironmentDetails/ProjectionBuilder.cs b/src/Evelyn.Core/ReadModel/EnvironmentDetails/ProjectionBuilder.cs index 9e0e783..62c5d50 100644 --- a/src/Evelyn.Core/ReadModel/EnvironmentDetails/ProjectionBuilder.cs +++ b/src/Evelyn.Core/ReadModel/EnvironmentDetails/ProjectionBuilder.cs @@ -21,7 +21,7 @@ public ProjectionBuilder(IRepository repository) { var project = await _repository.Get(request.ProjectId, token); var environment = project.Environments.First(e => e.Key == request.EnvironmentKey); - var dto = new EnvironmentDetailsDto(project.Id, environment.Key, environment.Created, environment.LastModified); + var dto = new EnvironmentDetailsDto(project.Id, environment.Key, environment.Created, environment.CreatedBy, environment.LastModified, environment.LastModifiedBy); return dto; } diff --git a/src/Evelyn.Core/ReadModel/EnvironmentState/EnvironmentStateDto.cs b/src/Evelyn.Core/ReadModel/EnvironmentState/EnvironmentStateDto.cs index 7b8440b..6d7e3d9 100644 --- a/src/Evelyn.Core/ReadModel/EnvironmentState/EnvironmentStateDto.cs +++ b/src/Evelyn.Core/ReadModel/EnvironmentState/EnvironmentStateDto.cs @@ -8,8 +8,8 @@ public class EnvironmentStateDto : DtoRoot { private readonly List _toggleStates; - public EnvironmentStateDto(int version, DateTimeOffset created, DateTimeOffset lastModified, IEnumerable toggleStates) - : base(created, string.Empty, lastModified, string.Empty) + public EnvironmentStateDto(int version, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy, IEnumerable toggleStates) + : base(created, createdBy, lastModified, lastModifiedBy) { Version = version; _toggleStates = toggleStates.ToList(); diff --git a/src/Evelyn.Core/ReadModel/EnvironmentState/ProjectionBuilder.cs b/src/Evelyn.Core/ReadModel/EnvironmentState/ProjectionBuilder.cs index bbd4bc8..b58b464 100644 --- a/src/Evelyn.Core/ReadModel/EnvironmentState/ProjectionBuilder.cs +++ b/src/Evelyn.Core/ReadModel/EnvironmentState/ProjectionBuilder.cs @@ -22,7 +22,7 @@ public ProjectionBuilder(IRepository repository) var project = await _repository.Get(request.ProjectId, token); var environmentState = project.EnvironmentStates.First(es => es.EnvironmentKey == request.EnvironmentKey); var toggleStates = environmentState.ToggleStates.Select(ts => new ToggleStateDto(ts.Version, ts.Key, ts.Value)); - var environmentStateDto = new EnvironmentStateDto(environmentState.Version, environmentState.Created, environmentState.LastModified, toggleStates); + var environmentStateDto = new EnvironmentStateDto(environmentState.Version, environmentState.Created, environmentState.CreatedBy, environmentState.LastModified, environmentState.LastModifiedBy, toggleStates); return environmentStateDto; } diff --git a/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectDetailsDto.cs b/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectDetailsDto.cs index 319d484..95d3e99 100644 --- a/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectDetailsDto.cs +++ b/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectDetailsDto.cs @@ -9,8 +9,8 @@ public class ProjectDetailsDto : DtoRoot private readonly IList _environments; private readonly IList _toggles; - public ProjectDetailsDto(Guid id, string name, IEnumerable environments, IEnumerable toggles, int version, DateTimeOffset created, DateTimeOffset lastModified) - : base(created, string.Empty, lastModified, string.Empty) + public ProjectDetailsDto(Guid id, string name, IEnumerable environments, IEnumerable toggles, int version, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy) + : base(created, createdBy, lastModified, lastModifiedBy) { Id = id; Name = name; diff --git a/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectionBuilder.cs b/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectionBuilder.cs index 062b5ba..036971e 100644 --- a/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectionBuilder.cs +++ b/src/Evelyn.Core/ReadModel/ProjectDetails/ProjectionBuilder.cs @@ -22,7 +22,7 @@ public ProjectionBuilder(IRepository repository) var project = await _repository.Get(request.ProjectId, token).ConfigureAwait(false); var environments = project.Environments.Select(e => new EnvironmentListDto(e.Key)); var toggles = project.Toggles.Select(t => new ToggleListDto(t.Key, t.Name)); - var dto = new ProjectDetailsDto(project.Id, project.Name, environments, toggles, project.Version, project.Created, project.LastModified); + var dto = new ProjectDetailsDto(project.Id, project.Name, environments, toggles, project.Version, project.Created, project.CreatedBy, project.LastModified, project.LastModifiedBy); return dto; } diff --git a/src/Evelyn.Core/ReadModel/ToggleDetails/ProjectionBuilder.cs b/src/Evelyn.Core/ReadModel/ToggleDetails/ProjectionBuilder.cs index 34704e7..8aae5fb 100644 --- a/src/Evelyn.Core/ReadModel/ToggleDetails/ProjectionBuilder.cs +++ b/src/Evelyn.Core/ReadModel/ToggleDetails/ProjectionBuilder.cs @@ -21,7 +21,7 @@ public ProjectionBuilder(IRepository repository) { var project = await _repository.Get(request.ProjectId, token); var toggle = project.Toggles.First(t => t.Key == request.ToggleKey); - var dto = new ToggleDetailsDto(request.ProjectId, toggle.Key, toggle.Name, toggle.Created, toggle.LastModified); + var dto = new ToggleDetailsDto(request.ProjectId, toggle.Key, toggle.Name, toggle.Created, toggle.CreatedBy, toggle.LastModified, toggle.LastModifiedBy); return dto; } diff --git a/src/Evelyn.Core/ReadModel/ToggleDetails/ToggleDetailsDto.cs b/src/Evelyn.Core/ReadModel/ToggleDetails/ToggleDetailsDto.cs index df6d165..ba45f7d 100644 --- a/src/Evelyn.Core/ReadModel/ToggleDetails/ToggleDetailsDto.cs +++ b/src/Evelyn.Core/ReadModel/ToggleDetails/ToggleDetailsDto.cs @@ -4,8 +4,8 @@ public class ToggleDetailsDto : DtoRoot { - public ToggleDetailsDto(Guid projectId, string key, string name, DateTimeOffset created, DateTimeOffset lastModified) - : base(created, string.Empty, lastModified, string.Empty) + public ToggleDetailsDto(Guid projectId, string key, string name, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy) + : base(created, createdBy, lastModified, lastModifiedBy) { Key = key; Name = name; diff --git a/src/Evelyn.Core/WriteModel/Account/Domain/Account.cs b/src/Evelyn.Core/WriteModel/Account/Domain/Account.cs index 9313db0..836a94f 100644 --- a/src/Evelyn.Core/WriteModel/Account/Domain/Account.cs +++ b/src/Evelyn.Core/WriteModel/Account/Domain/Account.cs @@ -3,11 +3,10 @@ using System; using System.Collections.Generic; using System.Linq; - using CQRSlite.Domain; using Events; using Project.Domain; - public class Account : AggregateRoot + public class Account : EvelynAggregateRoot { private readonly List _projects; @@ -23,14 +22,6 @@ public Account(string userId, Guid accountId) ApplyChange(new AccountRegistered(userId, accountId, DateTimeOffset.UtcNow)); } - public DateTimeOffset Created { get; private set; } - - public string CreatedBy { get; private set; } - - public DateTimeOffset LastModified { get; private set; } - - public string LastModifiedBy { get; private set; } - public IEnumerable Projects => _projects.ToList(); public Project CreateProject(string userId, Guid projectId, string name) diff --git a/src/Evelyn.Core/WriteModel/Evelyn/Domain/Evelyn.cs b/src/Evelyn.Core/WriteModel/Evelyn/Domain/Evelyn.cs index 1bdea66..37ba70e 100644 --- a/src/Evelyn.Core/WriteModel/Evelyn/Domain/Evelyn.cs +++ b/src/Evelyn.Core/WriteModel/Evelyn/Domain/Evelyn.cs @@ -3,10 +3,9 @@ using System; using System.Collections.Generic; using Account.Domain; - using CQRSlite.Domain; using Events; - public class Evelyn : AggregateRoot + public class Evelyn : EvelynAggregateRoot { private readonly IList _accounts; @@ -42,16 +41,24 @@ public void StartSystem(string userId) private void Apply(SystemCreated @event) { - this.Id = @event.Id; + Id = @event.Id; + Created = @event.OccurredAt; + CreatedBy = @event.UserId; + LastModified = @event.OccurredAt; + LastModifiedBy = @event.UserId; } private void Apply(SystemStarted @event) { + LastModified = @event.OccurredAt; + LastModifiedBy = @event.UserId; } private void Apply(AccountRegistered @event) { _accounts.Add(@event.AccountId); + LastModified = @event.OccurredAt; + LastModifiedBy = @event.UserId; } } } diff --git a/src/Evelyn.Core/WriteModel/EvelynAggregateRoot.cs b/src/Evelyn.Core/WriteModel/EvelynAggregateRoot.cs new file mode 100644 index 0000000..0abf6d6 --- /dev/null +++ b/src/Evelyn.Core/WriteModel/EvelynAggregateRoot.cs @@ -0,0 +1,16 @@ +namespace Evelyn.Core.WriteModel +{ + using System; + using CQRSlite.Domain; + + public class EvelynAggregateRoot : AggregateRoot + { + public DateTimeOffset Created { get; protected set; } + + public string CreatedBy { get; protected set; } + + public DateTimeOffset LastModified { get; protected set; } + + public string LastModifiedBy { get; protected set; } + } +} diff --git a/src/Evelyn.Core/WriteModel/Project/Domain/Environment.cs b/src/Evelyn.Core/WriteModel/Project/Domain/Environment.cs index 9f3f3d1..fcce936 100644 --- a/src/Evelyn.Core/WriteModel/Project/Domain/Environment.cs +++ b/src/Evelyn.Core/WriteModel/Project/Domain/Environment.cs @@ -8,18 +8,24 @@ public Environment() { } - public Environment(string key, DateTimeOffset created) + public Environment(string key, DateTimeOffset occurredAt, string userId) : this() { Key = key; - Created = created; - LastModified = created; + Created = occurredAt; + CreatedBy = userId; + LastModified = occurredAt; + LastModifiedBy = CreatedBy; } public string Key { get; private set; } public DateTimeOffset Created { get; private set; } + public string CreatedBy { get; private set; } + public DateTimeOffset LastModified { get; private set; } + + public string LastModifiedBy { get; private set; } } } diff --git a/src/Evelyn.Core/WriteModel/Project/Domain/EnvironmentState.cs b/src/Evelyn.Core/WriteModel/Project/Domain/EnvironmentState.cs index 52adb89..0e155f4 100644 --- a/src/Evelyn.Core/WriteModel/Project/Domain/EnvironmentState.cs +++ b/src/Evelyn.Core/WriteModel/Project/Domain/EnvironmentState.cs @@ -14,14 +14,16 @@ public EnvironmentState() Version = -1; } - public EnvironmentState(string environmentKey, IEnumerable toggleStates, DateTimeOffset created) + public EnvironmentState(string environmentKey, IEnumerable toggleStates, DateTimeOffset occurredAt, string userId) : this() { EnvironmentKey = environmentKey; _toggleStates = toggleStates.ToList(); Version = 0; - Created = created; - LastModified = created; + Created = occurredAt; + CreatedBy = userId; + LastModified = occurredAt; + LastModifiedBy = userId; } public string EnvironmentKey { get; private set; } @@ -32,19 +34,26 @@ public EnvironmentState(string environmentKey, IEnumerable toggleSt public DateTimeOffset Created { get; private set; } + public string CreatedBy { get; private set; } + public DateTimeOffset LastModified { get; private set; } - public void AddToggleState(ToggleState toggleState) + public string LastModifiedBy { get; private set; } + + public void AddToggleState(ToggleState toggleState, DateTimeOffset occurredAt, string userId) { _toggleStates.Add(toggleState); + LastModified = occurredAt; + LastModifiedBy = userId; Version++; } - public void SetToggleState(string key, string value, DateTimeOffset modified) + public void SetToggleState(string key, string value, DateTimeOffset occurredAt, string userId) { var toggleState = _toggleStates.First(ts => ts.Key == key); - toggleState.SetState(value, modified); - LastModified = modified; + toggleState.SetState(value, occurredAt, userId); + LastModified = occurredAt; + LastModifiedBy = userId; Version++; } } diff --git a/src/Evelyn.Core/WriteModel/Project/Domain/Project.cs b/src/Evelyn.Core/WriteModel/Project/Domain/Project.cs index f4e3e62..92efb94 100644 --- a/src/Evelyn.Core/WriteModel/Project/Domain/Project.cs +++ b/src/Evelyn.Core/WriteModel/Project/Domain/Project.cs @@ -3,10 +3,9 @@ using System; using System.Collections.Generic; using System.Linq; - using CQRSlite.Domain; using Events; - public class Project : AggregateRoot + public class Project : EvelynAggregateRoot { private List _environments; private List _toggles; @@ -32,10 +31,6 @@ public Project(string userId, Guid accountId, Guid projectId, string name) public IEnumerable EnvironmentStates => _environmentStates.ToList(); - public DateTimeOffset Created { get; private set; } - - public DateTimeOffset LastModified { get; private set; } - public string Name { get; private set; } public void AddEnvironment(string userId, string key) @@ -97,49 +92,54 @@ public void ChangeToggleState(string userId, string environmentKey, string toggl private void Apply(ProjectCreated e) { Id = e.Id; + Created = e.OccurredAt; + CreatedBy = e.UserId; + Name = e.Name; _environments = new List(); _toggles = new List(); _environmentStates = new List(); - Created = e.OccurredAt; + LastModified = e.OccurredAt; + LastModifiedBy = e.UserId; } private void Apply(EnvironmentAdded e) { - _environments.Add(new Environment(e.Key, e.OccurredAt)); - LastModified = e.OccurredAt; - } + _environments.Add(new Environment(e.Key, e.OccurredAt, e.UserId)); - private void Apply(EnvironmentStateAdded e) - { - var toggleStates = e.ToggleStates.Select(ts => new ToggleState(ts.Key, ts.Value, e.OccurredAt)); - var environmentState = new EnvironmentState(e.EnvironmentKey, toggleStates, e.OccurredAt); - _environmentStates.Add(environmentState); LastModified = e.OccurredAt; + LastModifiedBy = e.UserId; } private void Apply(ToggleAdded e) { - var toggle = new Toggle(e.Key, e.Name, e.OccurredAt); + var toggle = new Toggle(e.Key, e.Name, e.OccurredAt, e.UserId); _toggles.Add(toggle); + LastModified = e.OccurredAt; + LastModifiedBy = e.UserId; + } + + private void Apply(EnvironmentStateAdded e) + { + var toggleStates = e.ToggleStates.Select(ts => new ToggleState(ts.Key, ts.Value, e.OccurredAt, e.UserId)); + var environmentState = new EnvironmentState(e.EnvironmentKey, toggleStates, e.OccurredAt, e.UserId); + _environmentStates.Add(environmentState); } private void Apply(ToggleStateAdded e) { - var toggleState = new ToggleState(e.ToggleKey, e.Value, e.OccurredAt); + var toggleState = new ToggleState(e.ToggleKey, e.Value, e.OccurredAt, e.UserId); var environmentState = _environmentStates.First(es => es.EnvironmentKey == e.EnvironmentKey); - environmentState.AddToggleState(toggleState); - LastModified = e.OccurredAt; + environmentState.AddToggleState(toggleState, e.OccurredAt, e.UserId); } private void Apply(ToggleStateChanged @event) { var environmentState = _environmentStates.First(es => es.EnvironmentKey == @event.EnvironmentKey); - environmentState.SetToggleState(@event.ToggleKey, @event.Value, @event.OccurredAt); - LastModified = @event.OccurredAt; + environmentState.SetToggleState(@event.ToggleKey, @event.Value, @event.OccurredAt, @event.UserId); } } } diff --git a/src/Evelyn.Core/WriteModel/Project/Domain/Toggle.cs b/src/Evelyn.Core/WriteModel/Project/Domain/Toggle.cs index dfbafc4..766a63a 100644 --- a/src/Evelyn.Core/WriteModel/Project/Domain/Toggle.cs +++ b/src/Evelyn.Core/WriteModel/Project/Domain/Toggle.cs @@ -9,12 +9,14 @@ public Toggle() { } - public Toggle(string key, string name, DateTimeOffset created) + public Toggle(string key, string name, DateTimeOffset occurredAt, string userId) { Name = name; Key = key; - Created = created; - LastModified = created; + Created = occurredAt; + CreatedBy = userId; + LastModified = occurredAt; + LastModifiedBy = userId; } public string Name { get; } @@ -23,8 +25,12 @@ public Toggle(string key, string name, DateTimeOffset created) public DateTimeOffset Created { get; private set; } + public string CreatedBy { get; private set; } + public DateTimeOffset LastModified { get; private set; } + public string LastModifiedBy { get; private set; } + public string DefaultValue => default(bool).ToString(CultureInfo.InvariantCulture); } } diff --git a/src/Evelyn.Core/WriteModel/Project/Domain/ToggleState.cs b/src/Evelyn.Core/WriteModel/Project/Domain/ToggleState.cs index 9daf40d..1cef055 100644 --- a/src/Evelyn.Core/WriteModel/Project/Domain/ToggleState.cs +++ b/src/Evelyn.Core/WriteModel/Project/Domain/ToggleState.cs @@ -9,14 +9,16 @@ public ToggleState() Version = -1; } - public ToggleState(string key, string value, DateTimeOffset created) + public ToggleState(string key, string value, DateTimeOffset occurredAt, string userId) : this() { Key = key; Value = value; Version = 0; - Created = created; - LastModified = created; + Created = occurredAt; + CreatedBy = userId; + LastModified = occurredAt; + LastModifiedBy = userId; } public string Key { get; private set; } @@ -27,12 +29,17 @@ public ToggleState(string key, string value, DateTimeOffset created) public DateTimeOffset Created { get; private set; } + public string CreatedBy { get; private set; } + public DateTimeOffset LastModified { get; private set; } - public void SetState(string value, DateTimeOffset modified) + public string LastModifiedBy { get; private set; } + + public void SetState(string value, DateTimeOffset occurredAt, string userId) { Value = value; - LastModified = modified; + LastModified = occurredAt; + LastModifiedBy = userId; Version++; } }