public async Task Functions_UpdateSearch_AddAllIndexes() { //ARRANGE //Ensure all orgs are in scope for current year IEnumerable <Organisation> orgs = _functions.SharedBusinessLogic.DataRepository.GetAll <Organisation>(); //Add a random number of in scope orgs var inScope = Numeric.Rand(1, orgs.Count()); OrganisationHelper.AddScopeStatus(ScopeStatuses.InScope, VirtualDateTime.Now.Year, orgs.Take(inScope).ToArray()); //Add returns to remaining orgs ReturnHelper.CreateTestReturns(orgs.Skip(inScope).ToArray(), VirtualDateTime.Now.Year); var log = new Mock <ILogger>(); orgs = orgs .Where( o => o.Status == OrganisationStatuses.Active && (o.Returns.Any(r => r.Status == ReturnStatuses.Submitted) || o.OrganisationScopes.Any( sc => sc.Status == ScopeRowStatuses.Active && (sc.ScopeStatus == ScopeStatuses.InScope || sc.ScopeStatus == ScopeStatuses.PresumedInScope)))) .ToList(); //ACT await _functions.UpdateSearchAsync(log.Object, "*****@*****.**", true); //ASSERT //Check for correct number of indexes var documentCount = await _functions.SearchBusinessLogic.EmployerSearchRepository.GetDocumentCountAsync(); Assert.That(documentCount == orgs.Count(), $"Expected '{documentCount}' indexes "); //Get the actual results var actualResults = await _functions.SearchBusinessLogic.EmployerSearchRepository.ListAsync(); //Generate the expected results var expectedResults = orgs.Select(o => EmployerSearchModel.Create(o)); //Check the results expectedResults.Compare(actualResults); }
public async Task AdminController_ReviewRequest_POST_ManualRegistration_ServiceActivated() { //ARRANGE: //create a user who does exist in the db var user = new User { UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now }; var org = new Core.Entities.Organisation { OrganisationId = 1, SectorType = SectorTypes.Private, Status = OrganisationStatuses.Pending }; //TODO: Refactoring to user the same Helpers (ie AddScopeStatus.AddScopeStatus) org.OrganisationScopes.Add( new OrganisationScope { Organisation = org, ScopeStatus = ScopeStatuses.InScope, SnapshotDate = org.SectorType.GetAccountingStartDate(VirtualDateTime.Now.Year), Status = ScopeRowStatuses.Active }); var address = new OrganisationAddress { AddressId = 1, OrganisationId = 1, Organisation = org, Status = AddressStatuses.Pending }; var userOrg = new UserOrganisation { UserId = 1, OrganisationId = 1, AddressId = address.AddressId, Address = address, User = user, Organisation = org }; var routeData = new RouteData(); routeData.Values.Add("Action", nameof(RegistrationController.OrganisationType)); routeData.Values.Add("Controller", "Registration"); var controller = UiTestHelper.GetController <AdminController>(user.UserId, routeData, user, org, address, userOrg); var model = new OrganisationViewModel { ReviewCode = userOrg.GetReviewCode() }; controller.StashModel(model); //ACT: var result = await controller.ReviewRequest(model, "approve") as RedirectToActionResult; //ASSERT: Assert.That(result != null, "Expected RedirectToActionResult"); Assert.That(result.ActionName == "RequestAccepted", "Expected redirect to RequestAccepted"); Assert.That(userOrg.PINConfirmedDate > DateTime.MinValue); Assert.That(userOrg.Organisation.Status == OrganisationStatuses.Active); Assert.That(userOrg.Organisation.LatestAddress.AddressId == address.AddressId); Assert.That(!string.IsNullOrWhiteSpace(userOrg.Organisation.EmployerReference)); Assert.That(address.Status == AddressStatuses.Active); //Check the organisation exists in search EmployerSearchModel actualIndex = await controller.AdminService.SearchBusinessLogic.EmployerSearchRepository.GetAsync(org.OrganisationId.ToString()); EmployerSearchModel expectedIndex = EmployerSearchModel.Create(org); expectedIndex.Compare(actualIndex); }