public void TestModifyAdminWhenUserFound1() { #region Arrange //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null)); var roles = new List <Role>(); roles.Add(CreateValidEntities.Role(99)); roles[0].SetIdTo(Role.Codes.DepartmentalAdmin); roles.Add(CreateValidEntities.Role(88)); roles[1].SetIdTo(Role.Codes.Admin); roles.Add(CreateValidEntities.Role(77)); roles[2].SetIdTo(Role.Codes.EmulationUser); new FakeRoles(0, RoleRepository, roles, true); var users = new List <User>(); users.Add(CreateValidEntities.User(3)); users[0].Organizations.Add(CreateValidEntities.Organization(1)); users[0].Organizations.Add(CreateValidEntities.Organization(2)); users[0].Roles.Add(RoleRepository.Queryable.Single(a => a.Id == Role.Codes.EmulationUser)); users[0].SetIdTo("3"); new FakeUsers(0, UserRepository, users, true); var user = CreateValidEntities.User(3); #endregion Arrange #region Act Controller.ModifyAdmin(user) .AssertActionRedirect() .ToAction <AdminController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("FirstName3 LastName3 (3) was edited under the administrator role", Controller.Message); UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything)); var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0]; Assert.IsNotNull(userArgs); Assert.AreEqual("FirstName3 LastName3 (3)", userArgs.FullNameAndId); Assert.AreEqual(2, userArgs.Roles.Count()); Assert.AreEqual(Role.Codes.EmulationUser, userArgs.Roles[0].Id); Assert.AreEqual(Role.Codes.Admin, userArgs.Roles[1].Id); Assert.AreEqual(2, userArgs.Organizations.Count()); Assert.AreEqual("*****@*****.**", userArgs.Email); Assert.IsTrue(userArgs.IsActive); EmailPreferencesRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything)); var epArgs = (EmailPreferences)EmailPreferencesRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything))[0][0]; Assert.IsNotNull(epArgs); Assert.AreEqual("3", epArgs.Id); UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "3")); #endregion Assert }
public void TestModifyAdminWhenUserFound2() { #region Arrange //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null)); var roles = new List <Role>(); roles.Add(CreateValidEntities.Role(99)); roles[0].SetIdTo(Role.Codes.DepartmentalAdmin); roles.Add(CreateValidEntities.Role(88)); roles[1].SetIdTo(Role.Codes.Admin); roles.Add(CreateValidEntities.Role(77)); roles[2].SetIdTo(Role.Codes.EmulationUser); new FakeRoles(0, RoleRepository, roles, true); var users = new List <User>(); users.Add(CreateValidEntities.User(3)); users[0].Organizations.Add(CreateValidEntities.Organization(1)); users[0].Organizations.Add(CreateValidEntities.Organization(2)); users[0].Roles.Add(RoleRepository.Queryable.Single(a => a.Id == Role.Codes.EmulationUser)); users[0].SetIdTo("3"); new FakeUsers(0, UserRepository, users, true); var user = CreateValidEntities.User(3); new FakeEmailPreferences(3, EmailPreferencesRepository); #endregion Arrange #region Act Controller.ModifyAdmin(user) .AssertActionRedirect() .ToAction <AdminController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("FirstName3 LastName3 (3) was edited under the administrator role", Controller.Message); UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything)); EmailPreferencesRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything)); #endregion Assert }
public void TestModifySscAdminWhenUserNotFound() { #region Arrange //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null)); var roles = new List <Role>(); roles.Add(CreateValidEntities.Role(99)); roles[0].SetIdTo(Role.Codes.DepartmentalAdmin); roles.Add(CreateValidEntities.Role(88)); roles[1].SetIdTo(Role.Codes.SscAdmin); roles.Add(CreateValidEntities.Role(77)); roles[2].SetIdTo(Role.Codes.EmulationUser); new FakeRoles(0, RoleRepository, roles, true); new FakeUsers(3, UserRepository); var user = CreateValidEntities.User(4); #endregion Arrange #region Act Controller.ModifySscAdmin(user) .AssertActionRedirect() .ToAction <AdminController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("FirstName4 LastName4 (4) was edited under the SSC administrator role", Controller.Message); UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything)); var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0]; Assert.IsNotNull(userArgs); Assert.AreEqual("FirstName4 LastName4 (4)", userArgs.FullNameAndId); Assert.AreEqual(1, userArgs.Roles.Count()); Assert.AreEqual(Role.Codes.SscAdmin, userArgs.Roles[0].Id); Assert.AreEqual("*****@*****.**", userArgs.Email); Assert.IsTrue(userArgs.IsActive); EmailPreferencesRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything)); var epArgs = (EmailPreferences)EmailPreferencesRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything))[0][0]; Assert.IsNotNull(epArgs); Assert.AreEqual("4", epArgs.Id); #endregion Assert }