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);
            });
        }
Esempio n. 2
0
        public void BeforeEach()
        {
            MockOrganisations = new[] {
                new Core.Entities.Organisation {
                    OrganisationId   = 123,
                    OrganisationName = "Org123",
                    LatestAddress    = new OrganisationAddress(),
                    SectorType       = SectorTypes.Private
                },
                new Core.Entities.Organisation {
                    OrganisationId   = 456,
                    OrganisationName = "Org456",
                    LatestAddress    = new OrganisationAddress(),
                    SectorType       = SectorTypes.Private
                }
            };

            MockUsers = new[] {
                CreateUser(1, "*****@*****.**"),
                CreateUser(2, "*****@*****.**"),
                CreateUser(3, "*****@*****.**"),
                CreateUser(4, "*****@*****.**"),
                CreateUser(5, "*****@*****.**")
            };

            Core.Entities.Organisation org123 = Array.Find(MockOrganisations, x => x.OrganisationId == 123);
            Core.Entities.Organisation org456 = Array.Find(MockOrganisations, x => x.OrganisationId == 456);

            MockUserOrganisations = new[] {
                CreateUserOrganisation(org123, 1, VirtualDateTime.Now),
                CreateUserOrganisation(org123, 2, VirtualDateTime.Now),
                CreateUserOrganisation(org123, 3, null),
                CreateUserOrganisation(org456, 4, VirtualDateTime.Now)
            };
        }
