public void CanRemove_should_throw_exception_if_contributor_not_found() { var command = new RemoveContributor { ContributorId = "1" }; Assert.Throws <DomainObjectNotFoundException>(() => GuardAppContributors.CanRemove(contributors_0, command)); }
public AppDomainObject RemoveContributor(RemoveContributor command) { ThrowIfNotCreated(); RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved())); return(this); }
protected Task On(RemoveContributor command, CommandContext context) { return(handler.UpdateSyncedAsync <AppDomainObject>(context, a => { GuardAppContributors.CanRemove(a.Snapshot.Contributors, command); a.RemoveContributor(command); })); }
public async Task <IActionResult> DeleteContributor(string app, string id) { var command = new RemoveContributor { ContributorId = id }; var response = await InvokeCommandAsync(command); return(Ok(response)); }
public AppDomainObject RemoveContributor(RemoveContributor command) { Guard.Valid(command, nameof(command), () => "Cannot remove contributor"); ThrowIfNotCreated(); RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved())); return(this); }
public async Task <IActionResult> DeleteMyself(string app) { var command = new RemoveContributor { ContributorId = UserId() }; var response = await InvokeCommandAsync(command); return(Ok(response)); }
public void CanRemove_should_throw_exception_if_contributor_is_only_owner() { var command = new RemoveContributor { ContributorId = "1" }; var contributors_1 = contributors_0.Assign("1", AppContributorPermission.Owner); var contributors_2 = contributors_1.Assign("2", AppContributorPermission.Editor); Assert.Throws <ValidationException>(() => GuardAppContributors.CanRemove(contributors_2, command)); }
public void CanRemove_should_not_throw_exception_if_contributor_not_only_owner() { var command = new RemoveContributor { ContributorId = "1" }; contributors.Assign("1", AppContributorPermission.Owner); contributors.Assign("2", AppContributorPermission.Owner); GuardAppContributors.CanRemove(contributors, command); }
public void CanRemove_should_not_throw_exception_if_contributor_not_only_owner() { var command = new RemoveContributor { ContributorId = "1" }; var contributors_1 = contributors_0.Assign("1", Role.Owner); var contributors_2 = contributors_1.Assign("2", Role.Owner); GuardAppContributors.CanRemove(contributors_2, command); }
public async Task <IActionResult> DeleteContributor(string appId, string contributorId) { var update = new RemoveContributor { ContributorId = contributorId, UserId = UserId }; var app = await appStore.UpsertAsync(appId, update, HttpContext.RequestAborted); var response = await AppDetailsDto.FromDomainObjectAsync(app, UserId, userResolver); return(Ok(response)); }
public void CanRemove_should_throw_exception_if_contributor_is_only_owner() { var command = new RemoveContributor { ContributorId = "1" }; var contributors_1 = contributors_0.Assign("1", Role.Owner); var contributors_2 = contributors_1.Assign("2", Role.Editor); ValidationAssert.Throws(() => GuardAppContributors.CanRemove(contributors_2, command), new ValidationError("Cannot remove the only owner.")); }
public async Task <ActionResult> RemoveContributorAsync([FromRoute] Guid backpackId, [FromRoute] Guid userId) { var sub = User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value; var command = new RemoveContributor(sub, backpackId, userId); var result = await _mediator.Send(command); if (result.IsFailure) { return(BadRequest()); } return(NoContent()); }
public async Task Should_remove_from_user_index_on_remove_of_contributor() { var command = new RemoveContributor { AppId = appId, ContributorId = userId }; var context = new CommandContext(command, commandBus) .Complete(); await sut.HandleAsync(context); A.CallTo(() => indexByUser.RemoveAsync(appId.Id)) .MustHaveHappened(); }
public async Task RemoveContributor_should_create_events_and_update_state() { var command = new RemoveContributor { ContributorId = contributorId }; await ExecuteCreateAsync(); await ExecuteAssignContributorAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppContributorRemoved { ContributorId = contributorId }) ); }
public static void CanRemove(AppContributors contributors, RemoveContributor command) { Guard.NotNull(command, nameof(command)); Validate.It(e => { if (string.IsNullOrWhiteSpace(command.ContributorId)) { e(Not.Defined(nameof(command.ContributorId)), nameof(command.ContributorId)); } var ownerIds = contributors.Where(x => x.Value == Role.Owner).Select(x => x.Key).ToList(); if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId)) { e(T.Get("apps.contributors.onlyOneOwner")); } }); if (!contributors.ContainsKey(command.ContributorId)) { throw new DomainObjectNotFoundException(command.ContributorId); } }
public static void CanRemove(AppContributors contributors, RemoveContributor command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot remove contributor.", e => { if (string.IsNullOrWhiteSpace(command.ContributorId)) { e(Not.Defined("Contributor id"), nameof(command.ContributorId)); } var ownerIds = contributors.Where(x => x.Value == Role.Owner).Select(x => x.Key).ToList(); if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId)) { e("Cannot remove the only owner."); } }); if (!contributors.ContainsKey(command.ContributorId)) { throw new DomainObjectNotFoundException(command.ContributorId, "Contributors", typeof(IAppEntity)); } }
public static void CanRemove(AppContributors contributors, RemoveContributor command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot remove contributor.", error => { if (string.IsNullOrWhiteSpace(command.ContributorId)) { error(new ValidationError("Contributor id not assigned.", nameof(command.ContributorId))); } var ownerIds = contributors.Where(x => x.Value == AppContributorPermission.Owner).Select(x => x.Key).ToList(); if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId)) { error(new ValidationError("Cannot remove the only owner.", nameof(command.ContributorId))); } }); if (!contributors.ContainsKey(command.ContributorId)) { throw new DomainObjectNotFoundException(command.ContributorId, "Contributors", typeof(AppDomainObject)); } }
private void RemoveContributor(RemoveContributor command) { Raise(command, new AppContributorRemoved()); }
private Task RemoveContributorAsync(RemoveContributor command) { return(Index(command.ContributorId).RemoveAsync(command.AppId)); }
public void RemoveContributor(RemoveContributor command) { RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved())); }
protected Task On(RemoveContributor command, CommandContext context) { return(handler.UpdateAsync <AppDomainObject>(context, a => a.RemoveContributor(command))); }
private async Task RemoveContributorAsync(RemoveContributor command) { await Index(command.ContributorId).RemoveAsync(command.AggregateId); }
private static string GetUserId(RemoveContributor removeContributor) { return(removeContributor.ContributorId); }
public void CanRemove_should_throw_exception_if_contributor_id_is_null() { var command = new RemoveContributor(); Assert.Throws <ValidationException>(() => GuardAppContributors.CanRemove(contributors_0, command)); }