public void GetNextAvailableVacancyShouldReturnNullIfThereIsntAnyMoreVacancies()
        {
            var            vacancyPostingService = new Mock <IVacancyPostingService>();
            var            vacancyLockingService = new Mock <IVacancyLockingService>();
            var            providerService       = new Mock <IProviderService>();
            VacancySummary vacancySummary        = null;

            int total;

            vacancyPostingService.Setup(
                avr => avr.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total))
            .Returns(new List <VacancySummary>());

            vacancyLockingService.Setup(
                vls => vls.GetNextAvailableVacancy(It.IsAny <string>(), It.IsAny <List <VacancySummary> >()))
            .Returns(vacancySummary);

            providerService.Setup(ps => ps.GetProvider(It.IsAny <int>())).Returns(new Provider());

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacancyLockingService)
                .With(providerService)
                .Build();

            var result = vacancyProvider.GetNextAvailableVacancy();

            result.Should().BeNull();
        }
예제 #2
0
        public void UpdateVacancyBasicDetailsShouldExpectVacancyReferenceNumber()
        {
            //Arrange
            var newVacancyVM = new Fixture().Build <NewVacancyViewModel>()
                               .With(vm => vm.VacancyReferenceNumber, null)
                               .Create();

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var providerService       = new Mock <IProviderService>();
            var configurationService  = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });

            var vacancyProvider =
                new VacancyProviderBuilder().With(vacancyPostingService)
                .With(providerService)
                .With(configurationService)
                .Build();

            //Act
            Action action = () => vacancyProvider.UpdateVacancyWithComments(newVacancyVM);

            //Assert
            action.ShouldThrow <ArgumentNullException>();
        }
        public void GetNextAvailableVacancyShouldReturnTheNextVacancyIfThereIsAnyAvailable()
        {
            const int vacancyReferenceNumber = 1;

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var vacancyLockingService = new Mock <IVacancyLockingService>();
            var providerService       = new Mock <IProviderService>();
            var vacancySummary        = new VacancySummary {
                VacancyReferenceNumber = vacancyReferenceNumber
            };

            int total;

            vacancyPostingService.Setup(
                avr => avr.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total))
            .Returns(new List <VacancySummary>());

            vacancyLockingService.Setup(
                vls => vls.GetNextAvailableVacancy(It.IsAny <string>(), It.IsAny <List <VacancySummary> >()))
            .Returns(vacancySummary);

            providerService.Setup(ps => ps.GetProvider(It.IsAny <int>())).Returns(new Provider());

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacancyLockingService)
                .With(providerService)
                .Build();

            var result = vacancyProvider.GetNextAvailableVacancy();

            result.VacancyReferenceNumber.Should().Be(vacancyReferenceNumber);
        }
        public void ShouldReturnInvalidVacancyIfTheUserCantQATheVacancy()
        {
            const int    vacanyReferenceNumber = 1;
            const string userName = "******";

            var requirementsProspectsViewModel = new Fixture().Build <VacancyRequirementsProspectsViewModel>().Create();

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var currentUserService    = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            vacancyPostingService.Setup(vps => vps.GetVacancyByReferenceNumber(vacanyReferenceNumber))
            .Returns(new Vacancy {
                VacancyReferenceNumber = vacanyReferenceNumber
            });
            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, It.IsAny <Vacancy>()))
            .Returns(false);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .With(currentUserService)
                .Build();

            var result = vacancyProvider.UpdateVacancyWithComments(requirementsProspectsViewModel);

            result.Code.Should().Be(QAActionResultCode.InvalidVacancy);
            result.ViewModel.Should().BeNull();
        }
        public void ShouldReturnInvalidVacancyIfTheUserCantQATheVacancy()
        {
            const int    vacanyReferenceNumber = 1;
            const string userName = "******";

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var currentUserService    = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            vacancyPostingService.Setup(vps => vps.GetVacancyByReferenceNumber(vacanyReferenceNumber))
            .Returns(new Vacancy {
                VacancyReferenceNumber = vacanyReferenceNumber
            });
            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, It.IsAny <Vacancy>()))
            .Returns(false);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .With(currentUserService)
                .Build();

            var result = vacancyProvider.ApproveVacancy(vacanyReferenceNumber);

            result.Should().Be(QAActionResultCode.InvalidVacancy);
        }
