public void TestCreateWorkgroupPostReturnsViewWhenNotValid2() { #region Arrange Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "3"); SetupDataForWorkgroupActions1(); var workgroup = CreateValidEntities.Workgroup(1); workgroup.PrimaryOrganization = OrganizationRepository.Queryable.Single(a => a.Id == "1"); workgroup.Name = null; SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)).Return(false); new FakeOrganizationDescendants(3, OrganizationDescendantRepository); #endregion Arrange #region Act var result = Controller.CreateWorkgroup(workgroup) .AssertViewRendered() .WithViewData <WorkgroupModifyModel>(); #endregion Act #region Assert Controller.ModelState.AssertErrorsAre("You do not have access to the selected organization"); Assert.IsNotNull(result); Assert.AreEqual(3, result.Organizations.Count()); Assert.AreEqual("Name7 (7)", result.Organizations[0].ToString()); Assert.AreEqual("Name8 (8)", result.Organizations[1].ToString()); Assert.AreEqual("Name9 (9)", result.Organizations[2].ToString()); Assert.IsNotNull(result.Workgroup); Assert.AreEqual(1, Controller.ViewBag.StepNumber); WorkgroupService.AssertWasNotCalled(a => a.CreateWorkgroup(Arg <Workgroup> .Is.Anything, Arg <string[]> .Is.Anything)); #endregion Assert }
public void TestProcessWorkGroupReturnsJsonNetResult2() { #region Arrange var workgroups = new List <Workgroup>(); for (int i = 0; i < 5; i++) { workgroups.Add(CreateValidEntities.Workgroup(i + 1)); workgroups[i].IsActive = true; workgroups[i].Administrative = true; } workgroups[1].Administrative = false; workgroups[2].IsActive = false; workgroups[3].Administrative = false; workgroups[3].IsActive = false; new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups); #endregion Arrange #region Act var result = Controller.ProcessWorkGroup(6) .AssertResultIs <JsonNetResult>(); #endregion Act #region Assert dynamic data = JObject.FromObject(result.Data); Assert.IsFalse(data.success.Value); Assert.AreEqual("Sequence contains no matching element", data.message.Value); WorkgroupService.AssertWasNotCalled(a => a.AddRelatedAdminUsers(Arg <Workgroup> .Is.Anything)); #endregion Assert }
public void TestGetChildWorkgroupIdsReturnsJsonNetResult3() { #region Arrange var workgroups = new List <Workgroup>(); for (int i = 0; i < 5; i++) { workgroups.Add(CreateValidEntities.Workgroup(i + 1)); workgroups[i].IsActive = true; workgroups[i].Administrative = true; } workgroups[1].Administrative = false; workgroups[2].IsActive = false; workgroups[3].Administrative = false; workgroups[3].IsActive = false; new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups); #endregion Arrange #region Act var result = Controller.GetChildWorkgroupIds(3) .AssertResultIs <JsonNetResult>(); #endregion Act #region Assert dynamic data = JObject.FromObject(result.Data); Assert.IsFalse(data.success.Value); Assert.AreEqual("Precondition failed.", data.message.Value); WorkgroupService.AssertWasNotCalled(a => a.GetChildWorkgroups(Arg <int> .Is.Anything)); #endregion Assert }
public void TestProcessWorkGroupReturnsJsonNetResult1() { #region Arrange //Nothing because it catches exceptions #endregion Arrange #region Act var result = Controller.ProcessWorkGroup(99) .AssertResultIs <JsonNetResult>(); #endregion Act #region Assert dynamic data = JObject.FromObject(result.Data); Assert.IsFalse(data.success.Value); Assert.AreEqual("Value cannot be null.\r\nParameter name: source", data.message.Value); WorkgroupService.AssertWasNotCalled(a => a.AddRelatedAdminUsers(Arg <Workgroup> .Is.Anything)); #endregion Assert }
public void TestRemoveExtraChildPermissions1() { #region Arrange var workgroups = new List <Workgroup>(); for (int i = 0; i < 3; i++) { workgroups.Add(CreateValidEntities.Workgroup(i + 1)); workgroups[i].Administrative = true; //no child workgroups } new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups); #endregion Arrange #region Act Controller.RemoveExtraChildPermissions() .AssertActionRedirect() .ToAction <AdminController>(a => a.ValidateChildWorkgroups()); #endregion Act #region Assert WorkgroupService.AssertWasNotCalled(a => a.GetParentWorkgroups(Arg <int> .Is.Anything)); RepositoryFactory.WorkgroupPermissionRepository.AssertWasNotCalled(a => a.Remove(Arg <WorkgroupPermission> .Is.Anything)); #endregion Assert }
public void TestValidateChildWorkgroupsReturnsView1() { #region Arrange var workgroups = new List <Workgroup>(); for (int i = 0; i < 3; i++) { workgroups.Add(CreateValidEntities.Workgroup(i + 1)); workgroups[i].Administrative = true; //no child workgroups } new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups); #endregion Arrange #region Act var result = Controller.ValidateChildWorkgroups() .AssertViewRendered() .WithViewData <List <ValidateChildWorkgroupsViewModel> >(); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); WorkgroupService.AssertWasNotCalled(a => a.GetParentWorkgroups(Arg <int> .Is.Anything)); #endregion Assert }