Esempio n. 3
0
        public async Task AdminUnconfirmedPinsController_POST_When_PIN_has_expired_create_new_PIN_and_send_email()
        {
            // Arrange

            // This PIN format is intentionally different for testing purposes to make sure
            // it doesn't clash with the new PIN that is generated
            var expiredPIN = "1111";

            var organisationId = 100;

            Core.Entities.Organisation organisation = createOrganisation(organisationId, "Company1", 12345678);
            User             user             = CreateUser(1, "*****@*****.**");
            UserOrganisation userOrganisation = CreateUserOrganisation(organisation, user.UserId, VirtualDateTime.Now);

            userOrganisation.PIN         = expiredPIN;
            userOrganisation.PINSentDate = VirtualDateTime.Now.AddYears(-1);

            User govEqualitiesOfficeUser = UserHelper.GetGovEqualitiesOfficeUser();

            govEqualitiesOfficeUser.EmailVerifiedDate = VirtualDateTime.Now;

            var routeData = new RouteData();

            routeData.Values.Add("Action", "SendPin");
            routeData.Values.Add("Controller", "AdminUnconfirmedPinsController");

            var controller = UiTestHelper.GetController <AdminUnconfirmedPinsController>(
                govEqualitiesOfficeUser.UserId,
                routeData,
                organisation,
                user,
                userOrganisation,
                govEqualitiesOfficeUser);

            var mockNotifyEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));

            // Act
            await controller.SendPin(user.UserId, organisationId);

            // Assert
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(user.EmailAddress))),
                Times.Once(),
                "Expected the user's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.SendPinEmail))),
                Times.Once,
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.SendPinEmail}");

            // Check that a new PIN has been created
            Assert.That(userOrganisation.PIN, Is.Not.EqualTo(expiredPIN));
            Assert.NotNull(userOrganisation.PIN);

            // Check that the PINSentDate has been updated
            Assert.That(userOrganisation.PINSentDate.Value.Date, Is.EqualTo(VirtualDateTime.Now.Date));
        }
        public async Task RegistrationController_VerifyEmail_GET_Success()
        {
            //ARRANGE:
            //1.Arrange the test setup variables
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = null
            };

            var organisation = new Core.Entities.Organisation {
                OrganisationId = 1
            };
            var userOrganisation = new UserOrganisation {
                OrganisationId   = organisation.OrganisationId,
                Organisation     = organisation,
                UserId           = 1,
                PINConfirmedDate = VirtualDateTime.Now,
                PIN = "0"
            };

            //Set user email address verified code and expired sent date
            var routeData = new RouteData();

            routeData.Values.Add("Action", "VerifyEmail");
            routeData.Values.Add("Controller", "Registration");

            //ARRANGE:
            //1.Arrange the test setup variables
            var model = new VerifyViewModel();

            model.EmailAddress = "*****@*****.**";
            model.Resend       = false;

            //Set model as if email

            // model.Sent = true;
            model.UserId = 1;

            // model.WrongCode = false;

            //var controller = UiTestHelper.GetController<RegistrationController>();
            var controller = UiTestHelper.GetController <RegistrationController>(1, routeData, user /*, userOrganisation*/);

            controller.Bind(model);

            //ACT:
            //2.Run and get the result of the test

            var result = await controller.VerifyEmail(model) as ViewResult;

            //ASSERT:
            Assert.NotNull(result, "Expected ViewResult");
            Assert.That(result.GetType() == typeof(ViewResult), "Incorrect resultType returned");
            Assert.That(result.ViewName == "VerifyEmail", "Incorrect view returned,Verification is incomplete");
            Assert.That(
                result.Model != null && result.Model.GetType() == typeof(VerifyViewModel),
                "Expected VerifyViewModel or Incorrect resultType returned");
            Assert.That(result.ViewData.ModelState.IsValid, "Model is Invalid");
        }
        public async Task AdminController_ManualChanges_POST_Fix_Database_Error_Missing_Latest_Return_Works_When_Run_In_Test_Mode_Async()
        {
            // Arrange
            User notAdminUser    = UserHelper.GetDatabaseAdmin();
            var  adminController = UiTestHelper.GetController <AdminController>(notAdminUser.UserId, null, null);

            #region Set up organisation missing the latest return link so it's picked up by the test

            Core.Entities.Organisation organisation_MissingLatestReturn     = OrganisationHelper.GetPrivateOrganisation("EmployerReference985");
            UserOrganisation           userOrganisation_MissingLatestReturn =
                UserOrganisationHelper.LinkUserWithOrganisation(notAdminUser, organisation_MissingLatestReturn);
            Return return_MissingLatestReturn = ReturnHelper.GetSubmittedReturnForOrganisationAndYear(
                userOrganisation_MissingLatestReturn,
                VirtualDateTime.Now.AddYears(-1).Year);
            organisation_MissingLatestReturn.Returns.Add(return_MissingLatestReturn); // latest return indeed exists for this organisation
            organisation_MissingLatestReturn.LatestRegistration = userOrganisation_MissingLatestReturn;
            organisation_MissingLatestReturn.LatestReturn       = null;               // missing latest return -link-

            #endregion

            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[] { organisation_MissingLatestReturn }.AsQueryable());

            var manualChangesViewModel = new ManualChangesViewModel {
                Command = FixDatabaseErrorsCommand
            };

            // 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 'Fix database errors': 1 items", actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "No organisations missing a latest registration\r\n001: Organisation 'EmployerReference985:Org123' missing a latest return will be fixed\r\nNo organisations missing a latest scope\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Fix database errors", actualManualChangesViewModel.LastTestedCommand);
                Assert.IsNull(actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
        AdminController_ManualChanges_POST_Fix_Database_Error_Missing_Latest_Registration_Works_When_Run_In_Live_Mode_Async()
        {
            // Arrange
            User notAdminUser    = UserHelper.GetDatabaseAdmin();
            var  adminController = UiTestHelper.GetController <AdminController>(notAdminUser.UserId, null, null);

            #region Set up organisation missing the latest registration link so it's picked up by the test

            Core.Entities.Organisation organisationMissingLatestRegistration = OrganisationHelper.GetPrivateOrganisation("EmployerReference96585");
            UserOrganisationHelper.LinkUserWithOrganisation(
                notAdminUser,
                organisationMissingLatestRegistration);                      // user registered link indeed exists for this organisation
            organisationMissingLatestRegistration.LatestRegistration = null; // missing latest registration -link-

            #endregion

            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[] { organisationMissingLatestRegistration }.AsQueryable());

            var manualChangesViewModel = new ManualChangesViewModel {
                Command = FixDatabaseErrorsCommand
            };

            /* live */
            manualChangesViewModel.LastTestedCommand = manualChangesViewModel.Command;
            manualChangesViewModel.LastTestedInput   = null;

            // 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 EXECUTED 'Fix database errors': 1 items", actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "001: Organisation 'EmployerReference96585:Org123' missing a latest registration was successfully fixed\r\nNo organisations missing a latest return\r\nNo organisations missing a latest scope\r\n",
                    actualManualChangesViewModel.Results);
                Assert.IsNull(actualManualChangesViewModel.LastTestedCommand);
                Assert.IsNull(actualManualChangesViewModel.LastTestedInput);
                Assert.False(actualManualChangesViewModel.Tested, "Must be tested=false as this case is running in LIVE mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
        public async Task AdminController_ManualChanges_POST_Add_Organisation_Latest_Name_Fails_When_The_New_Name_Was_Already_Set_Async()
        {
            // Arrange
            Core.Entities.Organisation organisationToChangeName = OrganisationHelper.GetPrivateOrganisation("EmployerReference373737");
            organisationToChangeName.OrganisationName = "New 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 }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command    = AddOrganisationsLatestNameCommand,
                Parameters =
                    $"{organisationToChangeName.EmployerReference.ToLower()}={organisationToChangeName.OrganisationName}" // We're calling change name, but in reality we're setting the same one
            };

            #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': 1 of 1",
                    actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "<span style=\"color:Orange\">1: WARNING: 'EMPLOYERREFERENCE373737' 'New name limited' already set to 'New name limited'</span>\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Add organisations latest name", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual("employerreference373737=New name limited", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
        public async Task AdminController_ManualChanges_POST_Add_Organisation_Latest_Name_Works_When_Run_In_Live_Mode_Async()
        {
            // Arrange
            Core.Entities.Organisation organisationToChangeName = OrganisationHelper.GetPrivateOrganisation("EmployerReference3335");

            #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 }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command    = AddOrganisationsLatestNameCommand,
                Parameters = $"{organisationToChangeName.EmployerReference.ToLower()}=New name ltd"
            };

            #endregion

            /* live */
            manualChangesViewModel.LastTestedCommand = manualChangesViewModel.Command;
            manualChangesViewModel.LastTestedInput   = manualChangesViewModel.Parameters;

            // 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 EXECUTED 'Add organisations latest name': 1 of 1",
                    actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual("1: EMPLOYERREFERENCE3335: 'Org123' set to 'New name ltd'\r\n", actualManualChangesViewModel.Results);
                Assert.IsNull(actualManualChangesViewModel.LastTestedCommand);
                Assert.IsNull(actualManualChangesViewModel.LastTestedInput);
                Assert.False(actualManualChangesViewModel.Tested, "Must be tested=false as this case is running in LIVE mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Esempio n. 9
0
        public async Task AdminUnconfirmedPinsController_POST_When_PIN_is_still_valid_send_email()
        {
            // Arrange

            var organisationId = 100;
            var pin            = "6A519E7";

            Core.Entities.Organisation organisation = createOrganisation(organisationId, "Company1", 12345678);
            User             user             = CreateUser(1, "*****@*****.**");
            UserOrganisation userOrganisation = CreateUserOrganisation(organisation, user.UserId, VirtualDateTime.Now);

            userOrganisation.PIN         = pin;
            userOrganisation.PINSentDate = VirtualDateTime.Now.AddDays(-1);

            User govEqualitiesOfficeUser = UserHelper.GetGovEqualitiesOfficeUser();

            govEqualitiesOfficeUser.EmailVerifiedDate = VirtualDateTime.Now;

            var routeData = new RouteData();

            routeData.Values.Add("Action", "SendPin");
            routeData.Values.Add("Controller", "AdminUnconfirmedPinsController");

            var controller = UiTestHelper.GetController <AdminUnconfirmedPinsController>(
                govEqualitiesOfficeUser.UserId,
                routeData,
                organisation,
                user,
                userOrganisation,
                govEqualitiesOfficeUser);

            var mockNotifyEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));

            // Act
            await controller.SendPin(user.UserId, organisationId);

            // Assert
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(user.EmailAddress))),
                Times.Once(),
                "Expected the user's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.SendPinEmail))),
                Times.Once,
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.SendPinEmail}");

            // Check that the same PIN has been used
            Assert.That(userOrganisation.PIN, Is.EqualTo(pin));

            // Check that the PINSentDate has been updated
            Assert.That(userOrganisation.PINSentDate.Value.Date, Is.EqualTo(VirtualDateTime.Now.Date));
        }
        AdminController_ManualChanges_POST_Add_Organisation_Latest_Name_Fails_When_Employer_Reference_Is_Duplicated_Async()
        {
            // Arrange
            Core.Entities.Organisation organisationToChangeName = OrganisationHelper.GetPrivateOrganisation("EmployerReference0111");

            #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 }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command    = AddOrganisationsLatestNameCommand,
                Parameters = $"{organisationToChangeName.EmployerReference.ToLower()}=New name ltd"
                             + Environment.NewLine
                             + $"{organisationToChangeName.EmployerReference.ToLower()}=New name ltd"
            };

            #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.AreEqual("SUCCESSFULLY TESTED 'Add organisations latest name': 1 of 2", actualManualChangesViewModel.SuccessMessage);
            Assert.AreEqual(
                "1: EMPLOYERREFERENCE0111: 'Org123' set to 'New name ltd'\r\n<span style=\"color:Red\">2: ERROR: 'EMPLOYERREFERENCE0111' duplicate organisation</span>\r\n",
                actualManualChangesViewModel.Results);
            Assert.AreEqual("Add organisations latest name", actualManualChangesViewModel.LastTestedCommand);
            Assert.AreEqual(
                "employerreference0111=New name ltd;employerreference0111=New name ltd",
                actualManualChangesViewModel.LastTestedInput);
            Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
            Assert.IsNull(actualManualChangesViewModel.Comment);
        }