예제 #6
0
        public void GetVacanciesSummaryForProviderShouldCallVacancySummaryService()
        {
            const int         providerId     = 1;
            const int         providerSiteId = 2;
            const int         employerId     = 3;
            const VacancyType vacancyType    = VacancyType.Apprenticeship;

            var search = new VacanciesSummarySearchViewModel
            {
                PageSize    = 5,
                VacancyType = vacancyType
            };

            var vacancySummaryService = new Mock <IVacancySummaryService>();
            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <VacancySummary, VacancySummaryViewModel>(It.IsAny <VacancySummary>()))
            .Returns(new VacancySummaryViewModel
            {
                VacancyOwnerRelationshipId = employerId,
                VacancyId = 0
            });


            int tmp;

            vacancySummaryService.Setup(s => s.GetSummariesForProvider(It.IsAny <VacancySummaryQuery>(), out tmp))
            .Returns(
                new List <VacancySummary>()
            {
                new VacancySummary()
                {
                    VacancyType = VacancyType.Apprenticeship,
                    Title       = "Test",
                    Address     = new PostalAddress()
                    {
                        Town = "Test"
                    }
                }
            });

            vacancySummaryService.Setup(s => s.GetLotteryCounts(It.IsAny <VacancySummaryQuery>())).Returns(
                new VacancyCounts()
            {
                RejectedCount = 1
            });

            var provider = new VacancyProviderBuilder()
                           .With(mapper)
                           .With(vacancySummaryService)
                           .BuildVacancyPostingProvider();

            provider.GetVacanciesSummaryForProvider(providerId, providerSiteId, search);

            vacancySummaryService.Verify(s => s.GetSummariesForProvider(It.IsAny <VacancySummaryQuery>(), out tmp), Times.Once);
        }
        public void ApproveMultilocationVacancyShouldReturnErrorIfGeoCodeVacancyFails(int locationAddressCount)
        {
            //Arrange
            const int vacancyReferenceNumber = 1;
            const int parentVacancyId        = 2;
            var       locationAddresses      = new Fixture().Build <VacancyLocation>()
                                               .CreateMany(locationAddressCount).ToList();

            foreach (var locationAddress in locationAddresses)
            {
                locationAddress.Address.GeoPoint.Easting   = 0;
                locationAddress.Address.GeoPoint.Northing  = 0;
                locationAddress.Address.GeoPoint.Latitude  = 0;
                locationAddress.Address.GeoPoint.Longitude = 0;
            }

            var vacancy = new Fixture().Build <Vacancy>()
                          .With(x => x.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(x => x.IsEmployerLocationMainApprenticeshipLocation, false)
                          .With(x => x.VacancyId, parentVacancyId)
                          .Create();

            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var geocodingService      = new Mock <IGeoCodeLookupService>();

            vacancyPostingService.Setup(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(vacancy);
            vacancyPostingService.Setup(s => s.GetVacancyLocations(vacancy.VacancyId)).Returns(locationAddresses);
            geocodingService.Setup(s => s.GetGeoPointFor(It.IsAny <PostalAddress>()))
            .Throws(new CustomException(Application.Interfaces.Locations.ErrorCodes.GeoCodeLookupProviderFailed));

            //set up so that a bunch of vacancy reference numbers are created that are not the same as the one supplied above
            var fixture = new Fixture {
                RepeatCount = locationAddressCount - 1
            };
            var vacancyNumbers = fixture.Create <List <int> >();

            vacancyPostingService.Setup(r => r.GetNextVacancyReferenceNumber()).ReturnsInOrder(vacancyNumbers.ToArray());

            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(It.IsAny <string>(), It.IsAny <Vacancy>()))
            .Returns(true);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .With(geocodingService)
                .Build();

            //Act
            var result = vacancyProvider.ApproveVacancy(vacancyReferenceNumber);

            //Assert
            result.Should().Be(QAActionResultCode.GeocodingFailure);
        }
        public void ApproveVacancyShoulReturnErrorIfGeocodeServiceFails()
        {
            //Arrange
            const int vacancyReferenceNumber = 1;
            var       address = new PostalAddress
            {
                Postcode = "CV1 2WT"
            };
            var vacancy = new Fixture().Build <Vacancy>()
                          .With(x => x.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(x => x.IsEmployerLocationMainApprenticeshipLocation, true)
                          .With(x => x.Address, address)
                          .Create();

            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var configurationService  = new Mock <IConfigurationService>();
            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var geocodingService      = new Mock <IGeoCodeLookupService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });

            vacancyPostingService.Setup(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(It.IsAny <string>(), It.IsAny <Vacancy>()))
            .Returns(true);

            geocodingService.Setup(s => s.GetGeoPointFor(address))
            .Throws(new CustomException(Application.Interfaces.Locations.ErrorCodes.GeoCodeLookupProviderFailed));

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(configurationService)
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .With(geocodingService)
                .Build();

            //Act
            var result = vacancyProvider.ApproveVacancy(vacancyReferenceNumber);

            //Assert
            result.Should().Be(QAActionResultCode.GeocodingFailure);
        }
