Exemplo n.º 1
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
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
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
        }