Esempio n. 11
0
        public async Task AdminController_ManualChanges_POST_Delete_Submissions_Works_When_Run_In_Test_Mode_Async()
        {
            // Arrange
            User databaseAdminUser = UserHelper.GetDatabaseAdmin();

            Core.Entities.Organisation publicOrganisationWithSubmissionsToBeDeleted =
                OrganisationHelper.GetPublicOrganisation("EmployerReference05");
            Return mockedReturn = ReturnHelper.CreateTestReturn(
                publicOrganisationWithSubmissionsToBeDeleted,
                VirtualDateTime.Now.AddYears(-1).Year);

            var testController = UiTestHelper.GetController <AdminController>(
                databaseAdminUser.UserId,
                null,
                databaseAdminUser,
                publicOrganisationWithSubmissionsToBeDeleted,
                mockedReturn);

            var manualChangesViewModelMock = Mock.Of <ManualChangesViewModel>();

            manualChangesViewModelMock.Command    = DeleteSubmissionsCommand;
            manualChangesViewModelMock.Parameters =
                $"{publicOrganisationWithSubmissionsToBeDeleted.EmployerReference}={mockedReturn.AccountingDate.Year}";

            // Act
            IActionResult actualManualChangesResult = await testController.ManualChanges(manualChangesViewModelMock);

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

            var manualChangesViewResult = actualManualChangesResult as ViewResult;

            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            Assert.Multiple(
                () => {
                Assert.AreEqual("SUCCESSFULLY TESTED 'Delete submissions': 1 of 1", actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    $"1: EMPLOYERREFERENCE05: Org123 Year='{VirtualDateTime.Now.AddYears(-1).Year}' Status='Submitted' set to 'Deleted'\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Delete submissions", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual(
                    $"EmployerReference05={mockedReturn.AccountingDate.Year}",
                    actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
        public async Task AdminController_ManualChanges_POST_Set_Organisation_DUNS_Number_Works_When_Run_In_Test_Mode_Async()
        {
            Core.Entities.Organisation orgWhoseDUNSNumberWillBeSet = OrganisationHelper.GetPrivateOrganisation("EmployerReference012");

            #region setting up database and controller

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

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

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

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

            var manualChangesViewModel = new ManualChangesViewModel {
                Command = SetOrganisationDUNSNumberCommand, Parameters = $"{orgWhoseDUNSNumberWillBeSet.EmployerReference}=123456789"
            };

            #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 'Set organisation DUNS number': 1 of 1",
                    actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "1: EMPLOYERREFERENCE012: Org123 DUNS Number='123456789' set to '123456789'\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Set organisation DUNS number", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual("EmployerReference012=123456789", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Esempio n. 13
0
        public async Task AdminController_ManualChanges_POST_Convert_Private_To_Public_Works_When_Run_In_Test_Mode_Async()
        {
            // Arrange
            Core.Entities.Organisation privateOrganisationToBeChangedToPublic = OrganisationHelper.GetPrivateOrganisation("EmployerReference04");

            #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[] { privateOrganisationToBeChangedToPublic }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command = ConvertPrivateToPublicCommand, Parameters = privateOrganisationToBeChangedToPublic.EmployerReference
            };

            #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 'Convert private to public': 1 of 1", actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "1: EMPLOYERREFERENCE04: Org123 sector Private set to 'Public'\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual(ConvertPrivateToPublicCommand, actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual("EmployerReference04", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Esempio n. 14
0
        public async Task AdminController_ManualChanges_POST_Delete_Submissions_Fails_When_No_Parameters_Are_Provided_Async(
            string nullOrEmptyParameter)
        {
            // Arrange
            User databaseAdminUser = UserHelper.GetDatabaseAdmin();

            Core.Entities.Organisation publicOrganisationWithSubmissionsToBeDeleted =
                OrganisationHelper.GetPublicOrganisation("EmployerReference05");
            Return mockedReturn = ReturnHelper.CreateTestReturn(
                publicOrganisationWithSubmissionsToBeDeleted,
                VirtualDateTime.Now.AddYears(-1).Year);

            var testController = UiTestHelper.GetController <AdminController>(
                databaseAdminUser.UserId,
                null,
                databaseAdminUser,
                publicOrganisationWithSubmissionsToBeDeleted,
                mockedReturn);

            var manualChangesViewModelMock = Mock.Of <ManualChangesViewModel>();

            manualChangesViewModelMock.Command    = DeleteSubmissionsCommand;
            manualChangesViewModelMock.Parameters = nullOrEmptyParameter;

            // Act
            IActionResult actualManualChangesResult = await testController.ManualChanges(manualChangesViewModelMock);

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

            var manualChangesViewResult = actualManualChangesResult as ViewResult;

            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            ModelStateEntry modelState    = testController.ModelState[""];
            ModelError      reportedError = modelState.Errors.First();

            Assert.AreEqual("ERROR: You must supply 1 or more input parameters", reportedError.ErrorMessage);
            Assert.IsNull(actualManualChangesViewModel.SuccessMessage);
            Assert.AreEqual("", actualManualChangesViewModel.Results);
            Assert.IsNull(actualManualChangesViewModel.LastTestedCommand);
            Assert.IsNull(actualManualChangesViewModel.LastTestedInput);
            Assert.False(actualManualChangesViewModel.Tested, "Must be false as this case has failed");
        }
Esempio n. 15
0
        public void ViewingController_EmployerDeprecated_When_An_Encrypted_Long_Id_Is_Received_Then_()
        {
            // Arrange
            var routeData = new RouteData();

            routeData.Values.Add("Action", "EmployerDetails");
            routeData.Values.Add("Controller", "Viewing");

            var org = new Core.Entities.Organisation {
                OrganisationId = 202, Status = OrganisationStatuses.Active
            };

            var report = new Return {
                ReturnId = 101, OrganisationId = org.OrganisationId, Status = ReturnStatuses.Submitted
            };
            var controller = UiTestHelper.GetController <ViewingController>(default, routeData, report);
Esempio n. 16
0
        public async Task AdminController_ManualChanges_POST_Delete_Submissions_Fails_When_Year_Parameter_Is_Not_Valid_Async()
        {
            // Arrange
            User databaseAdminUser = UserHelper.GetDatabaseAdmin();

            Core.Entities.Organisation publicOrganisationWithSubmissions =
                OrganisationHelper.GetPublicOrganisation("EmployerReference656262");
            Return mockedReturn   = ReturnHelper.CreateTestReturn(publicOrganisationWithSubmissions, VirtualDateTime.Now.AddYears(-1).Year);
            var    testController = UiTestHelper.GetController <AdminController>(
                databaseAdminUser.UserId,
                null,
                databaseAdminUser,
                publicOrganisationWithSubmissions,
                mockedReturn);

            var manualChangesViewModelMock = Mock.Of <ManualChangesViewModel>();

            manualChangesViewModelMock.Command    = DeleteSubmissionsCommand;
            manualChangesViewModelMock.Parameters = "EmployerReference656262=Invalid_Year_Parameter";

            // Act
            IActionResult actualManualChangesResult = await testController.ManualChanges(manualChangesViewModelMock);

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

            var manualChangesViewResult = actualManualChangesResult as ViewResult;

            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            Assert.Multiple(
                () => {
                Assert.AreEqual("SUCCESSFULLY TESTED 'Delete submissions': 0 of 1", actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "<span style=\"color:Red\">1: ERROR: 'EMPLOYERREFERENCE656262' invalid year 'Invalid_Year_Parameter'</span>\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Delete submissions", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual("EmployerReference656262=Invalid_Year_Parameter", actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Esempio n. 17
0
        public async Task ShouldReplaceEmployerAddress()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=Some House,1 Some Street,,Some Town,,,PC1 11RT",
                "D43TYU76=PO BOX 12,,,Another Town,,,PC2 55RT");

            ManualChangesViewModel thisTestManualChangesVm =
                ManualChangesViewModelHelper.GetMock(SetOrganisationAddressesCommand, thisTestParameters);

            thisTestManualChangesVm.LastTestedCommand = SetOrganisationAddressesCommand;
            thisTestManualChangesVm.LastTestedInput   = thisTestParameters.ReplaceI(Environment.NewLine, ";");

            // Act
            var thisManualChangesVr = await thisTestAdminController.ManualChanges(thisTestManualChangesVm) as ViewResult;

            // Assert
            Assert.NotNull(thisManualChangesVr, "Expected ViewResult");

            var actualManualChangesViewModel = thisManualChangesVr.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            string[] actualResults = actualManualChangesViewModel.Results.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Assert.AreEqual(3, actualResults.Length);

            Core.Entities.Organisation org1 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "6B2LF57C");
            Assert.AreEqual("Some House, 1 Some Street, Some Town, PC1 11RT", org1.LatestAddress.GetAddressString());
            Assert.AreEqual(
                "1: 6B2LF57C: Address=No previous address has been set to Some House,1 Some Street,,Some Town,,,PC1 11RT",
                actualResults[0]);

            Core.Entities.Organisation org2 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "D43TYU76");
            Assert.AreEqual("PO BOX 12, Another Town, PC2 55RT", org2.LatestAddress.GetAddressString());
            Assert.AreEqual(
                "2: D43TYU76: Address=No previous address has been set to PO BOX 12,,,Another Town,,,PC2 55RT",
                actualResults[1]);
        }
Esempio n. 18
0
        public async Task AdminController_ManualChanges_POST_Delete_Submissions_Fails_When_Return_Is_Not_On_The_Database_Async()
        {
            // Arrange
            int  yearToTest        = VirtualDateTime.Now.AddYears(-1).Year;
            User databaseAdminUser = UserHelper.GetDatabaseAdmin();

            Core.Entities.Organisation publicOrganisationWithSubmissionsToBeDeleted =
                OrganisationHelper.GetPublicOrganisation("EmployerReference99778");

            var testController = UiTestHelper.GetController <AdminController>(
                databaseAdminUser.UserId,
                null,
                databaseAdminUser,
                publicOrganisationWithSubmissionsToBeDeleted);

            var manualChangesViewModelMock = Mock.Of <ManualChangesViewModel>();

            manualChangesViewModelMock.Command    = DeleteSubmissionsCommand;
            manualChangesViewModelMock.Parameters = $"{publicOrganisationWithSubmissionsToBeDeleted.EmployerReference}={yearToTest}";

            // Act
            IActionResult actualManualChangesResult = await testController.ManualChanges(manualChangesViewModelMock);

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

            var manualChangesViewResult = actualManualChangesResult as ViewResult;

            Assert.NotNull(manualChangesViewResult, "Expected ViewResult");

            var actualManualChangesViewModel = manualChangesViewResult.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            Assert.AreEqual("SUCCESSFULLY TESTED 'Delete submissions': 0 of 1", actualManualChangesViewModel.SuccessMessage);
            Assert.AreEqual(
                $"<span style=\"color:Orange\">1: WARNING: 'EMPLOYERREFERENCE99778' Cannot find submitted data for year {yearToTest}</span>\r\n",
                actualManualChangesViewModel.Results);
            Assert.AreEqual("Delete submissions", actualManualChangesViewModel.LastTestedCommand);
            Assert.AreEqual($"EmployerReference99778={yearToTest}", actualManualChangesViewModel.LastTestedInput);
            Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
            Assert.IsNull(actualManualChangesViewModel.Comment);
        }
Esempio n. 19
0
        public async Task AdminController_ManualChanges_POST_ShouldUpdateOrganisationPublicSectorType()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData, testSecTypesData, testOrgSecTypesData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=1",
                "D43TYU76=2");

            ManualChangesViewModel thisTestManualChangesVm =
                ManualChangesViewModelHelper.GetMock(SetPublicSectorTypeCommand, thisTestParameters);

            thisTestManualChangesVm.LastTestedCommand = SetPublicSectorTypeCommand;
            thisTestManualChangesVm.LastTestedInput   = thisTestParameters.ReplaceI(Environment.NewLine, ";");

            // Act
            var thisManualChangesVr = await thisTestAdminController.ManualChanges(thisTestManualChangesVm) as ViewResult;

            // Assert
            Assert.NotNull(thisManualChangesVr, "Expected ViewResult");

            var actualManualChangesViewModel = thisManualChangesVr.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            string[] actualResults = actualManualChangesViewModel.Results.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Assert.AreEqual(3, actualResults.Length);

            Core.Entities.Organisation org1 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "6B2LF57C");
            Assert.AreEqual(1, org1.LatestPublicSectorType.PublicSectorTypeId);
            Assert.AreEqual(
                "1: 6B2LF57C:org 1 public sector type=No previous public sector type has been set to public sector type 1",
                actualResults[0]);

            Core.Entities.Organisation org2 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "D43TYU76");
            Assert.AreEqual(2, org2.LatestPublicSectorType.PublicSectorTypeId);
            Assert.AreEqual(
                "2: D43TYU76:org 9 public sector type=No previous public sector type has been set to public sector type 2",
                actualResults[1]);
        }
Esempio n. 20
0
        public void OrganisationController_Manageorganisations_GET_When_Creates_New_Model()
        {
            // ARRANGE
            User mockUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();

            mockUser.UserSettings = new[] { new UserSetting(UserSettingKeys.AcceptedPrivacyStatement, VirtualDateTime.Now.ToString()) };

            Core.Entities.Organisation mockOrg  = OrganisationHelper.GetPublicOrganisation();
            Core.Entities.Organisation mockOrg2 = OrganisationHelper.GetPublicOrganisation();
            Core.Entities.Organisation mockOrg3 = OrganisationHelper.GetPublicOrganisation();

            UserOrganisation mockUserOrg1 = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg);
            UserOrganisation mockUserOrg2 = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg2);
            UserOrganisation mockUserOrg3 = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg3);

            // route data
            var routeData = new RouteData();

            routeData.Values.Add("action", "ManageOrganisations");
            routeData.Values.Add("Controller", "Registrations");

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(
                -1,
                routeData,
                mockUser,
                mockOrg,
                mockOrg2,
                mockOrg3,
                mockUserOrg1,
                mockUserOrg2,
                mockUserOrg3);

            // Acts
            var result = controller.Home() as ViewResult;

            object actualUserOrganisationViewModel = result.Model;

            // Assert
            Assert.NotNull(result);
            Assert.NotNull(actualUserOrganisationViewModel);
            Assert.AreEqual(result.ViewName, "ManageOrganisations");
        }
Esempio n. 21
0
        public void RegistrationController_ServiceActivated_GET_When_OrgScope_is_Not_Null_Then_Return_Expected_ViewData()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ServiceActivated");
            mockRouteData.Values.Add("Controller", "Registration");

            var mockOrg = new Core.Entities.Organisation {
                OrganisationId = 52425, SectorType = SectorTypes.Private, OrganisationName = "Mock Organisation Ltd"
            };

            var mockUser = new User {
                UserId = 87654, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };

            var mockReg = new UserOrganisation {
                UserId = 87654, OrganisationId = 52425, PINConfirmedDate = VirtualDateTime.Now
            };

            var controller = UiTestHelper.GetController <RegistrationController>(87654, mockRouteData, mockUser, mockOrg, mockReg);

            controller.ReportingOrganisationId = mockOrg.OrganisationId;

            var testUri = new Uri("https://localhost/register/activate-service");

            controller.AddMockUriHelper(testUri.ToString(), "ActivateService");

            //Mock the Referrer
            controller.Request.Headers["Referer"] = testUri.ToString();

            // Act
            var viewResult = controller.ServiceActivated() as ViewResult;

            // Assert
            Assert.NotNull(viewResult, "ViewResult should not be null");
            Assert.AreEqual(viewResult.ViewName, "ServiceActivated", "Expected the ViewName to be 'ServiceActivated'");

            // Assert ViewData
            Assert.That(controller.ViewBag.OrganisationName == mockOrg.OrganisationName, "Expected OrganisationName");
        }
Esempio n. 22
0
        public async Task ShouldReplaceEmployerSicCodes()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData, testSicCodeData, testOrgSicCodeData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=1111",
                "23TYLBLB=3333");

            ManualChangesViewModel thisTestManualChangesVm =
                ManualChangesViewModelHelper.GetMock(SetOrganisationSicCodesCommand, thisTestParameters);

            thisTestManualChangesVm.LastTestedCommand = SetOrganisationSicCodesCommand;
            thisTestManualChangesVm.LastTestedInput   = thisTestParameters.ReplaceI(Environment.NewLine, ";");

            // Act
            var thisManualChangesVr = await thisTestAdminController.ManualChanges(thisTestManualChangesVm) as ViewResult;

            // Assert
            Assert.NotNull(thisManualChangesVr, "Expected ViewResult");

            var actualManualChangesViewModel = thisManualChangesVr.Model as ManualChangesViewModel;

            Assert.NotNull(actualManualChangesViewModel, "Expected ManualChangesViewModel");

            string[] actualResults = actualManualChangesViewModel.Results.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
            Assert.AreEqual(3, actualResults.Length);

            Core.Entities.Organisation org1 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "6B2LF57C");
            Assert.AreEqual("1111", org1.GetSicCodeIdsString());
            Assert.AreEqual("1: 6B2LF57C: SIC codes=1 has been set to 1111", actualResults[0]);

            Core.Entities.Organisation org2 = thisTestAdminController.SharedBusinessLogic.DataRepository.GetAll <Core.Entities.Organisation>()
                                              .SingleOrDefault(x => x.EmployerReference == "23TYLBLB");
            Assert.AreEqual("3333", org2.GetSicCodeIdsString());
            Assert.AreEqual("2: 23TYLBLB: SIC codes=3 has been set to 3333", actualResults[1]);
        }
