AdminController_ManualChanges_POST_Add_Organisation_Latest_Name_Fails_When_The_New_Name_Exists_In_Another_Org_In_Database_Async()
        {
            // Arrange
            Core.Entities.Organisation organisationToChangeName = OrganisationHelper.GetMockedOrganisation("EmployerReference565658");
            organisationToChangeName.OrganisationName = "Old name";

            Core.Entities.Organisation organisationWithSameNameInDb = OrganisationHelper.GetMockedOrganisation("EmployerReference55441122");
            organisationWithSameNameInDb.OrganisationName = "Another org with this name limited";

            #region setting up database and controller

            User notAdminUser    = UserHelper.GetDatabaseAdmin();
            var  adminController = UiTestHelper.GetController <AdminController>(notAdminUser.UserId, null, null);

            Mock <IDataRepository> configurableDataRepository = AutoFacExtensions.ResolveAsMock <IDataRepository>();

            configurableDataRepository
            .Setup(x => x.Get <User>(It.IsAny <long>()))
            .Returns(notAdminUser);

            configurableDataRepository
            .Setup(x => x.GetAll <Core.Entities.Organisation>())
            .Returns(new[] { organisationToChangeName, organisationWithSameNameInDb }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command    = AddOrganisationsLatestNameCommand,
                Parameters =
                    $"{organisationToChangeName.EmployerReference.ToLower()}=Another org with this name limited" // This name already exists in another org in DB
            };

            #endregion

            // Act
            IActionResult manualChangesResult = await adminController.ManualChanges(manualChangesViewModel);

            // Assert
            Assert.NotNull(manualChangesResult, "Expected a Result");

            var manualChangesViewResult = manualChangesResult as ViewResult;
            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;
            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            Assert.Multiple(
                () => {
                Assert.AreEqual(
                    "SUCCESSFULLY TESTED 'Add organisations latest name': 0 of 1",
                    actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "<span style=\"color:Red\">1: ERROR: 'EMPLOYERREFERENCE565658' Another organisation exists with this company name</span>\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Add organisations latest name", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual(
                    "employerreference565658=Another org with this name limited",
                    actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Beispiel #2
0
        public void CompareController_AddEmployerJS_NoEmployers_ReturnsNotFound()
        {
            // Arrange
            var    org        = OrganisationHelper.GetMockedOrganisation("abc123");
            var    controller = UiTestHelper.GetController <CompareController>();
            string returnUrl  = @"\viewing\search-results";

            controller.SearchViewService.LastSearchResults = new SearchViewModel()
            {
                Employers = null
            };

            var mockedObfuscatorToSetup = AutoFacExtensions.ResolveAsMock <IObfuscator>();

            mockedObfuscatorToSetup
            .Setup(x => x.DeObfuscate(org.EmployerReference))
            .Returns((int)org.OrganisationId);

            // Act
            Assert.Throws <HttpException>(() => controller.AddEmployerJs(org.EmployerReference, returnUrl), "Expected IdentityNotMappedException");
        }
Beispiel #3
0
        public static object[] CreateRegistrations()
        {
            List <User> users = UserHelpers.CreateUsers();

            var organisations = new List <Organisation> {
                OrganisationHelper.GetMockedOrganisation(),
                OrganisationHelper.GetMockedOrganisation(),
                OrganisationHelper.GetMockedOrganisation()
            };

            var registrations = new List <UserOrganisation> {
                LinkUserWithOrganisation(users.Where(u => u.UserId == 23322).FirstOrDefault(), organisations[0]),
                LinkUserWithOrganisation(users.Where(u => u.UserId == 21555).FirstOrDefault(), organisations[0]),
                LinkUserWithOrganisation(users.Where(u => u.UserId == 23322).FirstOrDefault(), organisations[1]),
                LinkUserWithOrganisation(users.Where(u => u.UserId == 24572).FirstOrDefault(), organisations[2])
            };

            return(new List <object> {
                users, organisations, registrations
            }.ToArray());
        }
        private List <Return> GetFourOrgsWithVariousReturns()
        {
            var result = new List <Return>();

            #region Two organisations with returns that have all their information filled correctly

            for (var i = 0; i < 2; i++)
            {
                Organisation organisationInfoCorrect = OrganisationHelper.GetMockedOrganisation();
                Return       returnInfoCorrect       = ReturnHelper.CreateTestReturn(organisationInfoCorrect);
                result.Add(returnInfoCorrect);
            }

            #endregion

            #region Organisation with return that doesn't contain bonus info

            var tempOrg    = new Organisation();
            var tempReturn = new Return();
            do
            {
                tempOrg    = OrganisationHelper.GetMockedOrganisation();
                tempReturn = ReturnHelper.CreateTestReturnWithNoBonus(tempOrg);
            } while (result.Any(x => x.OrganisationId == tempOrg.OrganisationId));

            result.Add(tempReturn);

            #endregion

            #region Organisation with return that has a bonus information completed as 0%

            do
            {
                tempOrg    = OrganisationHelper.GetMockedOrganisation();
                tempReturn = ReturnHelper.CreateBonusTestReturn(
                    tempOrg,
                    0,
                    0,
                    0,
                    0);
            } while (result.Any(x => x.OrganisationId == tempOrg.OrganisationId));

            result.Add(tempReturn);

            #endregion

            #region Organisation with return that has a bonus information filled with negative numbers

            do
            {
                tempOrg    = OrganisationHelper.GetMockedOrganisation();
                tempReturn = ReturnHelper.CreateBonusTestReturn(
                    tempOrg,
                    -15,
                    -34,
                    -56,
                    -78);
            } while (result.Any(x => x.OrganisationId == tempOrg.OrganisationId));

            result.Add(tempReturn);

            #endregion

            return(result);
        }