public void TestDeletePostRedirectsWhenNoAccess2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 7; string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)).Return(false); #endregion Arrange #region Act Controller.Delete(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ErrorController>(a => a.NotAuthorized()); #endregion Act #region Assert ConditionalApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <ConditionalApproval> .Is.Anything)); Assert.AreEqual("Fake Message", Controller.Message); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.IsNull(args[0]); Assert.AreEqual("OName1", ((Organization)args[1]).Name); #endregion Assert }
public void TestDeletePostWhenValid2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "1"); SetupDateForIndex1(); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 7; const string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)).Return(true); #endregion Arrange #region Act var result = Controller.Delete(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ConditionalApprovalController>(a => a.ByOrg("1")); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual("1", result.RouteValues["id"]); Assert.AreEqual("Conditional Approval removed successfully", Controller.Message); ConditionalApprovalRepository.AssertWasCalled(a => a.Remove(Arg <ConditionalApproval> .Is.Anything)); var args1 = (ConditionalApproval)ConditionalApprovalRepository.GetArgumentsForCallsMadeOn(a => a.Remove(Arg <ConditionalApproval> .Is.Anything))[0][0]; Assert.IsNotNull(args1); Assert.AreEqual(7, args1.Id); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.IsNull(args[0]); Assert.AreEqual("OName1", ((Organization)args[1]).Name); #endregion Assert }
public void TestEditPostRedirectsWhenNoAccess1() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); const string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 1; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ErrorController>(a => a.NotAuthorized()); #endregion Act #region Assert Assert.AreEqual("Fake Message", Controller.Message); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.IsNull(args[0]); Assert.AreEqual("Name1", ((Organization)args[1]).Name); #endregion Assert }
public void TestEditPostRedirectsWhenConditionalApprovalNotFound() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 19; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ErrorController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("Conditional Approval not found", Controller.ErrorMessage); SecurityService.AssertWasNotCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)); #endregion Assert }
public void TestEditPostReturnsViewWhenNotValid() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 1; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; Controller.ModelState.AddModelError("Error", "Fake Error"); #endregion Arrange #region Act var result = Controller.Edit(conditionalApprovalViewModel) .AssertViewRendered() .WithViewData <ConditionalApprovalViewModel>(); #endregion Act #region Assert Controller.ModelState.AssertErrorsAre("Fake Error"); Assert.IsNotNull(result); Assert.AreEqual(1, result.Id); Assert.AreEqual("Que?", result.Question); Assert.AreEqual("Test", result.OrgOrWorkgroupName); Assert.AreEqual("Primy", result.PrimaryUserName); Assert.AreEqual("Seconds", result.SecondaryUserName); SecurityService.AssertWasNotCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)); #endregion Assert }
public void TestEditPostRedirectsAndSaves1() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); const string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)).Return(true); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 1; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act var result = Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ConditionalApprovalController>(a => a.ByWorkgroup(1)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.RouteValues["id"]); Assert.AreEqual("Conditional Approval edited successfully", Controller.Message); ConditionalApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <ConditionalApproval> .Is.Anything)); var conditionalApprovalArgs = (ConditionalApproval)ConditionalApprovalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <ConditionalApproval> .Is.Anything))[0][0]; Assert.IsNotNull(conditionalApprovalArgs); Assert.AreEqual(1, conditionalApprovalArgs.Id); Assert.AreEqual("Que?", conditionalApprovalArgs.Question); Assert.AreEqual("WName1", conditionalApprovalArgs.Workgroup.Name); Assert.AreEqual("FirstName99 LastName99 (99)", conditionalApprovalArgs.PrimaryApprover.FullNameAndId); Assert.IsNull(conditionalApprovalArgs.SecondaryApprover); Assert.IsNull(conditionalApprovalArgs.Organization); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.IsNull(args[0]); Assert.AreEqual("Name1", ((Organization)args[1]).Name); #endregion Assert }
public void TestDeletePostRedirectsToIndexInConditionalApprovalNotFound() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 19; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)).Return(false); #endregion Arrange #region Act Controller.Delete(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction <ErrorController>(a => a.Index()); #endregion Act #region Assert ConditionalApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <ConditionalApproval> .Is.Anything)); Assert.AreEqual("Conditional Approval not found", Controller.ErrorMessage); SecurityService.AssertWasNotCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)); #endregion Assert }
public void TestEditPostReturnsViewWhenNotValid() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(null).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 1; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; Controller.ModelState.AddModelError("Error", "Fake Error"); #endregion Arrange #region Act var result = Controller.Edit(conditionalApprovalViewModel) .AssertViewRendered() .WithViewData<ConditionalApprovalViewModel>(); #endregion Act #region Assert Controller.ModelState.AssertErrorsAre("Fake Error"); Assert.IsNotNull(result); Assert.AreEqual(1, result.Id); Assert.AreEqual("Que?", result.Question); Assert.AreEqual("Test", result.OrgOrWorkgroupName); Assert.AreEqual("Primy", result.PrimaryUserName); Assert.AreEqual("Seconds", result.SecondaryUserName); SecurityService.AssertWasNotCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(null).Dummy)); #endregion Assert }
public void TestEditPostRedirectsWhenNoAccess2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); const string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 7; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction<ErrorController>(a => a.NotAuthorized()); #endregion Act #region Assert Assert.AreEqual("Fake Message", Controller.Message); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.IsNull(args[0]); Assert.AreEqual("OName1", ((Organization)args[1]).Name); #endregion Assert }
public void TestEditPostRedirectsWhenConditionalApprovalNotFound() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(null).Dummy)).Return(false); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 19; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction<ErrorController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("Conditional Approval not found", Controller.ErrorMessage); SecurityService.AssertWasNotCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(null).Dummy)); #endregion Assert }
public void TestEditPostRedirectsAndSaves2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2"); SetupDateForIndex1(); const string message = "Fake Message"; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy)).Return(true); var conditionalApprovalViewModel = new ConditionalApprovalViewModel(); conditionalApprovalViewModel.Id = 7; conditionalApprovalViewModel.OrgOrWorkgroupName = "Test"; conditionalApprovalViewModel.PrimaryUserName = "******"; conditionalApprovalViewModel.Question = "Que?"; conditionalApprovalViewModel.SecondaryUserName = "******"; #endregion Arrange #region Act var result = Controller.Edit(conditionalApprovalViewModel) .AssertActionRedirect() .ToAction<ConditionalApprovalController>(a => a.ByOrg("1")); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual("1", result.RouteValues["id"]); Assert.AreEqual("Conditional Approval edited successfully", Controller.Message); ConditionalApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<ConditionalApproval>.Is.Anything)); var conditionalApprovalArgs = (ConditionalApproval)ConditionalApprovalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg<ConditionalApproval>.Is.Anything))[0][0]; Assert.IsNotNull(conditionalApprovalArgs); Assert.AreEqual(7, conditionalApprovalArgs.Id); Assert.AreEqual("Que?", conditionalApprovalArgs.Question); Assert.IsNull(conditionalApprovalArgs.Workgroup); Assert.AreEqual("FirstName99 LastName99 (99)", conditionalApprovalArgs.PrimaryApprover.FullNameAndId); Assert.AreEqual("FirstName88 LastName88 (88)", conditionalApprovalArgs.SecondaryApprover.FullNameAndId); Assert.AreEqual("OName1", conditionalApprovalArgs.Organization.Name); SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy)); var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg<Workgroup>.Is.Anything, Arg<Organization>.Is.Anything, out Arg<string>.Out(message).Dummy))[0]; Assert.IsNotNull(args); Assert.AreEqual("OName1", ((Organization)args[1]).Name); Assert.IsNull(args[0]); #endregion Assert }