public void TestDeleteGetReturnsView2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "1"); 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); #endregion Arrange #region Act var result = Controller.Delete(7) .AssertViewRendered() .WithViewData <ConditionalApprovalViewModel>(); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(7, result.Id); Assert.AreEqual("Question7", result.Question); Assert.AreEqual("OName1", result.OrgOrWorkgroupName); Assert.AreEqual("FirstName99 LastName99 (99)", result.PrimaryUserName); Assert.AreEqual("FirstName88 LastName88 (88)", result.SecondaryUserName); ConditionalApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <ConditionalApproval> .Is.Anything)); 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 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 TestDeleteGetRedirectsWhenConditionalApprovalNotFound() { #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); #endregion Arrange #region Act Controller.Delete(19) .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 }