Ejemplo n.º 1
0
        public async Task AdminController_ManualChanges_POST_Delete_Submissions_Fails_When_An_Equals_Sign_Is_Not_Sent_Async()
        {
            // Arrange
            User databaseAdminUser = UserHelper.GetDatabaseAdmin();
            var  testController    = UiTestHelper.GetController <AdminController>(databaseAdminUser.UserId, null, databaseAdminUser);

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

            manualChangesViewModelMock.Command    = DeleteSubmissionsCommand;
            manualChangesViewModelMock.Parameters = "Not_Equals_Sign";

            // 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:Red\">1: ERROR: 'Not_Equals_Sign' does not contain '=' character</span>\r\n",
                actualManualChangesViewModel.Results);
            Assert.AreEqual("Delete submissions", actualManualChangesViewModel.LastTestedCommand);
            Assert.AreEqual("Not_Equals_Sign", actualManualChangesViewModel.LastTestedInput);
            Assert.True(actualManualChangesViewModel.Tested, "Must be true as this case is running in TEST mode");
            Assert.Null(actualManualChangesViewModel.Comment);
        }
        public async Task POST_FailsWhenCurrentPasswordIsWrong()
        {
            // Arrange
            User verifiedUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            var  testPassword = "******";
            var  testSalt     = "testSalt";

            verifiedUser.Salt             = testSalt;
            verifiedUser.PasswordHash     = Crypto.GetPBKDF2(testPassword, Convert.FromBase64String(testSalt));
            verifiedUser.HashingAlgorithm = HashingAlgorithm.PBKDF2;

            var controller =
                UiTestHelper.GetController <ModernSlavery.WebUI.Areas.Account.Controllers.CloseAccountController>(
                    verifiedUser.UserId,
                    mockRouteData,
                    verifiedUser);

            // Act
            var viewResult = await controller.CloseAccount(new CloseAccountViewModel { EnterPassword = "******" }) as ViewResult;

            // Assert
            Assert.NotNull(viewResult, "Expected a ViewResult");
            Assert.AreEqual(nameof(ModernSlavery.WebUI.Areas.Account.Controllers.CloseAccountController.CloseAccount), viewResult.ViewName);
            Assert.AreEqual(
                "Could not verify your current password",
                viewResult.ViewData.ModelState["CurrentPassword"].Errors[0].ErrorMessage);
        }
Ejemplo n.º 3
0
        public async Task FailsWhenEmailOwnedByNewOrActiveUser()
        {
            // Arrange
            User   verifiedUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            User   existingUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            string testNewEmail = existingUser.EmailAddress;

            var controller = UiTestHelper.GetController <ModernSlavery.WebUI.Areas.Account.Controllers.ChangeEmailController>(
                verifiedUser.UserId,
                mockRouteData,
                verifiedUser,
                existingUser);

            string expectedCurrentEmailAddress = verifiedUser.EmailAddress;

            string code = Encryption.EncryptModel(
                new ChangeEmailVerificationToken {
                UserId = verifiedUser.UserId, NewEmailAddress = testNewEmail, TokenTimestamp = VirtualDateTime.Now
            });

            // Act
            var viewResult = await controller.CompleteChangeEmailAsync(code) as ViewResult;

            // Assert
            Assert.NotNull(viewResult);
            Assert.AreEqual("ChangeEmailFailed", viewResult.ViewName);
            Assert.AreEqual(1, viewResult.ViewData.ModelState.ErrorCount);
            Assert.AreEqual(
                "Cannot complete the change email process because the new email address has been registered since this change was requested.",
                viewResult.ViewData.ModelState[nameof(controller.CompleteChangeEmailAsync)].Errors[0].ErrorMessage);

            Assert.AreEqual(expectedCurrentEmailAddress, verifiedUser.EmailAddress, "Expected the email address not to change");
        }
Ejemplo n.º 4
0
        public async Task ShouldFailEachLineMissingEqualsCharacter()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "test=passed",
                "this line should fail",
                "red=passed",
                "this line should fail also");

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

            // 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(5, actualResults.Length);
            Assert.IsFalse(actualResults[0].Contains(DoesNotContainEquals), "Expected false when line contains '='");
            Assert.IsTrue(actualResults[1].Contains(DoesNotContainEquals), "Expected true when line does not contain '='");
            Assert.IsFalse(actualResults[2].Contains(DoesNotContainEquals), "Expected false when line contains '='");
            Assert.IsTrue(actualResults[3].Contains(DoesNotContainEquals), "Expected true when line does not contain '='");
        }