Esempio n. 23
0
        public async Task RegistrationController_ConfirmOrganisation_Get_SuccessAsync()
        {
            // Arrange
            User mockUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();

            Core.Entities.Organisation mockOrg     = OrganisationHelper.GetPublicOrganisation();
            UserOrganisation           mockUserOrg = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg);

            Return mockReturn = ReturnHelper.GetNewReturnForOrganisationAndYear(mockUserOrg, ConfigHelpers.SharedOptions.FirstReportingYear);

            OrganisationHelper.LinkOrganisationAndReturn(mockOrg, mockReturn);

            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ServiceActivated");
            mockRouteData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <RegistrationController>(-1, mockRouteData, mockUser, mockOrg, mockUserOrg, mockReturn);

            controller.ReportingOrganisationId = mockOrg.OrganisationId;

            controller.StashModel(new OrganisationViewModel());

            var testUri = new Uri("https://localhost/register/activate-service");

            controller.AddMockUriHelper(testUri.ToString(), "ActivateService");

            //Mock the Referrer
            controller.Request.Headers["Referer"] = testUri.ToString();

            var result = await controller.ConfirmOrganisation() as ViewResult;

            Assert.NotNull(result);

            Assert.AreEqual("ConfirmOrganisation", result.ViewName);
        }
Esempio n. 24
0
        public async Task RemoveOrganisation_POST_When_User_Org_Removed_Then_Sends_User_Email()
        {
            // Arrange
            User user1 = CreateUser(1, "*****@*****.**");
            User user2 = CreateUser(2, "*****@*****.**");

            Core.Entities.Organisation organisation      = createPrivateOrganisation(100, "Company1", 12345678);
            UserOrganisation           userOrganisation1 = CreateUserOrganisation(organisation, user1.UserId, VirtualDateTime.Now);
            UserOrganisation           userOrganisation2 = CreateUserOrganisation(organisation, user2.UserId, VirtualDateTime.Now);

            var routeData = new RouteData();

            routeData.Values.Add("Action", "RemoveOrganisation");
            routeData.Values.Add("Controller", "Registration");

            var testModel = new RemoveOrganisationModel {
                EncOrganisationId = Encryption.EncryptQuerystring(organisation.OrganisationId.ToString()),
                EncUserId         = Encryption.EncryptQuerystring(user1.UserId.ToString())
            };

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(
                user1.UserId,
                routeData,
                user1,
                user2,
                organisation,
                userOrganisation1,
                userOrganisation2);

            organisation.LatestScope = new OrganisationScope {
                ScopeStatus = ScopeStatuses.InScope
            };

            var mockNotifyEmailQueue = new Mock <IQueue>();

            var mockEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));
            mockEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <QueueWrapper>()));

            // Act
            var result = await controller.RemoveOrganisation(testModel) as RedirectToActionResult;

            // Assert$
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(user1.EmailAddress))),
                Times.Once(),
                "Expected the current user's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(
                    It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.RemovedUserFromOrganisationEmail))),
                Times.Exactly(2),
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.RemovedUserFromOrganisationEmail}");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(user2.EmailAddress))),
                Times.Once(),
                "Expected the other user of the same organisation's email address to be in the email send queue");

            mockEmailQueue.Verify(
                x => x.AddMessageAsync(
                    It.Is <QueueWrapper>(
                        inst => inst.Message.Contains(ConfigHelpers.EmailOptions.GEODistributionList) &&
                        inst.Type == typeof(OrphanOrganisationTemplate).FullName)),
                Times.Never,
                $"Didnt expect the GEO Email addresses using {nameof(OrphanOrganisationTemplate)} to be in the email send queue");

            Assert.NotNull(result, "redirectResult should not be null");
            Assert.AreEqual("RemoveOrganisationCompleted", result.ActionName, "Expected the ViewName to be 'RemoveOrganisationCompleted'");
        }
