Пример #1
0
        public void CanAdd_should_not_throw_exception_if_success()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = ".*"
            };

            GuardAppPattern.CanAdd(patterns_0, command);
        }
Пример #2
0
        public void CanDelete_should_throw_exception_if_pattern_not_found()
        {
            var command = new DeletePattern {
                PatternId = patternId
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardAppPattern.CanDelete(patterns_0, command));
        }
Пример #3
0
        public void CanAdd_should_throw_exception_if_pattern_not_valid()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = "[0-9{1}"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command));
        }
Пример #4
0
        public void CanAdd_should_throw_exception_if_id_empty_guid()
        {
            var command = new AddPattern {
                Name = string.Empty, Pattern = ".*"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command));
        }
Пример #5
0
        public void CanAdd_should_throw_exception_if_pattern_empty()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = string.Empty
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command));
        }
Пример #6
0
        public void CanUpdate_should_throw_exception_if_pattern_does_not_exists()
        {
            var command = new UpdatePattern {
                PatternId = patternId, Name = "Pattern1", Pattern = ".*"
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardAppPattern.CanUpdate(patterns_0, command));
        }
Пример #7
0
        protected async Task On(UpdatePattern command, CommandContext context)
        {
            await handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppPattern.CanUpdate(a.Snapshot.Patterns, command);

                a.UpdatePattern(command);
            });
        }
Пример #8
0
        protected Task On(DeletePattern command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppPattern.CanDelete(a.Snapshot.Patterns, command);

                a.DeletePattern(command);
            }));
        }
Пример #9
0
        protected Task On(AddPattern command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppPattern.CanAdd(a.State.Patterns, command);

                a.AddPattern(command);
            }));
        }
Пример #10
0
        public void CanDelete_should_not_throw_exception_if_success()
        {
            var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message");

            var command = new DeletePattern {
                PatternId = patternId
            };

            GuardAppPattern.CanDelete(patterns_1, command);
        }
Пример #11
0
        public void CanAdd_should_throw_exception_if_name_exists()
        {
            var patterns_1 = patterns_0.Add(Guid.NewGuid(), "any", "[a-z]", "Message");

            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = ".*"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_1, command));
        }
Пример #12
0
        public void CanUpdate_should_not_throw_exception_if_pattern_exist_with_valid_command()
        {
            var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message");

            var command = new UpdatePattern {
                PatternId = patternId, Name = "Pattern1", Pattern = ".*"
            };

            GuardAppPattern.CanUpdate(patterns_1, command);
        }
Пример #13
0
        public void CanUpdate_should_throw_exception_if_pattern_not_valid()
        {
            var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message");

            var command = new UpdatePattern {
                PatternId = patternId, Name = "any", Pattern = "[0-9{1}"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanUpdate(patterns_1, command));
        }
Пример #14
0
        public void CanUpdate_should_throw_exception_if_name_empty()
        {
            var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message");

            var command = new UpdatePattern {
                PatternId = patternId, Name = string.Empty, Pattern = ".*"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanUpdate(patterns_1, command));
        }
Пример #15
0
        public void CanUpdate_should_throw_exception_if_pattern_exists()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

            var patterns_1 = patterns_0.Add(id1, "Pattern1", "[0-5]", "Message");
            var patterns_2 = patterns_1.Add(id2, "Pattern2", "[0-4]", "Message");

            var command = new UpdatePattern {
                PatternId = id2, Name = "Pattern2", Pattern = "[0-5]"
            };

            Assert.Throws <ValidationException>(() => GuardAppPattern.CanUpdate(patterns_2, command));
        }
Пример #16
0
        public override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateApp createApp:
                return(CreateAsync(createApp, async c =>
                {
                    await GuardApp.CanCreate(c, appProvider);

                    Create(c);
                }));

            case AssignContributor assigneContributor:
                return(UpdateAsync(assigneContributor, async c =>
                {
                    await GuardAppContributors.CanAssign(Snapshot.Contributors, c, userResolver, appPlansProvider.GetPlan(Snapshot.Plan?.PlanId));

                    AssignContributor(c);
                }));

            case RemoveContributor removeContributor:
                return(UpdateAsync(removeContributor, c =>
                {
                    GuardAppContributors.CanRemove(Snapshot.Contributors, c);

                    RemoveContributor(c);
                }));

            case AttachClient attachClient:
                return(UpdateAsync(attachClient, c =>
                {
                    GuardAppClients.CanAttach(Snapshot.Clients, c);

                    AttachClient(c);
                }));

            case UpdateClient updateClient:
                return(UpdateAsync(updateClient, c =>
                {
                    GuardAppClients.CanUpdate(Snapshot.Clients, c);

                    UpdateClient(c);
                }));

            case RevokeClient revokeClient:
                return(UpdateAsync(revokeClient, c =>
                {
                    GuardAppClients.CanRevoke(Snapshot.Clients, c);

                    RevokeClient(c);
                }));

            case AddLanguage addLanguage:
                return(UpdateAsync(addLanguage, c =>
                {
                    GuardAppLanguages.CanAdd(Snapshot.LanguagesConfig, c);

                    AddLanguage(c);
                }));

            case RemoveLanguage removeLanguage:
                return(UpdateAsync(removeLanguage, c =>
                {
                    GuardAppLanguages.CanRemove(Snapshot.LanguagesConfig, c);

                    RemoveLanguage(c);
                }));

            case UpdateLanguage updateLanguage:
                return(UpdateAsync(updateLanguage, c =>
                {
                    GuardAppLanguages.CanUpdate(Snapshot.LanguagesConfig, c);

                    UpdateLanguage(c);
                }));

            case AddPattern addPattern:
                return(UpdateAsync(addPattern, c =>
                {
                    GuardAppPattern.CanAdd(Snapshot.Patterns, c);

                    AddPattern(c);
                }));

            case DeletePattern deletePattern:
                return(UpdateAsync(deletePattern, c =>
                {
                    GuardAppPattern.CanDelete(Snapshot.Patterns, c);

                    DeletePattern(c);
                }));

            case UpdatePattern updatePattern:
                return(UpdateAsync(updatePattern, c =>
                {
                    GuardAppPattern.CanUpdate(Snapshot.Patterns, c);

                    UpdatePattern(c);
                }));

            case ChangePlan changePlan:
                return(UpdateReturnAsync(changePlan, async c =>
                {
                    GuardApp.CanChangePlan(c, Snapshot.Plan, appPlansProvider);

                    if (c.FromCallback)
                    {
                        ChangePlan(c);

                        return null;
                    }
                    else
                    {
                        var result = await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier, Snapshot.Id, Snapshot.Name, c.PlanId);

                        if (result is PlanChangedResult)
                        {
                            ChangePlan(c);
                        }

                        return result;
                    }
                }));

            default:
                throw new NotSupportedException();
            }
        }