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."); } }); }
private static IAppEntity App(AppPlan?plan) { var app = A.Fake <IAppEntity>(); A.CallTo(() => app.Plan) .Returns(plan); return(app); }
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")); }
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")); }
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")); } }); }
private bool UpdatePlan(AppPlan?plan) { Plan = plan; return(true); }