Esempio n. 25
0
        public async Task AdministrationController_ManualChanges_prevAddress_SetStatus_Address_Statuses_Retired()
        {
            // Arrange
            var existingAddressExpectedToBeRetired = new OrganisationAddress {
                Address1 = "Previous Address1",
                Address2 = "Previous Address2",
                Address3 = "Previous Address3",
                TownCity = "Previous TownCity",
                County   = "Previous County",
                Country  = "Previous Country",
                PostCode = "Previous PostCode",
                Status   = AddressStatuses.Active
            };

            Core.Entities.Organisation privateOrgWhoseAddressWillBeChanged = OrganisationHelper.GetPrivateOrganisation("Employer_Reference_989898");
            privateOrgWhoseAddressWillBeChanged.LatestAddress = existingAddressExpectedToBeRetired;

            #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[] { privateOrgWhoseAddressWillBeChanged }.AsQueryable().BuildMock().Object);

            var manualChangesViewModel = new ManualChangesViewModel {
                Command    = SetOrganisationAddressesCommand,
                Parameters =
                    $"{privateOrgWhoseAddressWillBeChanged.EmployerReference}=New Address1, New Address2, New Address3, New TownCity, New County, New Country, New PostCode"
            };

            #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 'Set organisation addresses': 1 of 1",
                    actualManualChangesViewModel.SuccessMessage);
                Assert.AreEqual(
                    "1: EMPLOYER_REFERENCE_989898:Org123 Address=Previous Address1, Previous Address2, Previous Address3, Previous TownCity, Previous County, Previous Country, Previous PostCode will be set to New Address1, New Address2, New Address3, New TownCity, New County, New Country, New PostCode\r\n",
                    actualManualChangesViewModel.Results);
                Assert.AreEqual("Set organisation addresses", actualManualChangesViewModel.LastTestedCommand);
                Assert.AreEqual(
                    "Employer_Reference_989898=New Address1, New Address2, New Address3, New TownCity, New County, New Country, New PostCode",
                    actualManualChangesViewModel.LastTestedInput);
                Assert.True(actualManualChangesViewModel.Tested, "Must be tested=true as this case is running in TEST mode");
                Assert.IsNull(actualManualChangesViewModel.Comment);
            });
        }
