private Task <JsonResult> InvokeDeleteMember( OrganizationsController controller, Organization account, string memberName = defaultMemberName, EntityException exception = null) { // Arrange controller.SetCurrentUser(GetCurrentUser(controller)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username)) .Returns(account as User); var setup = userService.Setup(u => u.DeleteMemberAsync(It.IsAny <Organization>(), memberName)); if (exception != null) { setup.Throws(exception); } else { setup.Returns(Task.CompletedTask).Verifiable(); } // Act return(controller.DeleteMember(account.Username, memberName)); }
private Task <JsonResult> InvokeUpdateMember( OrganizationsController controller, Organization account, string memberName = defaultMemberName, bool isAdmin = false, EntityException exception = null) { // Arrange controller.SetCurrentUser(GetCurrentUser(controller)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username)) .Returns(account as User); var setup = userService.Setup(u => u.UpdateMemberAsync(It.IsAny <Organization>(), memberName, isAdmin)); if (exception != null) { setup.Throws(exception); } else { var membership = new Membership { Organization = account, Member = new User(memberName), IsAdmin = isAdmin }; setup.Returns(Task.FromResult(membership)).Verifiable(); } // Act return(controller.UpdateMember(account.Username, memberName, isAdmin)); }
private Task <JsonResult> InvokeCancelMemberRequestMember( OrganizationsController controller, Organization account, string memberName = defaultMemberName, EntityException exception = null) { // Arrange controller.SetCurrentUser(GetCurrentUser(controller)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username)) .Returns(account as User); var setup = userService.Setup(u => u.CancelMembershipRequestAsync(account, memberName)); if (exception != null) { setup.Throws(exception); } else { setup.Returns(Task.FromResult(new User(memberName))).Verifiable(); } // Act return(controller.CancelMemberRequest(account.Username, memberName)); }
private Task <ActionResult> InvokeRejectMember( OrganizationsController controller, Organization account, bool isAdmin, string confirmationToken = defaultConfirmationToken, EntityException exception = null) { // Arrange controller.SetCurrentUser(GetCurrentUser(controller)); var currentUser = controller.GetCurrentUser(); var userService = GetMock <IUserService>(); if (account != null) { userService.Setup(u => u.FindByUsername(account.Username)) .Returns(account as User); } var setup = userService.Setup(u => u.RejectMembershipRequestAsync(It.IsAny <Organization>(), currentUser.Username, confirmationToken)); if (exception != null) { setup.Throws(exception); } else { var membership = new Membership { Organization = account, Member = currentUser, IsAdmin = isAdmin, }; setup.Returns(Task.CompletedTask).Verifiable(); } // Act return(controller.RejectMemberRequest(account?.Username, confirmationToken)); }
protected override User GetCurrentUser(OrganizationsController controller) { return(controller.GetCurrentUser() ?? Fakes.OrganizationAdmin); }
protected override ActionResult InvokeAccount(OrganizationsController controller) { var accountName = GetAccount(controller).Username; return(controller.ManageOrganization(accountName)); }