예제 #9
0
        public void RejectVacancy()
        {
            //Arrange
            var vacancyReferenceNumber = 1;
            var vacancy = new Fixture().Build <Vacancy>()
                          .With(x => x.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(x => x.IsEmployerLocationMainApprenticeshipLocation, true)
                          .Create();

            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var configurationService  = new Mock <IConfigurationService>();
            var vacancyPostingService = new Mock <IVacancyPostingService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });

            vacancyPostingService.Setup(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(It.IsAny <string>(), It.IsAny <Vacancy>()))
            .Returns(true);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(configurationService)
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .Build();

            //Act
            var result = vacancyProvider.RejectVacancy(vacancyReferenceNumber);

            //Assert
            result.Should().Be(QAActionResultCode.Ok);
            vacancyPostingService.Verify(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber));
            vacancyPostingService.Verify(
                r =>
                r.UpdateVacancy(
                    It.Is <Vacancy>(
                        av =>
                        av.VacancyReferenceNumber == vacancyReferenceNumber &&
                        av.Status == VacancyStatus.Referred)));
        }
        public void ApproveVacancyShouldCallGeocodeServiceIfAddressIsNotGeocoded()
        {
            //Arrange
            const int vacancyReferenceNumber = 1;
            var       address = new PostalAddress
            {
                Postcode = "CV1 2WT"
            };
            var vacancy = new Fixture().Build <Vacancy>()
                          .With(x => x.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(x => x.IsEmployerLocationMainApprenticeshipLocation, true)
                          .With(x => x.Address, address)
                          .Create();

            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var configurationService  = new Mock <IConfigurationService>();
            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var geocodingService      = new Mock <IGeoCodeLookupService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });

            vacancyPostingService.Setup(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(It.IsAny <string>(), It.IsAny <Vacancy>()))
            .Returns(true);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(configurationService)
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .With(geocodingService)
                .Build();

            //Act
            var result = vacancyProvider.ApproveVacancy(vacancyReferenceNumber);

            //Assert
            geocodingService.Verify(s => s.GetGeoPointFor(address));
        }
