Skip to content

Commit

Permalink
Merge pull request #85 from binarymash/feature/#83-AddUserInformation…
Browse files Browse the repository at this point in the history
…ToDTOs

Feature/#83 add user information to DTOs
  • Loading branch information
binarymash authored Mar 19, 2018
2 parents ed85fa8 + a9746ff commit 7bf2284
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public void AccountAndProjectsExist()
.When(_ => WhenWeInvokeTheProjectionBuilder())
.Then(_ => ThenTheAccountIdIsSet())
.And(_ => ThenTheCreatedDateIsSet())
.And(_ => ThenTheCreatedByIsSet())
.And(_ => ThenTheLastModifiedDateIsSet())
.And(_ => ThenTheLastModifiedByIsSet())
.And(_ => ThenAllTheProjectsAreSet())
.BDDfy();
}
Expand Down Expand Up @@ -182,11 +184,21 @@ private void ThenTheCreatedDateIsSet()
Dto.Created.Should().Be(_account.Created);
}

private void ThenTheCreatedByIsSet()
{
Dto.CreatedBy.Should().Be(_account.CreatedBy);
}

private void ThenTheLastModifiedDateIsSet()
{
Dto.LastModified.Should().Be(_account.LastModified);
}

private void ThenTheLastModifiedByIsSet()
{
Dto.LastModifiedBy.Should().Be(_account.LastModifiedBy);
}

