Esempio n. 1
0
        public void TestAddSubOrganizationsPostRedirectsToSubOrganizationsWhenNoOrgsAdded2()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "3");
            SetupDataForWorkgroupActions1();
            Assert.AreEqual(2, WorkgroupRepository.Queryable.Single(a => a.Id == 1).Organizations.Count()); //Organizations does not contain primary org
            #endregion Arrange

            #region Act
            var result = Controller.AddSubOrganizations(3, new string[0])
                         .AssertActionRedirect()
                         .ToAction <WizardController>(a => a.SubOrganizations(3));
            #endregion Act

            #region Assert

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues["id"]);

            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var workgroupArgs = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(workgroupArgs);
            Assert.AreEqual(2, workgroupArgs.Organizations.Count());
            Assert.AreEqual("Name1", workgroupArgs.Organizations[0].Name);
            Assert.AreEqual("Name3", workgroupArgs.Organizations[1].Name);

            Assert.AreEqual(2, Controller.ViewBag.StepNumber);
            #endregion Assert
        }
Esempio n. 2
0
        public void TestDeleteAddressPostRegdirectsAndSaves3()
        {
            #region Arrange
            SetupDataForAddress();
            #endregion Arrange

            #region Act
            var result = Controller.DeleteAddress(2, 6, new WorkgroupAddress())
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.Addresses(2));
            #endregion Act

            #region Assert
            Assert.AreEqual("Address deleted.", Controller.Message);
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.RouteValues["id"]);
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(3, args.Addresses.Count());
            Assert.IsTrue(args.Addresses[0].IsActive);
            Assert.IsFalse(args.Addresses[1].IsActive);
            Assert.IsFalse(args.Addresses[2].IsActive);
            #endregion Assert
        }
        public void TestAddAddressPostWhenInactiveMatchFound()
        {
            #region Arrange
            SetupDataForAddress();
            var address = CreateValidEntities.WorkgroupAddress(10);
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[0])).Return(0).Repeat.Once();
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[1])).Return(5).Repeat.Once();
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[2])).Return(0).Repeat.Once();
            #endregion Arrange

            #region Act
            var result = Controller.AddAddress(2, address)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.Addresses(2));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.RouteValues["id"]);
            Assert.AreEqual("Address created.", Controller.Message);
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(2, args.Id);
            Assert.AreEqual(3, args.Addresses.Count());
            Assert.AreEqual(true, args.Addresses[1].IsActive);
            Assert.AreEqual("Name5", args.Addresses[1].Name);

            WorkgroupAddressService.AssertWasCalled(a => a.CompareAddress(Arg <WorkgroupAddress> .Is.Anything, Arg <WorkgroupAddress> .Is.Anything), x => x.Repeat.Times(2));
            #endregion Assert
        }
        public void TestDeletePostSetsValueAndSaves()
        {
            #region Arrange
            var workgroups = new List <Workgroup>();
            for (var i = 0; i < 3; i++)
            {
                workgroups.Add(CreateValidEntities.Workgroup(i + 1));
                workgroups[i].IsActive = true;
            }
            new FakeWorkgroups(0, WorkgroupRepository, workgroups);
            var worgroupToDelete = CreateValidEntities.Workgroup(3);
            worgroupToDelete.SetIdTo(3);
            #endregion Arrange

            #region Act
            Controller.Delete(3, worgroupToDelete)
            .AssertActionRedirect()
            .ToAction <WorkgroupController>(a => a.Index(false));
            #endregion Act

            #region Assert
            Assert.AreEqual("Name3 was disabled successfully", Controller.Message);
            WorkgroupRepository.AssertWasNotCalled(a => a.Remove(Arg <Workgroup> .Is.Anything));
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("Name3", args.Name);
            Assert.IsFalse(args.IsActive);
            #endregion Assert
        }
