示例#1
0
        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();
        }
示例#2
0
        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);
        }
示例#3
0
        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();
        }
示例#4
0
        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);
        }