public void ShouldAuthoriseQaUserForAnyVacancy() { // Arrange. var providerId = new Random().Next(1, 100); var providerSiteId = new Random().Next(101, 200); var vacancy = new Vacancy { ContractOwnerId = providerId, VacancyManagerId = providerSiteId }; var mockCurrentUserService = new Mock <ICurrentUserService>(); var mockProviderService = new Mock <IProviderService>(); mockCurrentUserService.Setup(mock => mock.IsInRole(Roles.Raa)) .Returns(true); var service = new ProviderVacancyAuthorisationService(mockCurrentUserService.Object, mockProviderService.Object); // Act. Action action = () => service.Authorise(vacancy); // Assert. action.ShouldNotThrow(); }
public void ShouldNotAuthoriseProviderUserForVacancyForOtherProviderSite() { // Arrange. var ukprn = Convert.ToString(new Random().Next(1, 50)); var providerSiteId = new Random().Next(101, 200); var otherProviderSiteId = providerSiteId + 1; var provider = new Fixture().Create <Provider>(); var otherProviderId = provider.ProviderId + 1; var vacancy = new Vacancy { ContractOwnerId = otherProviderId, VacancyManagerId = providerSiteId }; var mockCurrentUserService = new Mock <ICurrentUserService>(); var mockProviderService = new Mock <IProviderService>(); mockCurrentUserService.Setup(mock => mock.IsInRole(Roles.Faa)) .Returns(true); mockCurrentUserService.Setup(mock => mock.GetClaimValue("ukprn")) .Returns(ukprn); mockProviderService.Setup(mock => mock .GetProvider(ukprn, true)) .Returns(provider); mockProviderService.Setup(mock => mock .GetProviderSites(ukprn)) .Returns(new List <ProviderSite> { new ProviderSite { ProviderSiteId = otherProviderSiteId } }); var service = new ProviderVacancyAuthorisationService(mockCurrentUserService.Object, mockProviderService.Object); // Act. Action action = () => service.Authorise(vacancy); // Assert. action .ShouldThrow <CustomException>() .Which.Code.Should().Be(Interfaces.ErrorCodes.ProviderVacancyAuthorisation.Failed); }
public void ShouldAuthoriseProviderUserForVacancyForOwnProviderSite() { // Arrange. var ukprn = Convert.ToString(new Random().Next(1, 50)); var subContractorProviderId = new Random().Next(51, 100); var providerSiteId = new Random().Next(101, 200); var provider = new Fixture().Create <Provider>(); var vacancy = new Vacancy { ContractOwnerId = subContractorProviderId, VacancyManagerId = providerSiteId }; var mockCurrentUserService = new Mock <ICurrentUserService>(); var mockProviderService = new Mock <IProviderService>(); mockCurrentUserService.Setup(mock => mock.IsInRole(Roles.Faa)) .Returns(true); mockCurrentUserService.Setup(mock => mock.GetClaimValue("ukprn")) .Returns(ukprn); mockProviderService.Setup(mock => mock .GetProvider(ukprn, true)) .Returns(provider); mockProviderService.Setup(mock => mock .GetProviderSites(ukprn)) .Returns(new List <ProviderSite> { new ProviderSite { ProviderSiteId = providerSiteId } }); var service = new ProviderVacancyAuthorisationService(mockCurrentUserService.Object, mockProviderService.Object); // Act. Action action = () => service.Authorise(vacancy); // Assert. action.ShouldNotThrow(); }
public void ShouldNotAuthoriseProviderWithInvalidUkprn() { // Arrange. var ukprn = Convert.ToString(new Random().Next(1, 50)); var vacancy = new Vacancy { ContractOwnerId = 1, VacancyManagerId = 2 }; var mockCurrentUserService = new Mock <ICurrentUserService>(); var mockProviderService = new Mock <IProviderService>(); mockCurrentUserService.Setup(mock => mock.IsInRole(Roles.Faa)) .Returns(true); mockCurrentUserService.Setup(mock => mock.GetClaimValue("ukprn")) .Returns(ukprn); mockProviderService.Setup(mock => mock .GetProvider(ukprn, true)) .Returns(default(Provider)); var service = new ProviderVacancyAuthorisationService(mockCurrentUserService.Object, mockProviderService.Object); // Act. Action action = () => service.Authorise(vacancy); // Assert. action .ShouldThrow <CustomException>() .Which.Code.Should().Be(Interfaces.ErrorCodes.ProviderVacancyAuthorisation.InvalidUkprn); }