Skip to content

Commit

Permalink
Set user info on account projects dto
Browse files Browse the repository at this point in the history
  • Loading branch information
binarymash committed Mar 19, 2018
1 parent ed85fa8 commit aca1a61
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 12 deletions.
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 @@ -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 @@ -5,7 +5,7 @@
public class EnvironmentDetailsDto : DtoRoot
{
public EnvironmentDetailsDto(Guid projectId, string key, DateTimeOffset created, DateTimeOffset lastModified)
: base(created, lastModified)
: base(created, string.Empty, lastModified, string.Empty)
{
Key = key;
ProjectId = projectId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EnvironmentStateDto : DtoRoot
private readonly List<ToggleStateDto> _toggleStates;

public EnvironmentStateDto(int version, DateTimeOffset created, DateTimeOffset lastModified, IEnumerable<ToggleStateDto> toggleStates)
: base(created, lastModified)
: base(created, string.Empty, lastModified, string.Empty)
{
Version = version;
_toggleStates = toggleStates.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ProjectDetailsDto : DtoRoot
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)
: base(created, string.Empty, lastModified, string.Empty)
{
Id = id;
Name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ToggleDetailsDto : DtoRoot
{
public ToggleDetailsDto(Guid projectId, string key, string name, DateTimeOffset created, DateTimeOffset lastModified)
: base(created, lastModified)
: base(created, string.Empty, lastModified, string.Empty)
{
Key = key;
Name = name;
Expand Down
9 changes: 8 additions & 1 deletion src/Evelyn.Core/WriteModel/Account/Domain/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ public Account(string userId, Guid accountId)

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<Guid> Projects => _projects.ToList();

public Project CreateProject(string userId, Guid projectId, string name)
Expand All @@ -43,15 +47,18 @@ public Project CreateProject(string userId, Guid projectId, string name)

private void Apply(AccountRegistered @event)
{
this.Id = @event.Id;
Id = @event.Id;
Created = @event.OccurredAt;
CreatedBy = @event.UserId;
LastModified = @event.OccurredAt;
LastModifiedBy = @event.UserId;
}

private void Apply(ProjectCreated @event)
{
_projects.Add(@event.ProjectId);
LastModified = @event.OccurredAt;
LastModifiedBy = @event.UserId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void ExceptionWhenGettingProjectDetails()

private void GivenThatThereAreProjectsOnAnAccount()
{
_accountProjectsReturnedByFacade = new AccountProjectsDto(_accountId, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, _fixture.CreateMany<ProjectListDto>());
_accountProjectsReturnedByFacade = new AccountProjectsDto(_accountId, DateTimeOffset.UtcNow, _fixture.Create<string>(), DateTimeOffset.UtcNow, _fixture.Create<string>(), _fixture.CreateMany<ProjectListDto>());

_readModelFacade.GetProjects(_accountId).Returns(_accountProjectsReturnedByFacade);
}
Expand Down

0 comments on commit aca1a61

Please sign in to comment.