Пример #1
0
        public void TestEditGetRedirectWhenNotAuthorized()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            customFields.Add(CreateValidEntities.CustomField(1));
            customFields[0].Organization = CreateValidEntities.Organization(9);

            new FakeCustomFields(0, CustomFieldRepository, customFields);
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                           Arg <Organization> .Is.Anything,
                                                                           out Arg <string> .Out("Fail Message").Dummy)).Return(false);
            #endregion Arrange

            #region Act
            Controller.Edit(1)
            .AssertActionRedirect()
            .ToAction <ErrorController>(a => a.NotAuthorized());
            #endregion Act

            #region Assert
            Assert.AreEqual("Fail Message", Controller.Message);
            SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                    Arg <Organization> .Is.Anything,
                                                                                    out Arg <string> .Out("Fail Message").Dummy));
            var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                                          Arg <Organization> .Is.Anything,
                                                                                                          out Arg <string> .Out("Fail Message").Dummy))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual("Name9", ((Organization)args[1]).Name);
            #endregion Assert
        }
Пример #2
0
        public void TestCreatePostRedirectsWhenValid()
        {
            #region Arrange
            new FakeOrganizations(3, OrganazationRepository);
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                           Arg <Organization> .Is.Anything,
                                                                           out Arg <string> .Out(null).Dummy)).Return(true);
            var customField = CreateValidEntities.CustomField(1);
            #endregion Arrange

            #region Act
            var result = Controller.Create("2", customField)
                         .AssertActionRedirect()
                         .ToAction <CustomFieldController>(a => a.Index("2"));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("2", result.RouteValues["id"]);
            Assert.AreEqual("CustomField Created Successfully", Controller.Message);
            SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                    Arg <Organization> .Is.Anything,
                                                                                    out Arg <string> .Out("Fail Message").Dummy));

            CustomFieldRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything));
            var args = (CustomField)CustomFieldRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("Name1", args.Name);
            #endregion Assert
        }
Пример #3
0
        /// <summary>
        /// Gets the valid entity of type T
        /// </summary>
        /// <param name="counter">The counter.</param>
        /// <returns>A valid entity of type T</returns>
        protected override CustomField GetValid(int?counter)
        {
            var rtValue = CreateValidEntities.CustomField(counter);

            rtValue.Organization = OrganizationRepository.Queryable.First();

            return(rtValue);
        }
Пример #4
0
        public void TestEditPostRedirectsWhenValid()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            customFields.Add(CreateValidEntities.CustomField(1));
            customFields[0].Organization = CreateValidEntities.Organization(9);
            customFields[0].Organization.SetIdTo("9");
            customFields[0].IsActive = true;
            new FakeCustomFields(0, CustomFieldRepository, customFields);
            var customField = CreateValidEntities.CustomField(8);
            customField.Organization = null;

            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                           Arg <Organization> .Is.Anything,
                                                                           out Arg <string> .Out(null).Dummy)).Return(true);
            #endregion Arrange

            #region Act
            var result = Controller.Edit(1, customField)
                         .AssertActionRedirect()
                         .ToAction <CustomFieldController>(a => a.Index("9"));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("9", result.RouteValues["id"]);
            Assert.AreEqual("CustomField Edited Successfully", Controller.Message);
            SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                    Arg <Organization> .Is.Anything,
                                                                                    out Arg <string> .Out("Fail Message").Dummy));
            var ssargs = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                                            Arg <Organization> .Is.Anything,
                                                                                                            out Arg <string> .Out(null).Dummy))[0];
            Assert.IsNull(ssargs[0]);
            Assert.AreEqual("Name9", ((Organization)ssargs[1]).Name);

            CustomFieldRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything), x => x.Repeat.Times(2));
            var args = CustomFieldRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything));
            Assert.AreEqual(2, args.Count());
            Assert.AreEqual("Name1", ((CustomField)args[0][0]).Name);
            Assert.AreEqual(false, ((CustomField)args[0][0]).IsActive);
            Assert.AreEqual("Name8", ((CustomField)args[1][0]).Name);
            Assert.AreEqual(true, ((CustomField)args[1][0]).IsActive);
            Assert.AreEqual("Name9", ((CustomField)args[1][0]).Organization.Name);
            #endregion Assert
        }