Ejemplo n.º 5
0
        public async Task ShouldFailWhenOrganisationIsNotActive()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "TY67R5T6=1311",
                "DR994D7L=1241");

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

            // 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);
            Assert.IsTrue(actualResults[0].Contains(OrganisationMustBeActive), "Expected true when an organisation is not active");
            Assert.IsFalse(actualResults[1].Contains(OrganisationMustBeActive), "Expected false when an organisation is active");
        }
        public void RemoveOrganisation_GET_When_User_Org_Not_Assoc_to_Then_Return_Forbidden()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "RemoveOrganisation");
            mockRouteData.Values.Add("Controller", "Organisation");

            var testUserId = 4;
            var testOrgId  = 123; // not in user 4's UserOrganisations

            var controller = UiTestHelper.GetController <OrganisationController>(
                testUserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);

            string encOrgId  = Encryption.EncryptQuerystring(testOrgId.ToString());
            string encUserId = Encryption.EncryptQuerystring(testUserId.ToString());

            // Act
            IActionResult actionResult = controller.RemoveOrganisation(encOrgId, encUserId);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.Forbidden, "Expected the StatusCode to be a 'Forbidden'");
        }
Ejemplo n.º 7
0
        public async Task ShouldFailWhenMissingAddressEntries()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=a1,a2",
                "DR994D7L=a1,a2,a3,t1,c1,c2,pc1",
                "23TYLBLB=1,2,3,4",
                "SNGNB4BH=a1,a2,a3,t1,c1,c2,pc1",
                "RWT2TY62=1,2,3,4,5");

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

            // 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(6, actualResults.Length);
            Assert.IsTrue(actualResults[0].Contains(IncorrectNumberOfAddressFields), "Expected true when Sic code is not an integer");
            Assert.IsFalse(actualResults[1].Contains(IncorrectNumberOfAddressFields), "Expected false when Sic code is an integer");
            Assert.IsTrue(actualResults[2].Contains(IncorrectNumberOfAddressFields), "Expected true when Sic code is not an integer");
            Assert.IsFalse(actualResults[3].Contains(IncorrectNumberOfAddressFields), "Expected false when Sic code is an integer");
            Assert.IsTrue(actualResults[4].Contains(IncorrectNumberOfAddressFields), "Expected true when Sic code is not an integer");
        }
Ejemplo n.º 8
0
        public async Task AdminController_ManualChanges_POST_ShouldFailWhenEmployerIsNotPublicSector()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=1",
                "DR994D7L=2",
                "23TYLBLB=3",
                "SNGNB4BH=4",
                "RWT2TY62=5");

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

            // 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(6, actualResults.Length);
            Assert.IsFalse(actualResults[0].Contains(IsNotPublicSector), "Expected false when organisation is not public sector");
            Assert.IsTrue(actualResults[1].Contains(IsNotPublicSector), "Expected true when organisation is public sector");
            Assert.IsFalse(actualResults[2].Contains(IsNotPublicSector), "Expected false when organisation is not public sector");
            Assert.IsTrue(actualResults[3].Contains(IsNotPublicSector), "Expected true when organisation is public sector");
            Assert.IsFalse(actualResults[4].Contains(IsNotPublicSector), "Expected false when organisation is not public sector");
        }
Ejemplo n.º 9
0
        public async Task AdminController_ManualChanges_POST_ShouldFailWhenPublicSectorTypeDoesNotExist()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData, testOrgSecTypesData, testSecTypesData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=1412",
                "DR994D7L=2",
                "23TYLBLB=355");

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

            // 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(4, actualResults.Length);
            Assert.IsTrue(
                actualResults[0].Contains("public sector type 1412 does not exist"),
                "Expected false when public sector type doesn't exist");
            Assert.IsFalse(actualResults[1].Contains("does not exist"), "Expected true when public sector type exists");
            Assert.IsTrue(
                actualResults[2].Contains("public sector type 355 does not exist"),
                "Expected false when public sector type doesn't exist");
        }
