public void CanRemove_should_throw_exception_if_contributor_not_found()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardAppContributors.CanRemove(contributors_0, command));
        }
Esempio n. 2
0
        public AppDomainObject RemoveContributor(RemoveContributor command)
        {
            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));

            return(this);
        }
Esempio n. 3
0
        protected Task On(RemoveContributor command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppContributors.CanRemove(a.Snapshot.Contributors, command);

                a.RemoveContributor(command);
            }));
        }
Esempio n. 4
0
        public async Task <IActionResult> DeleteContributor(string app, string id)
        {
            var command = new RemoveContributor {
                ContributorId = id
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Esempio n. 5
0
        public AppDomainObject RemoveContributor(RemoveContributor command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot remove contributor");

            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));

            return(this);
        }
Esempio n. 6
0
        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));
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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."));
        }
Esempio n. 12
0
        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());
        }
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 16
0
        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));
            }
        }
Esempio n. 17
0
        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));
            }
        }
Esempio n. 18
0
 private void RemoveContributor(RemoveContributor command)
 {
     Raise(command, new AppContributorRemoved());
 }
Esempio n. 19
0
 private Task RemoveContributorAsync(RemoveContributor command)
 {
     return(Index(command.ContributorId).RemoveAsync(command.AppId));
 }
Esempio n. 20
0
 public void RemoveContributor(RemoveContributor command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));
 }
Esempio n. 21
0
 protected Task On(RemoveContributor command, CommandContext context)
 {
     return(handler.UpdateAsync <AppDomainObject>(context, a => a.RemoveContributor(command)));
 }
Esempio n. 22
0
 private async Task RemoveContributorAsync(RemoveContributor command)
 {
     await Index(command.ContributorId).RemoveAsync(command.AggregateId);
 }
Esempio n. 23
0
 private static string GetUserId(RemoveContributor removeContributor)
 {
     return(removeContributor.ContributorId);
 }
Esempio n. 24
0
        public void CanRemove_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new RemoveContributor();

            Assert.Throws <ValidationException>(() => GuardAppContributors.CanRemove(contributors_0, command));
        }