コード例 #1
0
        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
        }
コード例 #2
0
        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
        }