Ejemplo n.º 10
0
        public async Task AdminController_ManualChanges_POST_ShouldFailWhenNoValueAfterEqualsCharacter()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=",
                "23TYLBLB=",
                "RWT2TY62=4");

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

            // 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(4, actualResults.Length);
            Assert.IsTrue(actualResults[0].Contains(MustContainPublicSectorTypeCode), "Expected true when line contains a value");
            Assert.IsTrue(actualResults[1].Contains(MustContainPublicSectorTypeCode), "Expected true when line contains a value");
            Assert.IsFalse(actualResults[2].Contains(MustContainPublicSectorTypeCode), "Expected true when line contains a value");
        }
Ejemplo n.º 11
0
        public async Task AdminController_ManualChanges_POST_ShouldFailWhenPublicSectorTypeNotInteger()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData, testOrgSecTypesData, testSecTypesData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=TEST",
                "23TYLBLB=ABCD",
                "RWT2TY62=4");

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

            // 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(4, actualResults.Length);
            Assert.IsTrue(actualResults[0].Contains(PublicSectorTypeMustBeInteger), "Expected to fail when input not an integer");
            Assert.IsTrue(actualResults[1].Contains(PublicSectorTypeMustBeInteger), "Expected to fail when input not an integer");
            Assert.IsFalse(actualResults[2].Contains(PublicSectorTypeMustBeInteger), "Expected to succeed when input is an integer");
        }
Ejemplo n.º 12
0
        public async Task ViewingController_SearchResults_GET_Returns_400_for_invalid_search_parameters()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "SearchResults");
            mockRouteData.Values.Add("Controller", "Viewing");

            var controller = UiTestHelper.GetController <ViewingController>(0, mockRouteData);

            // Test p Parameter
            var result = await controller.SearchResults(new SearchResultsQuery { search = "search text", p = 0 }) as HttpStatusViewResult;

            Assert.NotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("EmployerSearch: Invalid page 0", result.StatusDescription);

            // Test es Parameter
            result =
                await controller.SearchResults(new SearchResultsQuery { search = "search text", es = new[] { 4, 10 }, p = 1 }) as
                HttpStatusViewResult;

            Assert.NotNull(result);
            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("EmployerSearch: Invalid EmployerSize 4,10", result.StatusDescription);
        }
Ejemplo n.º 13
0
        public async Task ViewingController_SearchResults_GET_Returns_Finder_SearchResults_view()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "SearchResults");
            mockRouteData.Values.Add("Controller", "Viewing");

            var controller = UiTestHelper.GetController <ViewingController>(0, mockRouteData);

            var searchText = "search text";
            var sectorType = SearchTypes.BySectorType;
            // Test
            var query = new SearchResultsQuery {
                search = searchText, t = sectorType, p = 1
            };
            var result = await controller.SearchResults(query) as ViewResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual("Finder/SearchResults", result.ViewName);
            var model = result.Model as SearchViewModel;

            Assert.NotNull(model);
            Assert.AreEqual(query.search, model.search);
            Assert.AreEqual(query.p, model.p);
        }
