public void Is_False_When_ModifiedDate_Is_Late_And_OutOfScope(SectorTypes sector, ScopeStatuses scopeStatus) { var totalYearOffsets = 4; for (var yearOffset = 0; yearOffset < totalYearOffsets; yearOffset++) { // Arrange int testYear = VirtualDateTime.Now.Year - yearOffset; DateTime snapshotDate = sector.GetAccountingStartDate(testYear); DateTime nextSnapshotDate = snapshotDate.AddYears(1); DateTime modifiedDate = nextSnapshotDate.AddDays(2); Organisation testOrganisation = sector == SectorTypes.Private ? OrganisationHelper.GetPrivateOrganisation() : OrganisationHelper.GetPublicOrganisation(); OrganisationScope testScope = ScopeHelper.CreateScope(scopeStatus, snapshotDate); Return testReturn = ReturnHelper.CreateLateReturn(testOrganisation, snapshotDate, modifiedDate, testScope); // Act bool actual = testReturn.IsLateSubmission; // Assert Assert.AreEqual(false, actual); } }
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); }); }
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); }
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); }); }
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); }); }
public async Task ScopePresentation_CreateOrganisationViewModel_When_Data_Is_Valid_It_SucceedsAsync() { // Arrange var employerRef = "6MQP1ETH"; User mockUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress(); Organisation mockOrg = OrganisationHelper.GetPrivateOrganisation(employerRef); mockOrg.SetSecurityCode(VirtualDateTime.Now.AddDays(1)); UserOrganisation mockUserOrg = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg); var dataRepo = new Mock <IDataRepository>(); dataRepo.SetupGetAll(mockOrg); var organisationBusinessLogic = new OrganisationBusinessLogic( testCommonBL, dataRepo.Object, new Mock <ISubmissionBusinessLogic>().Object, new Mock <IScopeBusinessLogic>().Object, new Mock <IEncryptionHandler>().Object, new Mock <ISecurityCodeBusinessLogic>().Object, new Mock <IDnBOrgsRepository>().Object, new Mock <IObfuscator>().Object); var scopePresenter = new ScopePresenter( mockScopeBL.Object, dataRepo.Object, organisationBusinessLogic, testCommonBL); var testModel = new EnterCodesViewModel { EmployerReference = mockOrg.EmployerReference, SecurityToken = mockOrg.SecurityCode }; // Act OrganisationViewModel actual = await scopePresenter.CreateOrganisationViewModelAsync(testModel, mockUser); // Assert Assert.NotNull(actual, "Expected an organisation view model"); Assert.AreEqual(employerRef, actual.Employers.Results[0].EmployerReference); Assert.False(actual.IsSecurityCodeExpired, "the security code was set to expire tomorrow"); }
public void Is_True_When_ModifiedDate_Is_Late_And_InScope(SectorTypes sector, ScopeStatuses scopeStatus) { // Arrange int testYear = GetRandomReportingYear(ignoreYearsExcludedFromLateFlagEnforcement: true); DateTime snapshotDate = sector.GetAccountingStartDate(testYear); DateTime modifiedDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate).AddDays(2); Organisation testOrganisation = sector == SectorTypes.Private ? OrganisationHelper.GetPrivateOrganisation() : OrganisationHelper.GetPublicOrganisation(); OrganisationScope testScope = ScopeHelper.CreateScope(scopeStatus, snapshotDate); Return testReturn = ReturnHelper.CreateLateReturn(testOrganisation, snapshotDate, modifiedDate, testScope); // Act bool actual = testReturn.IsLateSubmission; // Assert Assert.AreEqual(true, actual); }
public async Task ScopePresentation_CreateOrganisationViewModel_When_Record_Not_Found_Returns_NullAsync() { // Arrange var employerRef = "SomeThatWillBeInDatabase"; User mockUser = UserHelper.GetNotAdminUserWithVerifiedEmailAddress(); Organisation mockOrg = OrganisationHelper.GetPrivateOrganisation(employerRef); mockOrg.SetSecurityCode(VirtualDateTime.Now.AddDays(1)); UserOrganisation mockUserOrg = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg); var dataRepo = new Mock <IDataRepository>(); dataRepo.SetupGetAll(mockOrg); var organisationBusinessLogic = new OrganisationBusinessLogic( testCommonBL, dataRepo.Object, new Mock <ISubmissionBusinessLogic>().Object, new Mock <IScopeBusinessLogic>().Object, new Mock <IEncryptionHandler>().Object, new Mock <ISecurityCodeBusinessLogic>().Object, new Mock <IDnBOrgsRepository>().Object, new Mock <IObfuscator>().Object); var scopePresenter = new ScopePresenter( mockScopeBL.Object, dataRepo.Object, organisationBusinessLogic, testCommonBL); var testModel = new EnterCodesViewModel { EmployerReference = "NotFoundInDB", SecurityToken = mockOrg.SecurityCode }; // Act OrganisationViewModel actual = await scopePresenter.CreateOrganisationViewModelAsync(testModel, mockUser); // Assert Assert.Null(actual, "When the combination EmployerReference/SecurityCode is not found in DB, this method must return null"); }
public void IsFalseWhenNotVoluntary(SectorTypes testSector, int testOrgSize, ScopeStatuses testScopeStatus) { // Arrange var testOrganisation = testSector == SectorTypes.Private ? OrganisationHelper.GetPrivateOrganisation() : OrganisationHelper.GetPublicOrganisation(); var snapshotDate = testSector.GetAccountingStartDate(VirtualDateTime.Now.Year); var testScope = ScopeHelper.CreateScope(testScopeStatus, snapshotDate); var testReturn = ReturnHelper.CreateTestReturn(testOrganisation, snapshotDate.Year); testReturn.MaxEmployees = testOrgSize; OrganisationHelper.LinkOrganisationAndReturn(testOrganisation, testReturn); OrganisationHelper.LinkOrganisationAndScope(testOrganisation, testScope, true); // Act var actual = testReturn.IsVoluntarySubmission(); // Assert Assert.IsFalse((bool)actual); }
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); }); }
public async Task AdminController_ManualChanges_POST_Fix_Database_Error_Missing_Latest_Scope_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 scope link so it's picked up by the test Core.Entities.Organisation organisation_MissingLatestScope = OrganisationHelper.GetPrivateOrganisation("EmployerReference5487548"); UserOrganisation userOrganisation_MissingLatestScope = UserOrganisationHelper.LinkUserWithOrganisation(notAdminUser, organisation_MissingLatestScope); organisation_MissingLatestScope.LatestRegistration = userOrganisation_MissingLatestScope; Return return_MissingLatestScope = ReturnHelper.GetSubmittedReturnForOrganisationAndYear( userOrganisation_MissingLatestScope, VirtualDateTime.Now.AddYears(-1).Year); organisation_MissingLatestScope.Returns.Add(return_MissingLatestScope); organisation_MissingLatestScope.LatestReturn = return_MissingLatestScope; OrganisationScope scope_MissingLatestScope = ScopeHelper.CreateScope(ScopeStatuses.InScope, VirtualDateTime.Now.AddYears(-1)); organisation_MissingLatestScope.OrganisationScopes.Add( scope_MissingLatestScope); // latest scope indeed exists for this organisation organisation_MissingLatestScope.LatestScope = null; // missing latest scope -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_MissingLatestScope }.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.AreEqual("SUCCESSFULLY EXECUTED 'Fix database errors': 1 items", actualManualChangesViewModel.SuccessMessage); var expectedManualChangesViewModelResults = "No organisations missing a latest registration\r\nNo organisations missing a latest return\r\n001: Organisation 'EmployerReference5487548:Org123' missing a latest scope was successfully fixed\r\n"; Assert.AreEqual( expectedManualChangesViewModelResults, actualManualChangesViewModel.Results, $"EXPECTED -{expectedManualChangesViewModelResults}- BUT WAS -{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); }