Esempio n. 5
0
        public void TestEditPostReplacesOrganizationsWithSuppliedOnes2()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "2");
            SetupDataForWorkgroupActions1();
            var orgs = new[] { "1", "3" };
            #endregion Arrange

            #region Act
            Controller.Edit(3, WorkgroupRepository.GetNullableById(3), orgs)
            .AssertActionRedirect()
            .ToAction <WorkgroupController>(a => a.Index(false));
            #endregion Act

            #region Assert
            Assert.AreEqual("Name3 was modified successfully", Controller.Message);
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("Name3", args.Name);
            Assert.AreEqual(3, args.Organizations.Count());
            Assert.AreEqual("Name1", args.Organizations[0].Name);
            Assert.AreEqual("Name3", args.Organizations[1].Name);
            Assert.AreEqual("Name3", args.Organizations[2].Name); //Limitation of the test, this doesn't happen when running normally which is correct
            #endregion Assert
        }
Esempio n. 6
0
        public void TestEditAddressPostWhenAddressIsChangedToAnNewAddress()
        {
            #region Arrange
            SetupDataForAddress();
            var address = CreateValidEntities.WorkgroupAddress(4);
            address.Name = "Fake";
            address.SetIdTo(4);
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[0])).Return(0);
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[1])).Return(0);
            WorkgroupAddressService.Expect(a => a.CompareAddress(address, WorkgroupRepository.GetNullableById(2).Addresses[2])).Return(0);
            #endregion Arrange

            #region Act
            var result = Controller.EditAddress(2, 4, address)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.Addresses(2));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.RouteValues["id"]);
            Assert.AreEqual("Address updated.", Controller.Message);
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(4, args.Addresses.Count());
            Assert.AreEqual("Name4", args.Addresses[0].Name);
            Assert.IsFalse(args.Addresses[0].IsActive); //Disabled one we are editing

            Assert.AreEqual("Name5", args.Addresses[1].Name);
            Assert.IsFalse(args.Addresses[1].IsActive);

            Assert.AreEqual("Name6", args.Addresses[2].Name); //Not Touched
            Assert.IsTrue(args.Addresses[2].IsActive);

            Assert.AreEqual("Fake", args.Addresses[3].Name); //New one
            Assert.IsTrue(args.Addresses[3].IsActive);
            #endregion Assert
        }
        public void TestAddAddressPostWhenNoMatchRedirects1()
        {
            #region Arrange
            SetupDataForAddress();
            var address = CreateValidEntities.WorkgroupAddress(10);
            WorkgroupAddressService.Expect(a => a.CompareAddress(Arg <WorkgroupAddress> .Is.Anything, Arg <WorkgroupAddress> .Is.Anything)).Return(0).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.AddAddress(2, address)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.Addresses(2));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.RouteValues["id"]);
            Assert.AreEqual("Address created", Controller.Message);
            WorkgroupRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything));
            var args = (Workgroup)WorkgroupRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Workgroup> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(2, args.Id);
            Assert.AreEqual(4, args.Addresses.Count());
            Assert.AreEqual("Name10", args.Addresses[3].Name);

            WorkgroupAddressService.AssertWasCalled(a => a.CompareAddress(Arg <WorkgroupAddress> .Is.Anything, Arg <WorkgroupAddress> .Is.Anything), x => x.Repeat.Times(3));
            var compareArgs = WorkgroupAddressService.GetArgumentsForCallsMadeOn(a => a.CompareAddress(Arg <WorkgroupAddress> .Is.Anything, Arg <WorkgroupAddress> .Is.Anything));
            Assert.IsNotNull(compareArgs);
            Assert.AreEqual(3, compareArgs.Count());
            Assert.AreEqual("Name4", ((WorkgroupAddress)compareArgs[0][1]).Name);
            Assert.AreEqual("Name5", ((WorkgroupAddress)compareArgs[1][1]).Name);
            Assert.AreEqual("Name6", ((WorkgroupAddress)compareArgs[2][1]).Name);
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual("Name10", ((WorkgroupAddress)compareArgs[i][0]).Name);
            }
            #endregion Assert
        }