Ejemplo n.º 14
0
        public void OrganisationController_ManageOrganisations_GET_When_UserSettings_AcceptedPrivacyStatement_is_Latest_Then_Return()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ManageOrganisations");
            mockRouteData.Values.Add("Controller", "Registrations");

            var mockUser = new User {
                UserId            = 87654,
                EmailAddress      = "*****@*****.**",
                EmailVerifiedDate = VirtualDateTime.Now,
                UserSettings      = new[] { new UserSetting(UserSettingKeys.AcceptedPrivacyStatement, VirtualDateTime.Now.ToString()) }
            };

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(-1, mockRouteData, mockUser);

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

            // Assert
            Assert.IsNull(result, "RedirectToActionResult should be null");
            Assert.AreNotEqual(result?.ActionName, "ReadPrivacyStatement", "Expected the Action NOT to be 'ReadPrivacyStatement'");
            Assert.AreNotEqual(result?.ControllerName, "Organisation", "Expected the Controller NOT to be 'Home'");
        }
        public void DeclareScope_POST_When_User_Not_FullyRegistered_Then_Return_ForbiddenAsync()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "DeclareScope");
            mockRouteData.Values.Add("Controller", "Organisation");

            var testUserId = 3;
            var testOrgId  = 123;

            var controller = UiTestHelper.GetController <OrganisationController>(
                testUserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);

            string   encOrgId     = Encryption.EncryptQuerystring(testOrgId.ToString());
            DateTime snapshotDate = SectorTypes.Private.GetAccountingStartDate();
            var      model        = new DeclareScopeModel();

            // Act
            IActionResult actionResult = controller.DeclareScope(model, encOrgId);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.Forbidden, "Expected the StatusCode to be a 'Forbidden'");
        }
        public void RegistrationController_AddAddress_GET_Success()
        {
            //ARRANGE:
            //create a user who does exist in the db
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };

            var routeData = new RouteData();

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

            var controller = UiTestHelper.GetController <RegistrationController>(user.UserId, routeData, user);

            var orgModel = new OrganisationViewModel {
                ManualRegistration = false, ManualAddress = true, SectorType = SectorTypes.Public
            };

            controller.StashModel(orgModel);

            //ACT:
            var result       = controller.AddAddress() as ViewResult;
            var model        = result?.Model as OrganisationViewModel;
            var stashedModel = controller.UnstashModel <OrganisationViewModel>();

            //ASSERT:
            Assert.NotNull(result, "Expected ViewResult");
            Assert.That(result.ViewName == nameof(RegistrationController.AddAddress), "Expected Viewname=AddAddress");
            Assert.NotNull(model, "Expected model of OrganisationViewModel");
            Assert.NotNull(stashedModel, "Expected model saved to stash");
            Assert.That(model.ManualAddress, "Expected ManualAddress to be false");
        }
        public void RemoveOrganisation_GET_When_OrgId_IsNullOrWhitespace_Then_Return_BadRequest()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "RemoveOrganisation");
            mockRouteData.Values.Add("Controller", "Organisation");

            var controller = UiTestHelper.GetController <OrganisationController>(
                MockUsers[0].UserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);
            var testOrgId  = "";
            var testUserId = "";

            // Act
            IActionResult actionResult = controller.RemoveOrganisation(testOrgId, testUserId);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.BadRequest, "Expected the StatusCode to be a 'BadRequest'");
        }
        public void InitialiseTestObjectsBeforeEachTest()
        {
            User testUser          = UserHelper.GetSuperAdmin();
            var  thisTestDbObjects = new object[] { testUser };

            _TestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
        }
Ejemplo n.º 19
0
        public async Task ShouldFailWhenEmployerHasCompanyNumber()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=address",
                "DR994D7L=address",
                "23TYLBLB=address",
                "SNGNB4BH=address",
                "RWT2TY62=address");

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

            // 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(6, actualResults.Length);
            Assert.IsFalse(actualResults[0].Contains(HasCompanyNumber), "Expected false when organisation doesnt have a company number");
            Assert.IsTrue(actualResults[1].Contains(HasCompanyNumber), "Expected true when organisation has a company number");
            Assert.IsFalse(actualResults[2].Contains(HasCompanyNumber), "Expected false when organisation doesnt have a company number");
            Assert.IsTrue(actualResults[3].Contains(HasCompanyNumber), "Expected true when organisation has a company number");
            Assert.IsFalse(actualResults[4].Contains(HasCompanyNumber), "Expected false when organisation doesnt have a company number");
        }
Ejemplo n.º 20
0
        public void ChangeOrganisationScope_GET_When_User_Not_Assoc_to_Org_Then_Return_Forbidden()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ChangeOrganisationScope");
            mockRouteData.Values.Add("Controller", "Scope");

            var testUserId = 4;
            var testOrgId  = 123;

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(
                testUserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);

            string testRequest = Encryption.EncryptAsParams(testOrgId.ToString(), "2017");

            // Act
            IActionResult actionResult = controller.ChangeOrganisationScope(testRequest);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.Forbidden, "Expected the StatusCode to be a 'Forbidden'");
        }
Ejemplo n.º 21
0
        public async Task ShouldFailWhenRequiredFieldIsMissing()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=,a2,a3,t1,c1,c2,pc1",
                "23TYLBLB=a1,a2,a3,,c1,c2,pc1",
                "RWT2TY62=a1,a2,a3,t1,c1,c2,");

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

            // 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(4, actualResults.Length);
            Assert.IsTrue(actualResults[0].Contains(Address1IsRequired), "Expected true when address1 is missing");
            Assert.IsTrue(actualResults[1].Contains(TownCityIsRequired), "Expected true when town\\city is missing");
            Assert.IsTrue(actualResults[2].Contains(PostcodeIsRequired), "Expected true when postcode is missing");
        }