private void ThenAllTheProjectsAreSet()
{
var projects = Dto.Projects.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public void EnvironmentExists()
.And(_ => GivenTheProjectIsInTheRepository())
.When(_ => WhenWeInvokeTheProjectionBuilder())
.Then(_ => ThenTheCreatedDateIsSet())
.And(_ => ThenTheCreatedByIsSet())
.And(_ => ThenTheLastModifiedDateIsSet())
.And(_ => ThenTheLastModifiedByIsSet())
.And(_ => ThenTheProjectIdIsSet())
.And(_ => ThenTheEnvironmentKeyIsSet())
.BDDfy();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public class ProjectionBuilderSpecs : ProjectionBuilderSpecs<ProjectionBuilder,
private string _environmentKey;
private EnvironmentState _expectedEnvironmentState;

private string _toggle1Key;
private string _toggle2Key;
private string _toggle3Key;
private string _toggleKey;

public ProjectionBuilderSpecs()
{
Expand Down Expand Up @@ -65,7 +63,9 @@ public void EnvironmentExists()
.When(_ => WhenWeInvokeTheProjectionBuilderForTheEnvironmentState())
.Then(_ => ThenTheEnvironmentVersionIsSet())
.And(_ => ThenTheCreatedDateIsSet())
.And(_ => ThenTheCreatedByIsSet())
.And(_ => ThenTheLastModifiedDateIsSet())
.And(_ => ThenTheLastModifiedByIsSet())
.And(_ => ThenAllTheToggleStatesAreSet())
.BDDfy();
}
Expand Down Expand Up @@ -104,9 +104,7 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles()
{
_projectId = DataFixture.Create<Guid>();
_environmentKey = DataFixture.Create<string>();
_toggle1Key = DataFixture.Create<string>();
_toggle2Key = DataFixture.Create<string>();
_toggle3Key = DataFixture.Create<string>();
_toggleKey = DataFixture.Create<string>();

_projectEvents.Add(DataFixture.Build<ProjectCreated>()
.With(ev => ev.Version, 0)
Expand All @@ -128,14 +126,14 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles()
_projectEvents.Add(DataFixture.Build<ToggleAdded>()
.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<string>(),
_projectId,
_environmentKey,
_toggle1Key,
_toggleKey,
DataFixture.Create<bool>().ToString(),
DateTimeOffset.UtcNow)
{
Expand All @@ -145,14 +143,14 @@ private void GivenWeHaveAProjectWithEnvironmentsAndToggles()
_projectEvents.Add(DataFixture.Build<ToggleAdded>()
.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<string>(),
_projectId,
_environmentKey,
_toggle1Key,
_toggleKey,
DataFixture.Create<bool>().ToString(),
DateTimeOffset.UtcNow)
{
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void ThenAnEnvironmentAddedEventIsPublished()
var @event = (EnvironmentAdded)PublishedEvents.First(ev => ev is EnvironmentAdded);
@event.UserId.Should().Be(UserId);
@event.Key.Should().Be(_newEnvironmentKey);
@event.OccurredAt.Should().BeCloseTo(DateTimeOffset.UtcNow);
@event.OccurredAt.Should().BeCloseTo(DateTimeOffset.UtcNow, 100);
}

private void ThenAnEnvironmentStateAddedEventIsPublished()
Expand All @@ -91,7 +91,7 @@ private void ThenAnEnvironmentStateAddedEventIsPublished()
@event.UserId.Should().Be(UserId);
@event.EnvironmentKey.Should().Be(_newEnvironmentKey);
@event.ToggleStates.ToList().Exists(ts => ts.Key == _toggleKey && ts.Value == default(bool).ToString());
@event.OccurredAt.Should().BeCloseTo(DateTimeOffset.UtcNow);
@event.OccurredAt.Should().BeCloseTo(DateTimeOffset.UtcNow, 100);
}

private void ThenADuplicateEnvironmentKeyExceptionIsThrown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class AccountProjectsDto : DtoRoot
{
private readonly List<ProjectListDto> _projects;

public AccountProjectsDto(Guid accountId, DateTimeOffset created, DateTimeOffset lastModified, IEnumerable<ProjectListDto> projects)
: base(created, lastModified)
public AccountProjectsDto(Guid accountId, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy, IEnumerable<ProjectListDto> projects)
: base(created, createdBy, lastModified, lastModifiedBy)
{
AccountId = accountId;
_projects = projects?.ToList() ?? new List<ProjectListDto>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProjectionBuilder(IRepository repository)
projects.Add(new ProjectListDto(project.Id, project.Name));
}

var dto = new AccountProjectsDto(account.Id, account.Created, account.LastModified, projects);
var dto = new AccountProjectsDto(account.Id, account.Created, account.CreatedBy, account.LastModified, account.LastModifiedBy, projects);

return dto;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Evelyn.Core/ReadModel/DtoRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

public abstract class DtoRoot
{
protected DtoRoot(DateTimeOffset created, DateTimeOffset lastModified)
protected DtoRoot(DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy)
{
Created = created;
CreatedBy = createdBy;
LastModified = lastModified;
LastModifiedBy = lastModifiedBy;
}

public DateTimeOffset Created { get; private set; }

public string CreatedBy { get; private set; }

public DateTimeOffset LastModified { get; private set; }

public string LastModifiedBy { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class EnvironmentDetailsDto : DtoRoot
{
public EnvironmentDetailsDto(Guid projectId, string key, DateTimeOffset created, DateTimeOffset lastModified)
: base(created, lastModified)
public EnvironmentDetailsDto(Guid projectId, string key, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy)
: base(created, createdBy, lastModified, lastModifiedBy)
{
Key = key;
ProjectId = projectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ProjectionBuilder(IRepository repository)
{
var project = await _repository.Get<Project>(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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class EnvironmentStateDto : DtoRoot
{
private readonly List<ToggleStateDto> _toggleStates;

public EnvironmentStateDto(int version, DateTimeOffset created, DateTimeOffset lastModified, IEnumerable<ToggleStateDto> toggleStates)
: base(created, lastModified)
public EnvironmentStateDto(int version, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy, IEnumerable<ToggleStateDto> toggleStates)
: base(created, createdBy, lastModified, lastModifiedBy)
{
Version = version;
_toggleStates = toggleStates.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ProjectionBuilder(IRepository repository)
var project = await _repository.Get<Project>(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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Evelyn.Core/ReadModel/ProjectDetails/ProjectDetailsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class ProjectDetailsDto : DtoRoot
private readonly IList<EnvironmentListDto> _environments;
private readonly IList<ToggleListDto> _toggles;

public ProjectDetailsDto(Guid id, string name, IEnumerable<EnvironmentListDto> environments, IEnumerable<ToggleListDto> toggles, int version, DateTimeOffset created, DateTimeOffset lastModified)
: base(created, lastModified)
public ProjectDetailsDto(Guid id, string name, IEnumerable<EnvironmentListDto> environments, IEnumerable<ToggleListDto> toggles, int version, DateTimeOffset created, string createdBy, DateTimeOffset lastModified, string lastModifiedBy)
: base(created, createdBy, lastModified, lastModifiedBy)
{
Id = id;
Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ProjectionBuilder(IRepository repository)
var project = await _repository.Get<Project>(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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ProjectionBuilder(IRepository repository)
{
var project = await _repository.Get<Project>(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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Evelyn.Core/ReadModel/ToggleDetails/ToggleDetailsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class ToggleDetailsDto : DtoRoot
{
public ToggleDetailsDto(Guid projectId, string key, string name, DateTimeOffset created, DateTimeOffset lastModified)
: base(created, lastModified)
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;
Expand Down
Loading

0 comments on commit 7bf2284

Please sign in to comment.