public void AddInvalidPromotionTest1() { try { UserPolicyService.PromoteStorePolicies(promoteName, store1, new[] { StoreManagerPolicy.GetActionFromString("All your bases belong to us") }); Assert.Fail(); } catch (MarketException e) { Assert.AreEqual((int)PromoteStoreStatus.InvalidPromotion, e.Status); Assert.AreEqual(0, userServiceSignUpSession.MarketUser.GetStoreManagerPolicies(store1).Length); DoSignIn(promoteName, promotePassword); Assert.AreEqual(0, userServiceSignInSession.MarketUser.GetStoreManagerPolicies(store1).Length); } }
public void AddInvalidPromotionTest2() { try { UserPolicyService.PromoteStorePolicies(promoteName, store2, new[] { StoreManagerPolicy.StoreAction.StoreOwner, StoreManagerPolicy.StoreAction.ManageProducts, StoreManagerPolicy.GetActionFromString("THE CAKE IS A LIE") }); Assert.Fail(); } catch (MarketException e) { Assert.AreEqual((int)PromoteStoreStatus.InvalidPromotion, e.Status); Assert.AreEqual(0, userServiceSignUpSession.MarketUser.GetStoreManagerPolicies(store1).Length); DoSignIn(promoteName, promotePassword); Assert.AreEqual(0, userServiceSignInSession.MarketUser.GetStoreManagerPolicies(store2).Length); } }
public void RemoveAllPoliciesTest() { StoreManagerPolicy.StoreAction[] givenPermissions1 = { StoreManagerPolicy.StoreAction.ManageProducts, StoreManagerPolicy.StoreAction.PromoteStoreAdmin, StoreManagerPolicy.StoreAction.ViewPurchaseHistory, StoreManagerPolicy.StoreAction.DeclarePurchasePolicy }; StoreManagerPolicy.StoreAction[] givenPermissions2 = new StoreManagerPolicy.StoreAction[0]; StoreManagerPolicy[] expected1 = { new StoreManagerPolicy(store1, StoreManagerPolicy.StoreAction.PromoteStoreAdmin), new StoreManagerPolicy(store1, StoreManagerPolicy.StoreAction.ManageProducts), new StoreManagerPolicy(store1, StoreManagerPolicy.StoreAction.DeclarePurchasePolicy), new StoreManagerPolicy(store1, StoreManagerPolicy.StoreAction.ViewPurchaseHistory) }; StoreManagerPolicy[] expected2 = new StoreManagerPolicy[0]; AddMorePoliciesLater(expected1, expected2, givenPermissions1, givenPermissions2); }
public string[] Promote(string userName, string permissions) { ValidateCanManageStore(); ValidateNotPromotingHimself(userName); List <StoreManagerPolicy.StoreAction> actions = new List <StoreManagerPolicy.StoreAction>(); var permissionsArray = permissions.Split(',').Distinct().ToArray(); foreach (var permission in permissionsArray) { if (permission.Length == 0) { continue; } StoreManagerPolicy.StoreAction action = StoreManagerPolicy.GetActionFromString(permission); if (!CanDoAnything() && !SearchPermission(action)) { throw new UserException(PromoteStoreStatus.PromotionOutOfReach, "Cannot grant permission " + permission + " to others if you don't have it yourself"); } actions.Add(action); } return(PromoteStorePolicies(userName, actions.ToArray())); }