Ejemplo n.º 22
0
        public async Task ManageOrganisation_GET_When_User_Not_Assoc_to_Org_Then_Return_ForbiddenAsync()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ManageOrganisation");
            mockRouteData.Values.Add("Controller", "Submission");

            var testUserId = 4;
            var testOrgId  = 123;

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(
                testUserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);

            string encOrgId = Encryption.EncryptQuerystring(testOrgId.ToString());

            // Act
            IActionResult actionResult = await controller.ManageOrganisation(encOrgId);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.Forbidden, "Expected the StatusCode to be a 'Forbidden'");
        }
Ejemplo n.º 23
0
        public async Task ShouldFailDuplicateEmployers()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = "  ="
                                             + Environment.NewLine
                                             + string.Join(Environment.NewLine, "EMP1=1", "EMP2=2", "EMP3=3", "EMP2=4", "EMP4=4");

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

            // 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(6, actualResults.Length);
            Assert.IsFalse(actualResults[0].Contains(DuplicateOrganisation), "Expected false when employer is not duplicate");
            Assert.IsFalse(actualResults[1].Contains(DuplicateOrganisation), "Expected false when employer is not duplicate");
            Assert.IsFalse(actualResults[2].Contains(DuplicateOrganisation), "Expected false when employer is not duplicate");
            Assert.IsTrue(actualResults[3].Contains(DuplicateOrganisation), "Expected true when employer is a duplicate");
            Assert.IsFalse(actualResults[4].Contains(DuplicateOrganisation), "Expected false when employer is not duplicate");
        }
Ejemplo n.º 24
0
        public async Task ManageOrganisation_GET_When_NewOrg_PresumedScope_Then_RedirectToDeclareScope()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "ManageOrganisation");
            mockRouteData.Values.Add("Controller", "Submission");

            var testUserId = 2;
            var testOrgId  = 123;

            var controller = UiTestHelper.GetController <ManageOrganisationsController>(
                testUserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);

            //Mock an existing explicit scope to prevent redirect to DeclareScope page
            Mock <IScopeBusinessLogic> mockScopeBL = AutoFacExtensions.ResolveAsMock <IScopeBusinessLogic>();

            mockScopeBL.Setup(x => x.GetLatestScopeStatusForSnapshotYearAsync(It.IsAny <long>(), It.IsAny <int>()))
            .ReturnsAsync(ScopeStatuses.PresumedInScope);

            string encOrgId = Encryption.EncryptQuerystring(testOrgId.ToString());

            // Act
            var actionResult = await controller.ManageOrganisation(encOrgId) as RedirectToActionResult;

            // Assert
            Assert.IsNotNull(actionResult, "actionResult should not be null");

            Assert.AreEqual(actionResult.ActionName, "DeclareScope", "Expected redirect to DeclareScope");
            Assert.AreEqual(actionResult.RouteValues["id"], encOrgId, "Wrong organisation id returned");
        }
Ejemplo n.º 25
0
        public async Task ShouldFailWhenSicCodesDontExist()
        {
            // Arrange
            var    thisTestDbObjects       = new object[] { testUser, testOrgData, testSicCodeData };
            var    thisTestAdminController = UiTestHelper.GetController <AdminController>(testUser.UserId, null, thisTestDbObjects);
            string thisTestParameters      = string.Join(
                "\r\n",
                "6B2LF57C=1111",
                "DR994D7L=2",
                "23TYLBLB=3333",
                "SNGNB4BH=4",
                "RWT2TY62=5555");

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

            // 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(6, actualResults.Length);
            Assert.IsFalse(actualResults[0].Contains(SicCodeDoesntExist), "Expected false when sic code exists");
            Assert.IsFalse(actualResults[1].Contains(SicCodeDoesntExist), "Expected true when sic code does not exist");
            Assert.IsFalse(actualResults[2].Contains(SicCodeDoesntExist), "Expected false when sic code exists");
            Assert.IsFalse(actualResults[3].Contains(SicCodeDoesntExist), "Expected true when sic code does not exist");
            Assert.IsFalse(actualResults[4].Contains(SicCodeDoesntExist), "Expected false when sic code exists");
        }