예제 #11
0
        public void ShouldReturnOKIfTheUserCanLockTheVacancy()
        {
            //Arrange
            const string ukprn    = "ukprn";
            const string userName = "******";
            var          utcNow   = DateTime.UtcNow;

            var newVacancyVM = new Fixture().Build <NewVacancyViewModel>().Create();
            var vacancy      = new Fixture().Build <Vacancy>()
                               .With(av => av.VacancyReferenceNumber, newVacancyVM.VacancyReferenceNumber.Value)
                               .With(av => av.OfflineApplicationInstructionsComment, Guid.NewGuid().ToString())
                               .With(av => av.OfflineApplicationUrlComment, Guid.NewGuid().ToString())
                               .With(av => av.ShortDescriptionComment, Guid.NewGuid().ToString())
                               .With(av => av.TitleComment, Guid.NewGuid().ToString())
                               .With(av => av.OfflineApplicationUrl, $"http://www.google.com/{Guid.NewGuid()}")
                               .With(av => av.OfflineApplicationInstructions, Guid.NewGuid().ToString())
                               .With(av => av.ShortDescription, Guid.NewGuid().ToString())
                               .With(av => av.Title, Guid.NewGuid().ToString())
                               .Create();

            var sectorList = new List <Sector>
            {
                new Fixture().Build <Sector>().Create()
            };

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var providerService       = new Mock <IProviderService>();
            var configurationService  = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });
            configurationService.Setup(x => x.Get <RecruitWebConfiguration>())
            .Returns(new RecruitWebConfiguration {
                AutoSaveTimeoutInSeconds = 60
            });
            var referenceDataService = new Mock <IReferenceDataService>();

            referenceDataService.Setup(m => m.GetSectors()).Returns(sectorList);
            providerService.Setup(ps => ps.GetProvider(ukprn, true)).Returns(new Provider());
            var currentUserService = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            var dateTimeService = new Mock <IDateTimeService>();

            dateTimeService.Setup(dts => dts.UtcNow).Returns(utcNow);
            var vacancylockingService = new Mock <IVacancyLockingService>();

            vacancylockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, vacancy)).Returns(true);

            //Arrange: get AV, update retrieved AV with NVVM, save modified AV returning same modified AV, map AV to new NVVM with same properties as input
            vacancyPostingService.Setup(
                vps => vps.GetVacancyByReferenceNumber(newVacancyVM.VacancyReferenceNumber.Value)).Returns(vacancy);

            vacancyPostingService.Setup(vps => vps.UpdateVacancy(It.IsAny <Vacancy>())).Returns((Vacancy av) => av);

            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => newVacancyVM);

            var vacancyProvider =
                new VacancyProviderBuilder().With(vacancyPostingService)
                .With(providerService)
                .With(configurationService)
                .With(referenceDataService)
                .With(mapper)
                .With(currentUserService)
                .With(dateTimeService)
                .With(vacancylockingService)
                .Build();

            var expectedResult = new QAActionResult <NewVacancyViewModel>(QAActionResultCode.Ok, newVacancyVM);

            //Act
            var result = vacancyProvider.UpdateVacancyWithComments(newVacancyVM);

            //Assert
            vacancyPostingService.Verify(
                vps => vps.GetVacancyByReferenceNumber(newVacancyVM.VacancyReferenceNumber.Value), Times.Once);
            vacancyPostingService.Verify(
                vps =>
                vps.UpdateVacancy(
                    It.Is <Vacancy>(av => av.VacancyReferenceNumber == newVacancyVM.VacancyReferenceNumber.Value &&
                                    av.QAUserName == userName && av.DateStartedToQA == utcNow)));
            result.ShouldBeEquivalentTo(expectedResult);
        }
        public void GetVacanciesPendingQAShouldCallRepositoryWithPendingQAAsDesiredStatus()
        {
            //Arrange
            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var providerService       = new Mock <IProviderService>();
            var configurationService  = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });

            int total;

            vacancyPostingService.Setup(
                avr => avr.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total))
            .Returns(new List <VacancySummary>
            {
                new VacancySummary
                {
                    ClosingDate     = DateTime.Now,
                    DateSubmitted   = DateTime.Now,
                    ContractOwnerId = ProviderId,
                    Status          = VacancyStatus.Submitted
                }
            });

            var metrics = new List <RegionalTeamMetrics>()
            {
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.EastAnglia
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.EastMidlands
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.North
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.NorthWest
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.SouthEast
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.SouthWest
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.WestMidlands
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.YorkshireAndHumberside
                },
            };

            vacancyPostingService.Setup(p => p.GetRegionalTeamsMetrics(It.IsAny <VacancySummaryByStatusQuery>())).Returns(metrics);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(providerService)
                .With(vacancyPostingService)
                .With(configurationService)
                .Build();

            //Act
            vacancyProvider.GetPendingQAVacancies();

            //Assert
            vacancyPostingService.Verify(avr => avr.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total));
            vacancyPostingService.Verify(avr => avr.GetRegionalTeamsMetrics(It.IsAny <VacancySummaryByStatusQuery>()));
        }
        public void ShouldReturnOKIfTheUserCanLockTheVacancy()
        {
            //Arrange
            const string userName = "******";
            var          utcNow   = DateTime.UtcNow;
            const int    vacancyReferenceNumber = 1;
            const string aString = "aString";

            var viewModel = new VacancyQuestionsViewModel
            {
                FirstQuestion            = aString,
                SecondQuestion           = aString,
                FirstQuestionComment     = aString,
                SecondQuestionComment    = aString,
                VacancyReferenceNumber   = vacancyReferenceNumber,
                AutoSaveTimeoutInSeconds = 60
            };

            var vacancy = new Fixture().Build <Vacancy>()
                          .With(av => av.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(av => av.FirstQuestion, aString)
                          .With(av => av.SecondQuestion, aString)
                          .With(av => av.FirstQuestionComment, aString)
                          .With(av => av.SecondQuestionComment, aString)
                          .Create();

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var currentUserService    = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            var dateTimeService = new Mock <IDateTimeService>();

            dateTimeService.Setup(dts => dts.UtcNow).Returns(utcNow);
            var vacancylockingService = new Mock <IVacancyLockingService>();

            vacancylockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, vacancy)).Returns(true);
            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <RecruitWebConfiguration>())
            .Returns(new RecruitWebConfiguration {
                AutoSaveTimeoutInSeconds = 60
            });

            //Arrange: get AV, update retrieved AV with NVVM, save modified AV returning same modified AV, map AV to new NVVM with same properties as input
            vacancyPostingService.Setup(
                vps => vps.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacancyPostingService.Setup(vps => vps.UpdateVacancy(It.IsAny <Vacancy>())).Returns((Vacancy av) => av);

            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <Vacancy, VacancyQuestionsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => viewModel);

            var vacancyProvider =
                new VacancyProviderBuilder().With(vacancyPostingService)
                .With(mapper)
                .With(currentUserService)
                .With(dateTimeService)
                .With(vacancylockingService)
                .With(configurationService)
                .Build();

            var expectedResult = new QAActionResult <VacancyQuestionsViewModel>(QAActionResultCode.Ok, viewModel);

            //Act
            var result = vacancyProvider.UpdateVacancyWithComments(viewModel);

            //Assert
            vacancyPostingService.Verify(
                vps => vps.GetVacancyByReferenceNumber(viewModel.VacancyReferenceNumber), Times.Once);
            vacancyPostingService.Verify(
                vps =>
                vps.UpdateVacancy(
                    It.Is <Vacancy>(av => av.VacancyReferenceNumber == viewModel.VacancyReferenceNumber &&
                                    av.QAUserName == userName && av.DateStartedToQA == utcNow)));
            result.ShouldBeEquivalentTo(expectedResult);
        }
