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 void SaveScope_retires_any_previous_submissions_in_the_same_snapshot_year() { Organisation testOrg = testOrgData.Where(o => o.OrganisationId == 4).FirstOrDefault(); var testNewScope = new OrganisationScope { OrganisationId = 4, SnapshotDate = new DateTime(2017, 4, 5) }; var saveChangesCalled = false; // Mocks mockDataRepo.Setup(r => r.GetAll <OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); mockDataRepo.Setup(r => r.SaveChanges()).Callback(() => saveChangesCalled = true); // Test testScopeBL.SaveScope(testOrg, true, testNewScope); // Assert Expect(saveChangesCalled, "Expected SaveChanges() to be called"); Expect(testOrg.OrganisationScopes.Contains(testNewScope), "Expected org.OrganisationScopes to contain new scope"); // ensure only one submitted record for the current snapshot year Expect(testNewScope.Status == ScopeRowStatuses.Active, "Expected new scope status to be submitted"); Expect( testOrg.OrganisationScopes.Count(os => os.Status == ScopeRowStatuses.Active && os.SnapshotDate.Year == 2017) == 1, "Expected Count(OrganisationScopes == submitted) to be 1"); }
public IActionResult ConfirmOutOfScopeAnswers(string encryptedOrganisationId, int reportingYear, ScopeViewModel viewModel) { long organisationId = DecryptOrganisationId(encryptedOrganisationId); // Check user has permissions to access this page ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); // Get Organisation Organisation organisation = dataRepository.Get <Organisation>(organisationId); // Update OrganisationScope var reasonForChange = viewModel.WhyOutOfScope == WhyOutOfScope.Under250 ? "Under250" : viewModel.WhyOutOfScopeDetails; DateTime currentSnapshotDate = organisation.SectorType.GetAccountingStartDate(); RetireOldScopes(organisation, reportingYear); UpdateScopes(organisation, ScopeStatuses.OutOfScope, reportingYear, reasonForChange, viewModel.HaveReadGuidance == HaveReadGuidance.Yes); dataRepository.SaveChanges(); SendScopeChangeEmails(organisation, viewModel.ReportingYear, currentSnapshotDate, ScopeStatuses.OutOfScope); OrganisationScope organisationScope = organisation.OrganisationScopes.FirstOrDefault(s => s.SnapshotDate.Year == reportingYear); viewModel.Organisation = organisation; viewModel.ReportingYear = organisationScope.SnapshotDate; return(View("FinishOutOfScopeJourney", viewModel)); }
public IActionResult SubmitOutOfScopeAnswers(string encryptedOrganisationId, int reportingYear, ScopeViewModel viewModel) { long organisationId = DecryptOrganisationId(encryptedOrganisationId); // Check user has permissions to access this page ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); viewModel.ParseAndValidateParameters(Request, m => m.WhyOutOfScope); viewModel.ParseAndValidateParameters(Request, m => m.HaveReadGuidance); if (viewModel.WhyOutOfScope == WhyOutOfScope.Other) { viewModel.ParseAndValidateParameters(Request, m => m.WhyOutOfScopeDetails); } // Get Organisation and OrganisationScope for reporting year Organisation organisation = dataRepository.Get <Organisation>(organisationId); OrganisationScope organisationScope = organisation.OrganisationScopes.FirstOrDefault(s => s.SnapshotDate.Year == reportingYear); viewModel.Organisation = organisation; viewModel.ReportingYear = organisationScope.SnapshotDate; viewModel.IsToSetInScope = false; if (viewModel.HasAnyErrors()) { return(View("OutOfScopeQuestions", viewModel)); } return(View("ConfirmScope", viewModel)); }
public void PresumesInScopeForSnapshotYearsDuringAndAfterOrgCreatedDate(SectorTypes testSectorType) { // setup DateTime testCreatedDate = testSectorType.GetAccountingStartDate().AddYears(-1); Organisation testOrg = CreateOrgWithNoScopes(1, testSectorType, testCreatedDate); // act bool actualChanged = scopeBusinessLogic.FillMissingScopes(testOrg); // assert Assert.IsTrue(actualChanged, "Expected change for missing scopes"); // test the count of scopes set is correct DateTime currentSnapshotDate = testOrg.SectorType.GetAccountingStartDate(); int expectedScopeCount = (currentSnapshotDate.Year - Global.FirstReportingYear) + 1; Assert.AreEqual(expectedScopeCount, testOrg.OrganisationScopes.Count); // check each scope after created date is set to presumed in of scope OrganisationScope[] actualScopesArray = testOrg.OrganisationScopes.ToArray(); for (int i = actualScopesArray.Length - 2; i < actualScopesArray.Length; i++) { OrganisationScope scope = actualScopesArray[i]; Assert.AreEqual(ScopeStatuses.PresumedInScope, scope.ScopeStatus); } }
public void PresumesOutOfScopeForSnapshotYearsBeforeOrgCreatedDate(SectorTypes testSectorType) { // setup Organisation testOrg = CreateOrgWithNoScopes(1, testSectorType, VirtualDateTime.Now); // act bool actualChanged = scopeBusinessLogic.FillMissingScopes(testOrg); // assert Assert.IsTrue(actualChanged, "Expected change for missing scopes"); // test the count of scopes set is correct DateTime currentSnapshotDate = testOrg.SectorType.GetAccountingStartDate(); int expectedScopeCount = (currentSnapshotDate.Year - Global.FirstReportingYear) + 1; Assert.AreEqual(expectedScopeCount, testOrg.OrganisationScopes.Count); // check each scope before current snapshot year are set to presumed out of scope OrganisationScope[] actualScopesArray = testOrg.OrganisationScopes.ToArray(); for (var i = 0; i < actualScopesArray.Length - 1; i++) { OrganisationScope scope = actualScopesArray[i]; Assert.AreEqual(ScopeStatuses.PresumedOutOfScope, scope.ScopeStatus); } // assert current year is presumed in scope Assert.AreEqual(ScopeStatuses.PresumedInScope, actualScopesArray[actualScopesArray.Length - 1].ScopeStatus); }
public void PreservesDeclaredScopes(SectorTypes testSectorType, ScopeStatuses testDeclaredScopeStatus, ScopeStatuses expectedPresumedScopeStatus) { // setup DateTime testCreatedDate = testSectorType.GetAccountingStartDate(Global.FirstReportingYear); Organisation testOrg = CreateOrgWithDeclaredAndPresumedScopes( testSectorType, testDeclaredScopeStatus, testCreatedDate, testCreatedDate); // act bool actualChanged = scopeBusinessLogic.FillMissingScopes(testOrg); // assert Assert.IsTrue(actualChanged, "Expected change to be true for missing scopes"); OrganisationScope[] actualScopesArray = testOrg.OrganisationScopes.ToArray(); Assert.AreEqual(testDeclaredScopeStatus, actualScopesArray[0].ScopeStatus, "Expected first year scope status to match"); // check that each year is presumed out of scope after first year for (var i = 1; i < actualScopesArray.Length; i++) { OrganisationScope scope = actualScopesArray[i]; Assert.AreEqual(expectedPresumedScopeStatus, scope.ScopeStatus, "Expected presumed scope statuses to match"); } }
public string GetRequiredToReportOrNotText() { OrganisationScope scopeForYear = organisation.GetScopeForYear(ReportingYear); return(scopeForYear.IsInScopeVariant() ? "REQUIRED TO REPORT" : "NOT REQUIRED TO REPORT"); }
public IActionResult ChangeScopePost(long id, int year, AdminChangeScopeViewModel viewModel) { var organisation = dataRepository.Get <Organisation>(id); var currentOrganisationScope = organisation.GetScopeForYear(year); if (currentOrganisationScope.ScopeStatus != ScopeStatuses.InScope && currentOrganisationScope.ScopeStatus != ScopeStatuses.OutOfScope) { viewModel.ParseAndValidateParameters(Request, m => m.NewScopeStatus); } viewModel.ParseAndValidateParameters(Request, m => m.Reason); if (viewModel.HasAnyErrors()) { // If there are any errors, return the user back to the same page to correct the mistakes var currentScopeStatus = organisation.GetScopeStatus(year); viewModel.OrganisationName = organisation.OrganisationName; viewModel.OrganisationId = organisation.OrganisationId; viewModel.ReportingYear = year; viewModel.CurrentScopeStatus = currentScopeStatus; return(View("ChangeScope", viewModel)); } RetireOldScopesForCurrentSnapshotDate(organisation, year); ScopeStatuses newScope = ConvertNewScopeStatusToScopeStatus(viewModel.NewScopeStatus); var newOrganisationScope = new OrganisationScope { Organisation = organisation, ScopeStatus = newScope, ScopeStatusDate = VirtualDateTime.Now, ContactFirstname = currentOrganisationScope.ContactFirstname, ContactLastname = currentOrganisationScope.ContactLastname, ContactEmailAddress = currentOrganisationScope.ContactEmailAddress, Reason = viewModel.Reason, SnapshotDate = currentOrganisationScope.SnapshotDate, StatusDetails = "Changed by Admin", Status = ScopeRowStatuses.Active }; dataRepository.Insert(newOrganisationScope); dataRepository.SaveChanges(); auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationScope, organisation, new { PreviousScope = currentOrganisationScope.ScopeStatus.ToString(), NewScope = newScope.ToString(), Reason = viewModel.Reason }, User); return(RedirectToAction("ViewScopeHistory", "AdminOrganisationScope", new { id = organisation.OrganisationId })); }
public virtual async Task SavePresumedScopeAsync(ScopingViewModel model, int snapshotYear) { if (string.IsNullOrWhiteSpace(model.EnterCodes.EmployerReference)) { throw new ArgumentNullException(nameof(model.EnterCodes.EmployerReference)); } if (model.IsSecurityCodeExpired) { throw new ArgumentOutOfRangeException(nameof(model.IsSecurityCodeExpired)); } // get the organisation by EmployerReference var org = await GetOrgByEmployerReferenceAsync(model.EnterCodes.EmployerReference); if (org == null) { throw new ArgumentOutOfRangeException( nameof(model.EnterCodes.EmployerReference), $"Cannot find organisation with EmployerReference: {model.EnterCodes.EmployerReference} in the database"); } // can only save a presumed scope in the prev or current snapshot year var currentSnapshotDate = _sharedBusinessLogic.GetAccountingStartDate(org.SectorType); if (snapshotYear > currentSnapshotDate.Year || snapshotYear < currentSnapshotDate.Year - 1) { throw new ArgumentOutOfRangeException(nameof(snapshotYear)); } // skip saving a presumed scope when an active scope already exists for the snapshot year if (await ScopeBusinessLogic.GetLatestScopeBySnapshotYearAsync(org.OrganisationId, snapshotYear) != null) { return; } // create the new OrganisationScope var newScope = new OrganisationScope { OrganisationId = org.OrganisationId, ContactEmailAddress = model.EnterAnswers.EmailAddress, ContactFirstname = model.EnterAnswers.FirstName, ContactLastname = model.EnterAnswers.LastName, ReadGuidance = model.EnterAnswers.HasReadGuidance(), Reason = "", ScopeStatus = model.IsOutOfScopeJourney ? ScopeStatuses.PresumedOutOfScope : ScopeStatuses.PresumedInScope, CampaignId = model.CampaignId, // set the snapshot date according to sector SnapshotDate = _sharedBusinessLogic.GetAccountingStartDate(org.SectorType, snapshotYear), StatusDetails = "Generated by the system" }; // save the presumed scope await ScopeBusinessLogic.SaveScopeAsync(org, true, newScope); }
public static Organisation GetOrganisationInAGivenScope(ScopeStatuses scope, string employerRef = null, int snapshotYear = 0) { Organisation org = GetPrivateOrganisation(employerRef); OrganisationScope organisationScope = OrganisationScopeHelper.GetOrgScopeWithThisScope(snapshotYear, org.SectorType, scope); org.OrganisationScopes.Add(organisationScope); return(org); }
public virtual async Task SaveScopesAsync(ScopingViewModel model, IEnumerable <int> snapshotYears) { if (string.IsNullOrWhiteSpace(model.EnterCodes.EmployerReference)) { throw new ArgumentNullException(nameof(model.EnterCodes.EmployerReference)); } if (model.IsSecurityCodeExpired) { throw new ArgumentOutOfRangeException(nameof(model.IsSecurityCodeExpired)); } if (!snapshotYears.Any()) { throw new ArgumentNullException(nameof(snapshotYears)); } //Get the organisation with this employer reference var org = model.OrganisationId == 0 ? null : await _sharedBusinessLogic.DataRepository.FirstOrDefaultAsync <Organisation>(o => o.OrganisationId == model.OrganisationId); if (org == null) { throw new ArgumentOutOfRangeException( nameof(model.OrganisationId), $"Cannot find organisation with Id: {model.OrganisationId} in the database"); } var newScopes = new List <OrganisationScope>(); foreach (var snapshotYear in snapshotYears.OrderByDescending(y => y)) { var scope = new OrganisationScope { OrganisationId = org.OrganisationId, ContactEmailAddress = model.EnterAnswers.EmailAddress, ContactFirstname = model.EnterAnswers.FirstName, ContactLastname = model.EnterAnswers.LastName, ReadGuidance = model.EnterAnswers.HasReadGuidance(), Reason = model.EnterAnswers.Reason != "Other" ? model.EnterAnswers.Reason : model.EnterAnswers.OtherReason, ScopeStatus = model.IsOutOfScopeJourney ? ScopeStatuses.OutOfScope : ScopeStatuses.InScope, CampaignId = model.CampaignId, // set the snapshot date according to sector SnapshotDate = _sharedBusinessLogic.GetAccountingStartDate(org.SectorType, snapshotYear) }; newScopes.Add(scope); } await ScopeBusinessLogic.SaveScopesAsync(org, newScopes); await _searchBusinessLogic.UpdateSearchIndexAsync(org); }
public async Task GetPendingScopeRegistration_When_EmailAddress_doesnt_Match_Then_Return_Null() { // Arrange mockDataRepo.Setup(r => r.GetAll<OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetPendingScopeRegistrationAsync("*****@*****.**"); // Assert Assert.That(result == null, "Expected to return null when using a non existing EmailAddress"); }
public async Task GetOrgScopeById_When_ScopeId_doesnt_Match_Then_Return_Null() { // Arrange mockDataRepo.Setup(r => r.GetAll<OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetScopeByIdAsync(123); // Assert Assert.That(result == null, "Expected to return null when using a non existing scopeId"); }
/// <summary> /// Returns the latest scope status for an organisation and snapshot year /// </summary> /// <param name="organisationId"></param> /// <param name="snapshotYear"></param> public virtual ScopeStatuses GetLatestScopeStatusForSnapshotYear(Organisation org, int snapshotYear = 0) { OrganisationScope latestScope = GetLatestScopeBySnapshotYear(org, snapshotYear); if (latestScope == null) { return(ScopeStatuses.Unknown); } return(latestScope.ScopeStatus); }
public async Task GetPendingScopeRegistration_When_EmailAddress_Matches_Then_Return_OrganisationScope_ModelAsync() { // Arrange mockDataRepo.Setup(r => r.GetAll<OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetPendingScopeRegistrationAsync("*****@*****.**"); // Assert Assert.That(result != null, "Expected to return a valid OrganisationScope Model"); Assert.That(result.OrganisationScopeId == 35, "Expected the model to have the same OrganisationScopeId"); }
/// <summary> /// Gets the latest scope for the specified organisation id and snapshot year /// </summary> /// <param name="organisationId"></param> /// <param name="snapshotYear"></param> public virtual OrganisationScope GetLatestScopeBySnapshotYear(Organisation organisation, int snapshotYear = 0) { if (snapshotYear == 0) { snapshotYear = organisation.SectorType.GetAccountingStartDate().Year; } OrganisationScope orgScope = organisation.OrganisationScopes .SingleOrDefault(s => s.SnapshotDate.Year == snapshotYear && s.Status == ScopeRowStatuses.Active); return(orgScope); }
public static OrganisationScope GetOrgScopeWithThisScope(int snapshotYear, SectorTypes organisationSectorType, ScopeStatuses scope) { if (snapshotYear == 0) { snapshotYear = organisationSectorType.GetAccountingStartDate().Year; } OrganisationScope org = GetOrganisationScope(snapshotYear, organisationSectorType); org.ScopeStatus = scope; return(org); }
public void GetLatestScopeForSnapshotYear_When_SnapshotYear_doesnt_Match_Then_Return_Null() { // Arrange mockDataRepo.Setup(r => r.GetAll <OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); mockDataRepo.Setup(r => r.GetAll <Organisation>()).Returns(testOrgData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = testScopeBL.GetLatestScopeBySnapshotYear(4, 2016); // Assert Assert.That(result == null, "Expected to return null when using an existing EmployerReference that has no scope"); }
public async Task GetOrgScopeByEmployerReference_When_EmployerReference_Exists_But_Has_No_Scope_Then_Return_Null() { // Arrange var testEmployerRef = "RWT2TY62"; var testSnapshotYear = 2017; mockDataRepo.Setup(r => r.GetAll<Organisation>()).Returns(testOrgData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetScopeByEmployerReferenceAsync("RWT2TY62", testSnapshotYear); // Assert Assert.That(result == null, "Expected to return null when using an existing EmployerReference that has no scope"); }
public async Task GetOrgScopeByEmployerReference_When_EmployerReference_doesnt_Match_Then_Return_Null() { // Arrange var testEmployerRef = "AAAABBBB"; var testSnapshotYear = 2017; mockDataRepo.Setup(r => r.GetAll<Organisation>()).Returns(new List<Organisation>().AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetScopeByEmployerReferenceAsync(testEmployerRef, testSnapshotYear); // Assert Assert.That(result == null, "Expected to return null when using a non existing EmployerReference"); }
public string GetByReportingDeadlineText() { OrganisationScope scopeForYear = organisation.GetScopeForYear(ReportingYear); if (scopeForYear.IsInScopeVariant()) { DateTime snapshotDate = organisation.SectorType.GetAccountingStartDate(ReportingYear); DateTime deadline = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate); return("by " + deadline.ToString("d MMM yyyy")); } return(null); }
public void GetLatestScopeForSnapshotYear_When_SnapshotYear_Matches_Then_Return_LatestScopeForSnapshotYear() { // Arrange mockDataRepo.Setup(r => r.GetAll <OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); mockDataRepo.Setup(r => r.GetAll <Organisation>()).Returns(testOrgData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = testScopeBL.GetLatestScopeBySnapshotYear(4, 2017); // Assert Assert.That(result != null, "Expected to return a valid OrganisationScope Model"); Assert.That(result.OrganisationId == 4, "Expected the model to have the same OrganisationId"); Assert.That(result.OrganisationScopeId == 65, "Expected the model to have the same OrganisationScopeId"); }
public async Task GetOrgScopeById_When_ScopeId_Exists_Then_Return_ScopeAsync() { // Arrange mockDataRepo.Setup(r => r.GetAll<OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetScopeByIdAsync(35); // Assert Assert.That(result != null, "The result was null when using an existing scopeId"); Assert.That(result.OrganisationScopeId == 35, "Expected OrganisationScopeId to match"); Assert.That(result.OrganisationId == 3, "Expected OrganisationId to match"); Assert.That(result.ContactEmailAddress == "*****@*****.**", "Expected ContactEmailAddress to match"); }
/// <summary> /// Adds a new scope and updates the latest scope (if required) /// </summary> /// <param name="org"></param> /// <param name="scopeStatus"></param> /// <param name="snapshotDate"></param> /// <param name="currentUser"></param> public virtual OrganisationScope SetPresumedScope(Organisation org, ScopeStatuses scopeStatus, DateTime snapshotDate, User currentUser = null) { //Ensure scopestatus is presumed if (scopeStatus != ScopeStatuses.PresumedInScope && scopeStatus != ScopeStatuses.PresumedOutOfScope) { throw new ArgumentOutOfRangeException(nameof(scopeStatus)); } //Check no previous scopes if (org.OrganisationScopes.Any(os => os.SnapshotDate == snapshotDate)) { throw new ArgumentException( $"A scope already exists for snapshot year {snapshotDate.Year} for organisation employer reference '{org.EmployerReference}'", nameof(scopeStatus)); } //Check for conflict with previous years scope if (snapshotDate.Year > _sharedBusinessLogic.SharedOptions.FirstReportingYear) { var previousScope = GetLatestScopeStatusForSnapshotYear(org, snapshotDate.Year - 1); if (previousScope == ScopeStatuses.InScope && scopeStatus == ScopeStatuses.PresumedOutOfScope || previousScope == ScopeStatuses.OutOfScope && scopeStatus == ScopeStatuses.PresumedInScope) { throw new ArgumentException( $"Cannot set {scopeStatus} for snapshot year {snapshotDate.Year} when previos year was {previousScope} for organisation employer reference '{org.EmployerReference}'", nameof(scopeStatus)); } } var newScope = new OrganisationScope { OrganisationId = org.OrganisationId, ContactEmailAddress = currentUser?.EmailAddress, ContactFirstname = currentUser?.Firstname, ContactLastname = currentUser?.Lastname, ScopeStatus = scopeStatus, Status = ScopeRowStatuses.Active, StatusDetails = "Generated by the system", SnapshotDate = snapshotDate }; org.OrganisationScopes.Add(newScope); return(newScope); }
private void SetInitialScopeForYear(Organisation organisation, DateTime snapshotDate, ScopeStatuses scopeStatus) { var organisationScope = new OrganisationScope { Organisation = organisation, ScopeStatus = scopeStatus, ScopeStatusDate = VirtualDateTime.Now, SnapshotDate = snapshotDate, Status = ScopeRowStatuses.Active, StatusDetails = "Generated by the system" }; organisation.OrganisationScopes.Add(organisationScope); dataRepository.Insert(organisationScope); }
public async Task GetOrgScopeByEmployerReference_When_EmployerReference_Matches_Then_Return_OrganisationScope_ModelAsync() { // Arrange var testEmployerRef = "SNGNB4BH"; var testSnapshotYear = 2017; mockDataRepo.Setup(r => r.GetAll<Organisation>()).Returns(testOrgData.AsQueryable().BuildMock().Object); mockDataRepo.Setup(r => r.GetAll<OrganisationScope>()).Returns(testOrgScopeData.AsQueryable().BuildMock().Object); // Act OrganisationScope result = await testScopeBL.GetScopeByEmployerReferenceAsync(testEmployerRef, testSnapshotYear); // Assert Assert.That(result != null, "Expected to return a valid OrganisationScope Model"); Assert.That(result.OrganisationId == 4, "Expected the model to have the same OrganisationId"); Assert.That(result.OrganisationScopeId == 65, "Expected the model to have the same OrganisationScopeId"); }
/// <summary> /// Creates a new scope record using an existing scope and applies a new status /// </summary> /// <param name="existingOrgScopeId"></param> /// <param name="newStatus"></param> public virtual async Task <OrganisationScope> UpdateScopeStatusAsync(long existingOrgScopeId, ScopeStatuses newStatus) { var oldOrgScope = await _sharedBusinessLogic.DataRepository.FirstOrDefaultAsync <OrganisationScope>(os => os.OrganisationScopeId == existingOrgScopeId); // when OrganisationScope isn't found then throw ArgumentOutOfRangeException if (oldOrgScope == null) { throw new ArgumentOutOfRangeException( nameof(existingOrgScopeId), $"Cannot find organisation with OrganisationScopeId: {existingOrgScopeId}"); } var org = await _sharedBusinessLogic.DataRepository.FirstOrDefaultAsync <Organisation>(o => o.OrganisationId == oldOrgScope.OrganisationId); // when Organisation isn't found then throw ArgumentOutOfRangeException if (org == null) { throw new ArgumentOutOfRangeException( nameof(oldOrgScope.OrganisationId), $"Cannot find organisation with OrganisationId: {oldOrgScope.OrganisationId}"); } // When Organisation is Found Then Save New Scope Record With New Status var newScope = new OrganisationScope { OrganisationId = oldOrgScope.OrganisationId, ContactEmailAddress = oldOrgScope.ContactEmailAddress, ContactFirstname = oldOrgScope.ContactFirstname, ContactLastname = oldOrgScope.ContactLastname, ReadGuidance = oldOrgScope.ReadGuidance, Reason = oldOrgScope.Reason, ScopeStatus = newStatus, ScopeStatusDate = VirtualDateTime.Now, RegisterStatus = oldOrgScope.RegisterStatus, RegisterStatusDate = oldOrgScope.RegisterStatusDate, // carry the snapshot date over SnapshotDate = oldOrgScope.SnapshotDate }; await SaveScopeAsync(org, true, newScope); return(newScope); }
public virtual async Task <CustomResult <OrganisationScope> > AddScopeAsync(Organisation organisation, ScopeStatuses newStatus, User currentUser, int snapshotYear, string comment, bool saveToDatabase) { snapshotYear = _sharedBusinessLogic.GetAccountingStartDate(organisation.SectorType, snapshotYear) .Year; var oldOrgScope = organisation.GetScopeOrThrow(snapshotYear); if (oldOrgScope.ScopeStatus == newStatus) { return(new CustomResult <OrganisationScope>( InternalMessages.SameScopesCannotBeUpdated(newStatus, oldOrgScope.ScopeStatus, snapshotYear))); } // When Organisation is Found Then Save New Scope Record With New Status var newScope = new OrganisationScope { OrganisationId = oldOrgScope.OrganisationId, Organisation = organisation, /* Updated by the current user */ ContactEmailAddress = currentUser.EmailAddress, ContactFirstname = currentUser.Firstname, ContactLastname = currentUser.Lastname, ReadGuidance = oldOrgScope.ReadGuidance, Reason = !string.IsNullOrEmpty(comment) ? comment : oldOrgScope.Reason, ScopeStatus = newStatus, ScopeStatusDate = VirtualDateTime.Now, StatusDetails = _sharedBusinessLogic.AuthorisationBusinessLogic.IsAdministrator(currentUser) ? "Changed by Admin" : null, RegisterStatus = oldOrgScope.RegisterStatus, RegisterStatusDate = oldOrgScope.RegisterStatusDate, // carry the snapshot date over SnapshotDate = oldOrgScope.SnapshotDate }; await SaveScopeAsync(organisation, saveToDatabase, newScope); return(new CustomResult <OrganisationScope>(newScope)); }
public void DeclareScope_GET_When_PreviousInScope_Then_Return_BadRequest() { // Arrange var mockRouteData = new RouteData(); mockRouteData.Values.Add("Action", "DeclareScope"); mockRouteData.Values.Add("Controller", "Organisation"); var testUserId = 2; var testOrgId = 123; DateTime lastSnapshotDate = SectorTypes.Private.GetAccountingStartDate().AddYears(-1); var mockLastScope = new OrganisationScope { OrganisationId = testOrgId, Status = ScopeRowStatuses.Active, ScopeStatus = ScopeStatuses.InScope, SnapshotDate = lastSnapshotDate }; var controller = UiTestHelper.GetController <OrganisationController>( testUserId, mockRouteData, MockUsers, MockOrganisations, MockUserOrganisations, mockLastScope); Mock <IScopeBusinessLogic> mockScopeBL = AutoFacExtensions.ResolveAsMock <IScopeBusinessLogic>(true); string encOrgId = Encryption.EncryptQuerystring(testOrgId.ToString()); // Act IActionResult actionResult = controller.DeclareScope(encOrgId); // Assert Expect(actionResult != null, "actionResult should not be null"); // 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'"); }