Ejemplo n.º 26
0
        public void CompareController_AddEmployer_Success_RedirectToReturnUrl()
        {
            // Arrange
            var  controller     = UiTestHelper.GetController <CompareController>();
            long organisationId = 123;
            var  expectedObfuscatedOrganisationId = ViewingControllerTests.ConfigureObfuscator(organisationId);
            var  employerIdentifier = expectedObfuscatedOrganisationId;
            var  returnUrl          = @"\viewing\search-results";

            controller.SearchViewService.LastSearchResults = new SearchViewModel()
            {
                Employers = new PagedResult <Core.Models.EmployerSearchModel>()
                {
                    Results = new List <Core.Models.EmployerSearchModel>()
                    {
                        new Core.Models.EmployerSearchModel()
                        {
                            OrganisationIdEncrypted = employerIdentifier,
                            OrganisationId          = organisationId.ToString()
                        }
                    }
                }
            };

            // Act
            var result = controller.AddEmployer(employerIdentifier, returnUrl) as LocalRedirectResult;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(returnUrl, result.Url);
            Assert.AreEqual(controller.CompareViewService.BasketItemCount, 1);
            Assert.IsTrue(controller.CompareViewService.ComparedEmployers.Value.Contains(employerIdentifier));
            controller.AssertCookieAdded(CookieNames.LastCompareQuery, expectedObfuscatedOrganisationId);
        }
Ejemplo n.º 27
0
        public async Task FailsWhenTokenExpired()
        {
            // Arrange
            var  testNewEmail = "*****@*****.**";
            User verifiedUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            var  controller   =
                UiTestHelper.GetController <ModernSlavery.WebUI.Areas.Account.Controllers.ChangeEmailController>(
                    verifiedUser.UserId,
                    mockRouteData,
                    verifiedUser);
            string expectedCurrentEmailAddress = verifiedUser.EmailAddress;

            string code = Encryption.EncryptModel(
                new ChangeEmailVerificationToken {
                UserId = verifiedUser.UserId, NewEmailAddress = testNewEmail, TokenTimestamp = VirtualDateTime.Now.AddDays(-1)
            });

            // Act
            var viewResult = await controller.CompleteChangeEmailAsync(code) as ViewResult;

            // Assert
            Assert.NotNull(viewResult);
            Assert.AreEqual("ChangeEmailFailed", viewResult.ViewName);
            Assert.AreEqual(1, viewResult.ViewData.ModelState.ErrorCount);
            Assert.AreEqual(
                "Cannot complete the change email process because your verify url has expired.",
                viewResult.ViewData.ModelState[nameof(controller.CompleteChangeEmailAsync)].Errors[0].ErrorMessage);

            Assert.AreEqual(expectedCurrentEmailAddress, verifiedUser.EmailAddress, "Expected the email address not to change");
        }
        public void DeclareScope_POST_When_Id_IsNullOrWhitespace_Then_Return_BadRequestAsync()
        {
            // Arrange
            var mockRouteData = new RouteData();

            mockRouteData.Values.Add("Action", "DeclareScope");
            mockRouteData.Values.Add("Controller", "Organisation");

            var controller = UiTestHelper.GetController <OrganisationController>(
                MockUsers[0].UserId,
                mockRouteData,
                MockUsers,
                MockUserOrganisations);
            var      testOrgId    = "";
            var      model        = new DeclareScopeModel();
            DateTime snapshotDate = SectorTypes.Private.GetAccountingStartDate();

            // Act
            IActionResult actionResult = controller.DeclareScope(model, testOrgId);

            // Assert
            var httpStatusResult = actionResult as HttpStatusViewResult;

            Assert.NotNull(httpStatusResult, "httpStatusResult should not be null");
            Assert.AreEqual(httpStatusResult.StatusCode, (int)HttpStatusCode.BadRequest, "Expected the StatusCode to be a 'BadRequest'");
        }
Ejemplo n.º 29
0
        public async Task UpdatesUserEmailAddress()
        {
            // Arrange
            var  testNewEmail = "*****@*****.**";
            User verifiedUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            var  controller   =
                UiTestHelper.GetController <ModernSlavery.WebUI.Areas.Account.Controllers.ChangeEmailController>(
                    verifiedUser.UserId,
                    mockRouteData,
                    verifiedUser);

            string code = Encryption.EncryptModel(
                new ChangeEmailVerificationToken {
                UserId = verifiedUser.UserId, NewEmailAddress = testNewEmail, TokenTimestamp = VirtualDateTime.Now
            });

            // Act
            var viewResult = await controller.CompleteChangeEmailAsync(code) as ViewResult;

            // Assert
            Assert.NotNull(viewResult);
            Assert.AreEqual("ChangeEmailCompleted", viewResult.ViewName);

            Assert.AreEqual(testNewEmail, verifiedUser.EmailAddress, "Expected new email address to be saved");
        }
        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);
            });
        }