示例#1
0
        public static void CanChangePlan(ChangePlan command, AppPlan?plan, IAppPlansProvider appPlans)
        {
            Guard.NotNull(command);

            Validate.It(() => "Cannot change plan.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.PlanId))
                {
                    e(Not.Defined("Plan id"), nameof(command.PlanId));
                    return;
                }

                if (appPlans.GetPlan(command.PlanId) == null)
                {
                    e("A plan with this id does not exist.", nameof(command.PlanId));
                }

                if (!string.IsNullOrWhiteSpace(command.PlanId) && plan != null && !plan.Owner.Equals(command.Actor))
                {
                    e("Plan can only changed from the user who configured the plan initially.");
                }

                if (string.Equals(command.PlanId, plan?.PlanId, StringComparison.OrdinalIgnoreCase))
                {
                    e("App has already this plan.");
                }
            });
        }
示例#2
0
        private static IAppEntity App(AppPlan?plan)
        {
            var app = A.Fake <IAppEntity>();

            A.CallTo(() => app.Plan)
            .Returns(plan);

            return(app);
        }
示例#3
0
        public void CanChangePlan_should_throw_exception_if_plan_not_found()
        {
            var command = new ChangePlan {
                PlanId = "notfound", Actor = new RefToken("user", "me")
            };

            AppPlan?plan = null;

            ValidationAssert.Throws(() => GuardApp.CanChangePlan(command, plan, appPlans),
                                    new ValidationError("A plan with this id does not exist.", "PlanId"));
        }
示例#4
0
        public void CanChangePlan_should_throw_exception_if_plan_id_is_null()
        {
            var command = new ChangePlan {
                Actor = new RefToken("user", "me")
            };

            AppPlan?plan = null;

            ValidationAssert.Throws(() => GuardApp.CanChangePlan(command, plan, appPlans),
                                    new ValidationError("Plan id is required.", "PlanId"));
        }
示例#5
0
        public static void CanChangePlan(ChangePlan command, AppPlan?plan, IAppPlansProvider appPlans)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                if (string.IsNullOrWhiteSpace(command.PlanId))
                {
                    e(Not.Defined(nameof(command.PlanId)), nameof(command.PlanId));
                    return;
                }

                if (appPlans.GetPlan(command.PlanId) == null)
                {
                    e(T.Get("apps.plans.notFound"), nameof(command.PlanId));
                }

                if (!string.IsNullOrWhiteSpace(command.PlanId) && plan != null && !plan.Owner.Equals(command.Actor))
                {
                    e(T.Get("apps.plans.notPlanOwner"));
                }
            });
        }
示例#6
0
            private bool UpdatePlan(AppPlan?plan)
            {
                Plan = plan;

                return(true);
            }