Esempio n. 1
0
        public Task CanAssign_should_throw_exception_if_user_already_exists_with_same_permission()
        {
            var command = new AssignContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", AppContributorPermission.Owner);

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_1, command, users, appPlan),
                                                new ValidationError("Contributor has already this permission.", "Permission")));
        }
Esempio n. 2
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. 3
0
        public async Task CanAssign_should_not_throw_exception_if_user_found()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(-1);

            var command = new AssignContributor {
                ContributorId = "1"
            };

            await GuardAppContributors.CanAssign(contributors_0, roles, command, users, appPlan);
        }
        public Task CanAssign_should_throw_exception_if_user_not_found()
        {
            A.CallTo(() => users.FindByIdAsync(A <string> .Ignored))
            .Returns(Task.FromResult <IUser>(null));

            var command = new AssignContributor {
                ContributorId = "1", Permission = (AppContributorPermission)10
            };

            return(Assert.ThrowsAsync <ValidationException>(() => GuardAppContributors.CanAssign(contributors_0, command, users, appPlan)));
        }
        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 Task CanAssign_should_throw_exception_if_user_already_exists_with_same_role()
        {
            var command = new AssignContributor {
                ContributorId = "1", Role = Role.Owner
            };

            var contributors_1 = contributors_0.Assign("1", Role.Owner);

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_1, command, users, appPlan, roles),
                                                new ValidationError("Contributor has already this role.", "Role")));
        }
Esempio n. 7
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. 8
0
        public Task CanAssign_should_not_throw_exception_if_contributor_max_reached_but_role_changed()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(2);

            var command = new AssignContributor {
                ContributorId = "1", Role = Role.Developer
            };

            var contributors_1 = contributors_0.Assign("1", Role.Editor);
            var contributors_2 = contributors_1.Assign("2", Role.Editor);

            return(GuardAppContributors.CanAssign(contributors_2, command, users, appPlan, roles));
        }
Esempio n. 9
0
        public async Task CanAssign_should_not_throw_exception_if_contributor_max_reached_but_from_restore()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(2);

            var command = new AssignContributor {
                ContributorId = "3", Restoring = true
            };

            var contributors_1 = contributors_0.Assign("1", Role.Editor);
            var contributors_2 = contributors_1.Assign("2", Role.Editor);

            await GuardAppContributors.CanAssign(contributors_2, roles, command, users, appPlan);
        }
Esempio n. 10
0
        public Task CanAssign_should_throw_exception_if_contributor_max_reached()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(2);

            var command = new AssignContributor {
                ContributorId = "3"
            };

            var contributors_1 = contributors_0.Assign("1", AppContributorPermission.Owner);
            var contributors_2 = contributors_1.Assign("2", AppContributorPermission.Editor);

            return(Assert.ThrowsAsync <ValidationException>(() => GuardAppContributors.CanAssign(contributors_2, command, users, appPlan)));
        }
Esempio n. 11
0
        public async Task CanAssign_should_not_throw_exception_if_contributor_max_reached_but_role_changed()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(2);

            var command = new AssignContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", Role.Developer);
            var contributors_2 = contributors_1.Assign("2", Role.Developer);

            await GuardAppContributors.CanAssign(command, App(contributors_2), users, appPlan);
        }
Esempio n. 12
0
        public Task CanAssign_should_throw_exception_if_contributor_max_reached()
        {
            A.CallTo(() => appPlan.MaxContributors)
            .Returns(2);

            var command = new AssignContributor {
                ContributorId = "3"
            };

            var contributors_1 = contributors_0.Assign("1", Role.Owner);
            var contributors_2 = contributors_1.Assign("2", Role.Editor);

            return(ValidationAssert.ThrowsAsync(() => GuardAppContributors.CanAssign(contributors_2, command, users, appPlan, roles),
                                                new ValidationError("You have reached the maximum number of contributors for your plan.")));
        }
Esempio n. 13
0
        public Task CanAssign_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new AssignContributor();

            return(Assert.ThrowsAsync <ValidationException>(() => GuardAppContributors.CanAssign(contributors_0, command, users, appPlan)));
        }
Esempio n. 14
0
        public void CanRemove_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new RemoveContributor();

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