Пример #5
0
        public void TestUpdateOrderReturnsTrueWhenNotExceptions2()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            var org          = CreateValidEntities.Organization(9);
            org.SetIdTo("9");
            for (int i = 0; i < 5; i++)
            {
                customFields.Add(CreateValidEntities.CustomField(i + 1));
                customFields[i].Organization = org;
                customFields[i].Rank         = i + 1;
            }

            customFields[4].Rank         = 1;
            customFields[0].Organization = CreateValidEntities.Organization(8);
            customFields[0].Organization.SetIdTo("8");
            new FakeCustomFields(0, CustomFieldRepository, customFields);
            var idsToReorder = new List <int>()
            {
                1, 4, 3, 2, 5, 99
            };
            #endregion Arrange

            #region Act
            var result = Controller.UpdateOrder("9", idsToReorder)
                         .AssertResultIs <JsonNetResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("true", result.JsonResultString);
            CustomFieldRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything), x => x.Repeat.Times(4));
            var args = CustomFieldRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything));
            Assert.IsNotNull(args);
            Assert.AreEqual(4, ((CustomField)args[0][0]).Id);
            Assert.AreEqual(1, ((CustomField)args[0][0]).Rank);
            Assert.AreEqual(3, ((CustomField)args[1][0]).Id);
            Assert.AreEqual(2, ((CustomField)args[1][0]).Rank);
            Assert.AreEqual(2, ((CustomField)args[2][0]).Id);
            Assert.AreEqual(3, ((CustomField)args[2][0]).Rank);
            Assert.AreEqual(5, ((CustomField)args[3][0]).Id);
            Assert.AreEqual(4, ((CustomField)args[3][0]).Rank);
            #endregion Assert
        }
Пример #6
0
        public void TestEditPostReturnsViewWhenInvalid()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            customFields.Add(CreateValidEntities.CustomField(1));
            customFields[0].Organization = CreateValidEntities.Organization(9);

            new FakeCustomFields(0, CustomFieldRepository, customFields);
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                           Arg <Organization> .Is.Anything,
                                                                           out Arg <string> .Out(null).Dummy)).Return(true);
            var customField = CreateValidEntities.CustomField(9);
            customField.Name = null;
            #endregion Arrange

            #region Act
            var result = Controller.Edit(1, customField)
                         .AssertViewRendered()
                         .WithViewData <CustomFieldViewModel>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Name9", result.Organization.Name);
            Assert.AreEqual("Name9", result.CustomField.Organization.Name);
            Assert.AreEqual(null, result.CustomField.Name);
            Assert.IsTrue(result.CustomField.IsActive);
            Assert.AreEqual(0, result.CustomField.Rank);
            Assert.IsFalse(result.CustomField.IsRequired);
            SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                    Arg <Organization> .Is.Anything,
                                                                                    out Arg <string> .Out("Fail Message").Dummy));
            var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                                          Arg <Organization> .Is.Anything,
                                                                                                          out Arg <string> .Out(null).Dummy))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual("Name9", ((Organization)args[1]).Name);
            Controller.ModelState.AssertErrorsAre("The Name field is required.");
            CustomFieldRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything));
            #endregion Assert
        }
Пример #7
0
        public void TestUpdateOrderReturnsFalseWhenException()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            var org          = CreateValidEntities.Organization(9);
            org.SetIdTo("9");
            for (int i = 0; i < 5; i++)
            {
                customFields.Add(CreateValidEntities.CustomField(i + 1));
                customFields[i].Organization = org;
                customFields[i].Rank         = i + 1;
            }

            customFields[4].Rank         = 1;
            customFields[0].Organization = CreateValidEntities.Organization(8);
            customFields[0].Organization.SetIdTo("8");
            new FakeCustomFields(0, CustomFieldRepository, customFields);
            var idsToReorder = new List <int>()
            {
                1, 4, 3, 2, 5, 99
            };

            CustomFieldRepository.Expect(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything))
            .Throw(new ApplicationException("Fake Exception"));

            #endregion Arrange

            #region Act
            var result = Controller.UpdateOrder("9", idsToReorder)
                         .AssertResultIs <JsonNetResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("false", result.JsonResultString);
            CustomFieldRepository.AssertWasCalled(a => a.GetNullableById(Arg <int> .Is.Anything), x => x.Repeat.Times(2));
            #endregion Assert
        }
Пример #8
0
        public void TestDeleteGetReturnsView()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            customFields.Add(CreateValidEntities.CustomField(1));
            customFields[0].Organization = CreateValidEntities.Organization(9);

            new FakeCustomFields(0, CustomFieldRepository, customFields);
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                           Arg <Organization> .Is.Anything,
                                                                           out Arg <string> .Out(null).Dummy)).Return(true);
            #endregion Arrange

            #region Act
            var result = Controller.Delete(1)
                         .AssertViewRendered()
                         .WithViewData <CustomField>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Name9", result.Organization.Name);
            Assert.AreEqual("Name1", result.Name);
            Assert.IsTrue(result.IsActive);
            Assert.AreEqual(0, result.Rank);
            Assert.IsFalse(result.IsRequired);
            SecurityService.AssertWasCalled(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                    Arg <Organization> .Is.Anything,
                                                                                    out Arg <string> .Out("Fail Message").Dummy));
            var args = SecurityService.GetArgumentsForCallsMadeOn(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything,
                                                                                                          Arg <Organization> .Is.Anything,
                                                                                                          out Arg <string> .Out(null).Dummy))[0];
            Assert.IsNull(args[0]);
            Assert.AreEqual("Name9", ((Organization)args[1]).Name);
            #endregion Assert
        }