Esempio n. 26
0
        public async Task AdminController_ReviewRequest_POST_ManualRegistration_ServiceActivated()
        {
            //ARRANGE:
            //create a user who does exist in the db
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };
            var org = new Core.Entities.Organisation {
                OrganisationId = 1, SectorType = SectorTypes.Private, Status = OrganisationStatuses.Pending
            };

            //TODO: Refactoring to user the same Helpers (ie AddScopeStatus.AddScopeStatus)
            org.OrganisationScopes.Add(
                new OrganisationScope {
                Organisation = org,
                ScopeStatus  = ScopeStatuses.InScope,
                SnapshotDate = org.SectorType.GetAccountingStartDate(VirtualDateTime.Now.Year),
                Status       = ScopeRowStatuses.Active
            });

            var address = new OrganisationAddress {
                AddressId = 1, OrganisationId = 1, Organisation = org, Status = AddressStatuses.Pending
            };
            var userOrg = new UserOrganisation {
                UserId         = 1,
                OrganisationId = 1,
                AddressId      = address.AddressId,
                Address        = address,
                User           = user,
                Organisation   = org
            };

            var routeData = new RouteData();

            routeData.Values.Add("Action", nameof(RegistrationController.OrganisationType));
            routeData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <AdminController>(user.UserId, routeData, user, org, address, userOrg);

            var model = new OrganisationViewModel {
                ReviewCode = userOrg.GetReviewCode()
            };

            controller.StashModel(model);

            //ACT:
            var result = await controller.ReviewRequest(model, "approve") as RedirectToActionResult;

            //ASSERT:
            Assert.That(result != null, "Expected RedirectToActionResult");
            Assert.That(result.ActionName == "RequestAccepted", "Expected redirect to RequestAccepted");
            Assert.That(userOrg.PINConfirmedDate > DateTime.MinValue);
            Assert.That(userOrg.Organisation.Status == OrganisationStatuses.Active);
            Assert.That(userOrg.Organisation.LatestAddress.AddressId == address.AddressId);
            Assert.That(!string.IsNullOrWhiteSpace(userOrg.Organisation.EmployerReference));
            Assert.That(address.Status == AddressStatuses.Active);

            //Check the organisation exists in search
            EmployerSearchModel actualIndex = await controller.AdminService.SearchBusinessLogic.EmployerSearchRepository.GetAsync(org.OrganisationId.ToString());

            EmployerSearchModel expectedIndex = EmployerSearchModel.Create(org);

            expectedIndex.Compare(actualIndex);
        }
        public async Task RegistrationController_POST_When_User_Added_To_Organisation_Via_Fast_Track_Then_Email_Existing_Users()
        {
            // Arrange
            var organisationId = 100;

            Core.Entities.Organisation organisation = createPrivateOrganisation(organisationId, "Company1", 12345678);
            User             existingUser1          = CreateUser(1, "*****@*****.**");
            User             existingUser2          = CreateUser(2, "*****@*****.**");
            User             newUser = CreateUser(3, "*****@*****.**");
            UserOrganisation existingUserOrganisation1 = CreateUserOrganisation(organisation, existingUser1.UserId, VirtualDateTime.Now);
            UserOrganisation existingUserOrganisation2 = CreateUserOrganisation(organisation, existingUser2.UserId, VirtualDateTime.Now);
            UserOrganisation newUserOrganisation       = CreateUserOrganisation(organisation, newUser.UserId, VirtualDateTime.Now);

            newUserOrganisation.PINConfirmedDate = null;

            var employers = new PagedResult <EmployerRecord> {
                Results = new List <EmployerRecord>()
            };

            var employer = new EmployerRecord {
                OrganisationId   = organisationId,
                OrganisationName = organisation.OrganisationName,
                CompanyNumber    = organisation.CompanyNumber,
                SectorType       = SectorTypes.Private,
                Address1         = "Address 1",
                Address2         = "Address 2",
                Address3         = "Address 3",
                City             = "City",
                County           = "County",
                Country          = "UK",
                PostCode         = "NW5 1TL",
                PoBox            = "Po Box"
            };

            employers.Results.Add(employer);

            var routeData = new RouteData();

            routeData.Values.Add("Action", "ConfirmOrganisation");
            routeData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <RegistrationController>(
                newUser.UserId,
                routeData,
                organisation,
                existingUser1,
                existingUser2,
                newUser,
                existingUserOrganisation1,
                existingUserOrganisation2,
                newUserOrganisation);

            var testModel = new OrganisationViewModel {
                SectorType            = SectorTypes.Private,
                OrganisationName      = organisation.OrganisationName,
                Employers             = employers,
                IsFastTrackAuthorised = true
            };

            controller.StashModel(testModel);

            var mockNotifyEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));

            // Act
            await controller.ConfirmOrganisation(testModel, "confirm");

            //ASSERT:
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser1.EmailAddress))),
                Times.Once(),
                "Expected the existingUser1's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser2.EmailAddress))),
                Times.Once(),
                "Expected the existingUser2's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.UserAddedToOrganisationEmail))),
                Times.Exactly(2),
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.UserAddedToOrganisationEmail}");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(newUser.EmailAddress))),
                Times.Never,
                "Do not expect new user's email address to be in the email send queue");
        }