예제 #14
0
        public static VacancyProviderBuilder GetBasicVacancyProviderBuilder(string userName, params int[] vacancyReferenceNumbers)
        {
            var currentUserService = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);

            var postingService = new Mock <IVacancyPostingService>();

            postingService.Setup(ps => ps.GetVacancyLocations(It.IsAny <int>())).Returns(new List <VacancyLocation>());

            int total;

            postingService.Setup(ps => ps.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total))
            .Returns(new List <VacancySummary>());

            foreach (var vacancyReferenceNumber in vacancyReferenceNumbers)
            {
                var vacancy = new Vacancy {
                    VacancyReferenceNumber = vacancyReferenceNumber
                };
                postingService.Setup(ps => ps.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(vacancy);
                postingService.Setup(ps => ps.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);
            }

            var vacancyLockingService = new Mock <IVacancyLockingService>();

            vacancyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, It.IsAny <VacancySummary>()))
            .Returns(true);

            var providerService = new Mock <IProviderService>();

            providerService.Setup(ps => ps.GetVacancyOwnerRelationship(It.IsAny <int>(), true)).Returns(new VacancyOwnerRelationship());
            providerService.Setup(ps => ps.GetProviderSite(It.IsAny <int>()))
            .Returns(new ProviderSite {
                Address = new PostalAddress()
            });

            var employerService = new Mock <IEmployerService>();

            employerService.Setup(es => es.GetEmployer(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(new Employer {
                Address = new PostalAddress()
            });

            var mapper = new Mock <IMapper>();

            foreach (var vacancyReferenceNumber in vacancyReferenceNumbers)
            {
                mapper.Setup(m => m.Map <Vacancy, VacancyViewModel>(It.IsAny <Vacancy>())).Returns(new VacancyViewModel
                {
                    VacancyReferenceNumber   = vacancyReferenceNumber,
                    NewVacancyViewModel      = new NewVacancyViewModel(),
                    TrainingDetailsViewModel = new TrainingDetailsViewModel()
                });
            }

            var vacancyProviderBuilder =
                new VacancyProviderBuilder().With(employerService)
                .With(providerService)
                .With(vacancyLockingService)
                .With(postingService)
                .With(currentUserService)
                .With(mapper);

            return(vacancyProviderBuilder);
        }
        public void ApproveMultilocationVacancy(int locationAddressCount)
        {
            //Arrange
            var vacancyReferenceNumber = 1;
            var parentVacancyId        = 2;
            var locationAddresses      = new Fixture().Build <VacancyLocation>()
                                         .CreateMany(locationAddressCount).ToList();

            var vacancy = new Fixture().Build <Vacancy>()
                          .With(x => x.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(x => x.IsEmployerLocationMainApprenticeshipLocation, false)
                          .With(x => x.VacancyId, parentVacancyId)
                          .Create();

            var vacanyLockingService  = new Mock <IVacancyLockingService>();
            var vacancyPostingService = new Mock <IVacancyPostingService>();

            vacancyPostingService.Setup(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(vacancy);
            vacancyPostingService.Setup(s => s.GetVacancyLocations(vacancy.VacancyId)).Returns(locationAddresses);

            //set up so that a bunch of vacancy reference numbers are created that are not the same as the one supplied above
            var fixture = new Fixture {
                RepeatCount = locationAddressCount - 1
            };
            var vacancyNumbers = fixture.Create <List <int> >();

            vacancyPostingService.Setup(r => r.GetNextVacancyReferenceNumber()).ReturnsInOrder(vacancyNumbers.ToArray());

            vacanyLockingService.Setup(vls => vls.IsVacancyAvailableToQABy(It.IsAny <string>(), It.IsAny <Vacancy>()))
            .Returns(true);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(vacancyPostingService)
                .With(vacanyLockingService)
                .Build();

            //Act
            vacancyProvider.ApproveVacancy(vacancyReferenceNumber);

            //Assert
            //get the submitted vacancy once
            vacancyPostingService.Verify(r => r.GetVacancyByReferenceNumber(vacancyReferenceNumber), Times.Once);
            //save the original vacancy with a status of Live and itself as a parent vacancy
            vacancyPostingService.Verify(
                r =>
                r.UpdateVacancy(
                    It.Is <Vacancy>(
                        av =>
                        av.VacancyReferenceNumber == vacancyReferenceNumber &&
                        av.Status == VacancyStatus.Live &&
                        av.ParentVacancyId == parentVacancyId &&
                        av.IsEmployerLocationMainApprenticeshipLocation.Value &&
                        av.Address.Postcode == locationAddresses.First().Address.Postcode&&
                        av.Address.AddressLine1 == locationAddresses.First().Address.AddressLine1&&
                        av.Address.AddressLine2 == locationAddresses.First().Address.AddressLine2&&
                        av.Address.AddressLine3 == locationAddresses.First().Address.AddressLine3&&
                        av.Address.AddressLine4 == locationAddresses.First().Address.AddressLine4&&
                        av.Address.AddressLine5 == locationAddresses.First().Address.AddressLine5&&
                        av.NumberOfPositions == locationAddresses.First().NumberOfPositions)));

            //save new vacancies with a status of Live
            foreach (var number in vacancyNumbers)
            {
                vacancyPostingService.Verify(r =>
                                             r.CreateVacancy(It.Is <Vacancy>(av => av.VacancyReferenceNumber == number &&
                                                                             av.Status == VacancyStatus.Live &&
                                                                             av.ParentVacancyId ==
                                                                             parentVacancyId &&
                                                                             av.IsEmployerLocationMainApprenticeshipLocation
                                                                             .Value)), Times.Once);
            }

            //save new vacancies with only one of the new addresses and the position count
            foreach (var location in locationAddresses.Skip(1))
            {
                vacancyPostingService.Verify(r => r.CreateVacancy(It.Is <Vacancy>(av
                                                                                  => av.Address.Postcode == location.Address.Postcode &&
                                                                                  av.Address.AddressLine1 == location.Address.AddressLine1 &&
                                                                                  av.Address.AddressLine2 == location.Address.AddressLine2 &&
                                                                                  av.Address.AddressLine3 == location.Address.AddressLine3 &&
                                                                                  av.Address.AddressLine4 == location.Address.AddressLine4 &&
                                                                                  av.Address.AddressLine5 == location.Address.AddressLine5 &&
                                                                                  av.NumberOfPositions == location.NumberOfPositions)));
            }

            //save the submitted vacancy once
            vacancyPostingService.Verify(r => r.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once);

            //Create each child vacancy once
            vacancyPostingService.Verify(r => r.CreateVacancy(It.IsAny <Vacancy>()),
                                         Times.Exactly(locationAddressCount - 1));

            vacancyPostingService.Verify(s => s.DeleteVacancyLocationsFor(vacancy.VacancyId));
        }
        public void GetPendingQAVacanciesOverviewShouldGetSubmittedAndReservedForQAVacanciesFromVacancyPostingService()
        {
            // Arrange
            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var providerService       = new Mock <IProviderService>();

            int total;

            vacancyPostingService.Setup(
                avr => avr.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total))
            .Returns(new List <VacancySummary>());

            var metrics = new List <RegionalTeamMetrics>()
            {
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.EastAnglia
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.EastMidlands
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.North
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.NorthWest
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.SouthEast
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.SouthWest
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.WestMidlands
                },
                new RegionalTeamMetrics()
                {
                    RegionalTeam = RegionalTeam.YorkshireAndHumberside
                },
            };

            vacancyPostingService.Setup(p => p.GetRegionalTeamsMetrics(It.IsAny <VacancySummaryByStatusQuery>())).Returns(metrics);

            var vacancyProvider =
                new VacancyProviderBuilder()
                .With(providerService)
                .With(vacancyPostingService)
                .Build();

            //Act
            vacancyProvider.GetPendingQAVacanciesOverview(new DashboardVacancySummariesSearchViewModel());

            // Assert
            vacancyPostingService.Verify(vps => vps.GetWithStatus(It.IsAny <VacancySummaryByStatusQuery>(), out total), Times.Once);
            vacancyPostingService.Verify(vps => vps.GetRegionalTeamsMetrics(It.IsAny <VacancySummaryByStatusQuery>()), Times.Once);
        }
        public void ShouldReturnOKIfTheUserCanLockTheVacancy()
        {
            //Arrange
            const string ukprn = "ukprn";
            //const int QAVacancyTimeout = 10;
            const string userName = "******";
            var          utcNow   = DateTime.UtcNow;
            const int    vacancyReferenceNumber = 1;
            const string aString = "aString";
            const int    autoSaveTimeoutInSeconds = 60;

            var sectorList = new List <Sector>
            {
                new Fixture().Build <Sector>().Create()
            };

            var viewModel = new VacancyRequirementsProspectsViewModel
            {
                VacancyReferenceNumber   = vacancyReferenceNumber,
                DesiredQualifications    = aString,
                AutoSaveTimeoutInSeconds = autoSaveTimeoutInSeconds
            };

            var vacancy = new Fixture().Build <Vacancy>()
                          .With(av => av.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(av => av.DesiredQualifications, aString)
                          .Create();

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });
            configurationService.Setup(x => x.Get <RecruitWebConfiguration>())
            .Returns(new RecruitWebConfiguration {
                AutoSaveTimeoutInSeconds = autoSaveTimeoutInSeconds
            });
            var referenceDataService = new Mock <IReferenceDataService>();

            referenceDataService.Setup(m => m.GetSectors()).Returns(sectorList);
            var providerService = new Mock <IProviderService>();

            providerService.Setup(ps => ps.GetProvider(ukprn, true)).Returns(new Provider());

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var currentUserService    = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            var dateTimeService = new Mock <IDateTimeService>();

            dateTimeService.Setup(dts => dts.UtcNow).Returns(utcNow);
            var vacancylockingService = new Mock <IVacancyLockingService>();

            vacancylockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, vacancy)).Returns(true);

            //Arrange: get AV, update retrieved AV with NVVM, save modified AV returning same modified AV, map AV to new NVVM with same properties as input
            vacancyPostingService.Setup(
                vps => vps.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacancyPostingService.Setup(vps => vps.UpdateVacancy(It.IsAny <Vacancy>())).Returns((Vacancy av) => av);

            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <Vacancy, VacancyRequirementsProspectsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => viewModel);

            var vacancyProvider =
                new VacancyProviderBuilder().With(vacancyPostingService)
                .With(providerService)
                .With(configurationService)
                .With(referenceDataService)
                .With(mapper)
                .With(currentUserService)
                .With(dateTimeService)
                .With(vacancylockingService)
                .Build();

            var expectedResult = new QAActionResult <VacancyRequirementsProspectsViewModel>(QAActionResultCode.Ok, viewModel);

            //Act
            var result = vacancyProvider.UpdateVacancyWithComments(viewModel);

            //Assert
            vacancyPostingService.Verify(
                vps => vps.GetVacancyByReferenceNumber(viewModel.VacancyReferenceNumber), Times.Once);
            vacancyPostingService.Verify(
                vps =>
                vps.UpdateVacancy(
                    It.Is <Vacancy>(av => av.VacancyReferenceNumber == viewModel.VacancyReferenceNumber &&
                                    av.QAUserName == userName && av.DateStartedToQA == utcNow)));
            result.ShouldBeEquivalentTo(expectedResult);
        }
        public void ShouldReturnOKIfTheUserCanLockTheVacancy()
        {
            //Arrange
            const string ukprn = "ukprn";
            //const int QAVacancyTimeout = 10;
            const string userName = "******";
            var          utcNow   = DateTime.UtcNow;
            const int    vacancyReferenceNumber = 1;
            const string aString = "aString";
            const int    autoSaveTimeoutInSeconds = 60;

            var sectorList = new List <Sector>
            {
                new Fixture().Build <Sector>().Create()
            };

            var wage = new WageViewModel()
            {
                CustomType       = CustomWageType.Fixed,
                Amount           = null,
                AmountLowerBound = null,
                AmountUpperBound = null,
                Text             = null,
                Unit             = WageUnit.NotApplicable,
                HoursPerWeek     = null
            };
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                DurationComment       = aString,
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    PossibleStartDate = new DateViewModel(),
                    ClosingDate       = new DateViewModel()
                },
                VacancyReferenceNumber   = vacancyReferenceNumber,
                AutoSaveTimeoutInSeconds = autoSaveTimeoutInSeconds,
                Wage = wage
            };

            var vacancy = new Fixture().Build <Vacancy>()
                          .With(av => av.VacancyReferenceNumber, vacancyReferenceNumber)
                          .With(av => av.DurationComment, aString)
                          .Create();

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(x => x.Get <CommonWebConfiguration>())
            .Returns(new CommonWebConfiguration {
                BlacklistedCategoryCodes = ""
            });
            configurationService.Setup(x => x.Get <RecruitWebConfiguration>())
            .Returns(new RecruitWebConfiguration {
                AutoSaveTimeoutInSeconds = autoSaveTimeoutInSeconds
            });
            var referenceDataService = new Mock <IReferenceDataService>();

            referenceDataService.Setup(m => m.GetSectors()).Returns(sectorList);
            var providerService = new Mock <IProviderService>();

            providerService.Setup(ps => ps.GetProvider(ukprn, true)).Returns(new Provider());

            var vacancyPostingService = new Mock <IVacancyPostingService>();
            var currentUserService    = new Mock <ICurrentUserService>();

            currentUserService.Setup(cus => cus.CurrentUserName).Returns(userName);
            var dateTimeService = new Mock <IDateTimeService>();

            dateTimeService.Setup(dts => dts.UtcNow).Returns(utcNow);
            var vacancylockingService = new Mock <IVacancyLockingService>();

            vacancylockingService.Setup(vls => vls.IsVacancyAvailableToQABy(userName, vacancy)).Returns(true);

            //Arrange: get AV, update retrieved AV with NVVM, save modified AV returning same modified AV, map AV to new NVVM with same properties as input
            vacancyPostingService.Setup(
                vps => vps.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy);

            vacancyPostingService.Setup(vps => vps.UpdateVacancy(It.IsAny <Vacancy>())).Returns((Vacancy av) => av);

            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <Wage, WageViewModel>(It.IsAny <Wage>())).Returns(wage);
            mapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => viewModel);

            var vacancyProvider =
                new VacancyProviderBuilder().With(vacancyPostingService)
                .With(providerService)
                .With(configurationService)
                .With(referenceDataService)
                .With(mapper)
                .With(currentUserService)
                .With(dateTimeService)
                .With(vacancylockingService)
                .Build();

            //Act
            var result = vacancyProvider.UpdateVacancyWithComments(viewModel);

            //Assert
            vacancyPostingService.Verify(
                vps => vps.GetVacancyByReferenceNumber(viewModel.VacancyReferenceNumber), Times.Once);
            vacancyPostingService.Verify(
                vps =>
                vps.UpdateVacancy(
                    It.Is <Vacancy>(av => av.VacancyReferenceNumber == viewModel.VacancyReferenceNumber &&
                                    av.QAUserName == userName && av.DateStartedToQA == utcNow)));
            result.Code.Should().Be(QAActionResultCode.Ok);
        }