Beispiel #1
0
        public void user_has_right_plan_wrong_option_value_should_redirect()
        {
            var reqPlanId   = 1;
            var optionName  = "HasThis";
            var optionValue = "Yes";
            var testUser    = new AppUser(new AspNetUser()
            {
                Id                 = Guid.NewGuid().ToString(),
                BillingOn          = DateTime.Now,
                MyShopifyDomain    = "store1.myshopify.com",
                ShopifyChargeId    = 1,
                Email              = "*****@*****.**",
                PlanId             = reqPlanId,
                UserName           = "******",
                ShopifyAccessToken = "thetoken"
            }, false);

            //mock user caching
            var userCache = new Mock <IUserCaching>();

            userCache.Setup(x => x.GetLoggedOnUser(It.IsAny <bool>())).Returns(Task.FromResult(testUser));

            var plan = new PlanAppModel(new Plan()
            {
                Id = reqPlanId
            });
            var def = new PlanDefinitionAppModel(new PlanDefinition()
            {
                OptionName  = optionName,
                OptionValue = "wrong value",
                PlanId      = plan.Id
            });
            var planReader = new Mock <IPlansReader>();

            planReader.Setup(x => x[It.IsAny <int>()]).Returns(plan);
            planReader.Setup(x => x[It.IsAny <int>(), It.IsAny <string>()]).Returns(def);

            //requires plan id 1

            RequiresPlan obj     = new RequiresPlan(userCache.Object, planReader.Object, realSettingsReader, mockLogger.Object, reqPlanId, optionName, optionValue);
            var          authCtx = _GetMockAuthrizationContext();

            obj.OnAuthorization(authCtx);
            userCache.Verify(x => x.GetLoggedOnUser(It.IsAny <bool>()), Times.Exactly(1));
            planReader.VerifyAll();
            Assert.IsType <RedirectToRouteResult>(authCtx.Result);
            var route      = (RedirectToRouteResult)authCtx.Result;
            var controller = route.RouteValues["controller"];
            var action     = route.RouteValues["action"];

            Assert.Equal(realSettingsReader.GetAppDashboardControllerName(), controller);
            Assert.Equal(DASHBOARD_ACTIONS.PlanDoesNotAllow.ToString(), action);
        }
Beispiel #2
0
        public void user_has_right_plan_and_option_should_pass()
        {
            var reqPlanId   = 1;
            var optionName  = "HasThis";
            var optionValue = "Yes";
            var testUser    = new AppUser(new AspNetUser()
            {
                Id                 = Guid.NewGuid().ToString(),
                BillingOn          = DateTime.Now,
                MyShopifyDomain    = "store1.myshopify.com",
                ShopifyChargeId    = 1,
                Email              = "*****@*****.**",
                PlanId             = reqPlanId,
                UserName           = "******",
                ShopifyAccessToken = "thetoken"
            }, false);

            //mock user caching
            var userCache = new Mock <IUserCaching>();

            userCache.Setup(x => x.GetLoggedOnUser(It.IsAny <bool>())).Returns(Task.FromResult(testUser));

            var plan = new PlanAppModel(new Plan()
            {
                Id = reqPlanId
            });
            var def = new PlanDefinitionAppModel(new PlanDefinition()
            {
                OptionName  = optionName,
                OptionValue = optionValue,
                PlanId      = plan.Id
            });
            var planReader = new Mock <IPlansReader>();

            planReader.Setup(x => x[It.IsAny <int>()]).Returns(plan);
            planReader.Setup(x => x[It.IsAny <int>(), It.IsAny <string>()]).Returns(def);

            //requires plan id 1

            RequiresPlan obj     = new RequiresPlan(userCache.Object, planReader.Object, realSettingsReader, mockLogger.Object, reqPlanId, optionName, optionValue);
            var          authCtx = _GetMockAuthrizationContext();

            obj.OnAuthorization(authCtx);
            userCache.Verify(x => x.GetLoggedOnUser(It.IsAny <bool>()), Times.Exactly(1));
            planReader.VerifyAll();
            Assert.Null(authCtx.Result);
        }
        private PlanDefinitionAppModel _GetDefinition(PlanAppModel plan, string optionName)
        {
            PlanDefinitionAppModel ret = null;

            if (plan != null)
            {
                if (plan.Definitions.ContainsKey(optionName))
                {
                    Logger.LogInformation($"Found option '{optionName}' in plan '{plan.Name}'");
                    ret = plan.Definitions[optionName];
                }
                else
                {
                    Logger.LogInformation($"Could not find option '{optionName}' in plan '{plan.Name}'");
                }
            }

            return(ret);
        }