Esempio n. 28
0
        public async Task RegistrationController_POST_When_User_Added_To_Public_Organisation_Then_Email_Existing_Users()
        {
            // Arrange
            var organisationId = 100;

            Core.Entities.Organisation organisation = Registration.RegistrationControllerTests.createPublicOrganisation(organisationId, "Company1", 12345678);
            User             existingUser1          = Registration.RegistrationControllerTests.CreateUser(1, "*****@*****.**");
            User             existingUser2          = Registration.RegistrationControllerTests.CreateUser(2, "*****@*****.**");
            User             newUser = Registration.RegistrationControllerTests.CreateUser(3, "*****@*****.**");
            UserOrganisation existingUserOrganisation1 = Registration.RegistrationControllerTests.CreateUserOrganisation(organisation, existingUser1.UserId, VirtualDateTime.Now);
            UserOrganisation existingUserOrganisation2 = Registration.RegistrationControllerTests.CreateUserOrganisation(organisation, existingUser2.UserId, VirtualDateTime.Now);
            UserOrganisation newUserOrganisation       = Registration.RegistrationControllerTests.CreateUserOrganisation(organisation, newUser.UserId, VirtualDateTime.Now);

            newUserOrganisation.PINConfirmedDate = null;
            User govEqualitiesOfficeUser = UserHelper.GetGovEqualitiesOfficeUser();

            govEqualitiesOfficeUser.EmailVerifiedDate = VirtualDateTime.Now;

            var routeData = new RouteData();

            routeData.Values.Add("Action", "ReviewRequest");
            routeData.Values.Add("Controller", "Registration");

            var controller = UiTestHelper.GetController <AdminController>(
                govEqualitiesOfficeUser.UserId,
                routeData,
                organisation,
                existingUser1,
                existingUser2,
                newUser,
                existingUserOrganisation1,
                existingUserOrganisation2,
                newUserOrganisation,
                govEqualitiesOfficeUser);

            var testModel = new OrganisationViewModel {
                ReviewCode = newUserOrganisation.GetReviewCode()
            };

            controller.StashModel(testModel);

            var mockNotifyEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));

            // Act
            await controller.ReviewRequest(testModel, "approve");

            //ASSERT:
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser1.EmailAddress))),
                Times.Once(),
                "Expected the existingUser1's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser2.EmailAddress))),
                Times.Once(),
                "Expected the existingUser2's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.UserAddedToOrganisationEmail))),
                Times.Exactly(2),
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.UserAddedToOrganisationEmail}");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(newUser.EmailAddress))),
                Times.Never,
                "Do not expect new user's email address to be in the email send queue");
        }
 public static UserOrganisation CreateUserOrganisation(Core.Entities.Organisation org, long userId, DateTime?pinConfirmedDate)
 {
     return(new UserOrganisation {
         Organisation = org, UserId = userId, PINConfirmedDate = pinConfirmedDate, Address = new OrganisationAddress()
     });
 }
        public async Task RegistrationController_POST_When_User_Added_To_Private_Organisation_Then_Email_Existing_Users()
        {
            // Arrange
            var organisationId = 100;

            Core.Entities.Organisation organisation = createPrivateOrganisation(organisationId, "Company1", 12345678);
            User             existingUser1          = CreateUser(1, "*****@*****.**");
            User             existingUser2          = CreateUser(2, "*****@*****.**");
            User             newUser = CreateUser(3, "*****@*****.**");
            UserOrganisation existingUserOrganisation1 = CreateUserOrganisation(organisation, existingUser1.UserId, VirtualDateTime.Now);
            UserOrganisation existingUserOrganisation2 = CreateUserOrganisation(organisation, existingUser2.UserId, VirtualDateTime.Now);
            UserOrganisation newUserOrganisation       = CreateUserOrganisation(organisation, newUser.UserId, VirtualDateTime.Now);

            newUserOrganisation.PIN = "B5EC243";
            newUserOrganisation.PINConfirmedDate = null;
            newUserOrganisation.PINSentDate      = VirtualDateTime.Now.AddDays(100000);

            var routeData = new RouteData();

            routeData.Values.Add("Action", "ActivateService");
            routeData.Values.Add("Controller", "Registration");

            var testModel = new CompleteViewModel {
                PIN = "B5EC243", OrganisationId = organisationId
            };

            var controller = UiTestHelper.GetController <RegistrationController>(
                newUser.UserId,
                routeData,
                organisation,
                existingUser1,
                existingUser2,
                newUser,
                existingUserOrganisation1,
                existingUserOrganisation2,
                newUserOrganisation);

            controller.ReportingOrganisationId = organisationId;

            var mockNotifyEmailQueue = new Mock <IQueue>();

            mockNotifyEmailQueue
            .Setup(q => q.AddMessageAsync(It.IsAny <SendEmailRequest>()));

            // Act
            await controller.ActivateService(testModel);

            //ASSERT:
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser1.EmailAddress))),
                Times.Once(),
                "Expected the existingUser1's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(existingUser2.EmailAddress))),
                Times.Once(),
                "Expected the existingUser2's email address to be in the email send queue");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.TemplateId.Contains(EmailTemplates.UserAddedToOrganisationEmail))),
                Times.Exactly(2),
                $"Expected the correct templateId to be in the email send queue, expected {EmailTemplates.UserAddedToOrganisationEmail}");
            mockNotifyEmailQueue.Verify(
                x => x.AddMessageAsync(It.Is <SendEmailRequest>(inst => inst.EmailAddress.Contains(newUser.EmailAddress))),
                Times.Never,
                "Do not expect new user's email address to be in the email send queue");
        }