public async Task Then_The_ProviderPermissions_Are_Returned_From_The_Repository_By_ProviderId(
            uint providerId,
            [Frozen] Mock <IProviderPermissionRepository> providerPermissionRepository,
            ProviderPermissionsService service)
        {
            //Arrange
            var providerPermissions = new List <Domain.Entities.ProviderPermission>
            {
                new Domain.Entities.ProviderPermission
                {
                    AccountId            = 1,
                    UkPrn                = providerId,
                    AccountLegalEntity   = new AccountLegalEntity(),
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account              = new Domain.Entities.Account {
                        Name = "test"
                    }
                }
            };

            providerPermissionRepository.Setup(x => x.GetByProviderId(providerId)).ReturnsAsync(providerPermissions);

            //Act
            await service.GetPermissionsByProviderId(providerId);

            //Assert
            providerPermissionRepository.Verify(x => x.GetByProviderId(providerId), Times.Once);
        }
Exemplo n.º 2
0
        public void Arrange()
        {
            _expectedEmployers = new List <Employer>
            {
                new Employer
                {
                    AccountId                        = 1,
                    AccountPublicHashedId            = "ABC111",
                    AccountName                      = "account 1",
                    AccountLegalEntityId             = 11,
                    AccountLegalEntityPublicHashedId = "DEF111",
                    AccountLegalEntityName           = "entity 1"
                },
                new Employer
                {
                    AccountId                        = 2,
                    AccountPublicHashedId            = "ABC222",
                    AccountName                      = "account 2",
                    AccountLegalEntityId             = 22,
                    AccountLegalEntityPublicHashedId = "DEF222",
                    AccountLegalEntityName           = "entity 2"
                }
            };

            _providerRelationsApiClient = new Mock <IProviderRelationshipsApiClient>();
            _providerPermissionsService = new ProviderPermissionsService(_providerRelationsApiClient.Object);

            _providerRelationsApiClient.Setup(c => c.GetAccountProviderLegalEntitiesWithPermission(
                                                  It.Is <GetAccountProviderLegalEntitiesWithPermissionRequest>(r =>
                                                                                                               r.Operation == Operation.CreateCohort &&
                                                                                                               r.Ukprn == ExpectedUkPrn), It.IsAny <CancellationToken>())).ReturnsAsync(new GetAccountProviderLegalEntitiesWithPermissionResponse
            {
                AccountProviderLegalEntities = new[]
                {
                    new AccountProviderLegalEntityDto
                    {
                        AccountId                        = 1,
                        AccountPublicHashedId            = "ABC111",
                        AccountLegalEntityId             = 11,
                        AccountLegalEntityPublicHashedId = "DEF111",
                        AccountLegalEntityName           = "entity 1",
                        AccountName                      = "account 1"
                    },
                    new AccountProviderLegalEntityDto
                    {
                        AccountId                        = 2,
                        AccountPublicHashedId            = "ABC222",
                        AccountLegalEntityId             = 22,
                        AccountLegalEntityPublicHashedId = "DEF222",
                        AccountLegalEntityName           = "entity 2",
                        AccountName                      = "account 2"
                    }
                }
            });
        }
        public async Task Then_Only_Non_Levy_Legal_Entities_With_Permissions_Are_Returned_And_Mapped_To_The_Domain_Object(
            uint providerId,
            string accountLegalEntityName,
            [Frozen] Mock <IProviderPermissionRepository> providerPermissionRepository,
            ProviderPermissionsService service)
        {
            //Arrange
            var providerPermissions = new List <Domain.Entities.ProviderPermission>
            {
                new Domain.Entities.ProviderPermission
                {
                    AccountId          = 1,
                    UkPrn              = providerId,
                    AccountLegalEntity = new AccountLegalEntity
                    {
                        AccountLegalEntityName = accountLegalEntityName
                    },
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account = new Domain.Entities.Account {
                        Name = "test", IsLevy = false
                    }
                },
                new Domain.Entities.ProviderPermission
                {
                    AccountId          = 1,
                    UkPrn              = providerId,
                    AccountLegalEntity = new AccountLegalEntity
                    {
                        AccountLegalEntityName = accountLegalEntityName
                    },
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account = new Domain.Entities.Account {
                        Name = "test", IsLevy = false
                    }
                },
                new Domain.Entities.ProviderPermission
                {
                    AccountId          = 1,
                    UkPrn              = providerId,
                    AccountLegalEntity = new AccountLegalEntity
                    {
                        AccountLegalEntityName = accountLegalEntityName
                    },
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account = new Domain.Entities.Account {
                        Name = "test", IsLevy = true
                    }
                },
                new Domain.Entities.ProviderPermission
                {
                    AccountId            = 1,
                    UkPrn                = providerId,
                    AccountLegalEntity   = null,
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account              = null
                },
                new Domain.Entities.ProviderPermission
                {
                    AccountId          = 1,
                    UkPrn              = providerId,
                    AccountLegalEntity = new AccountLegalEntity
                    {
                        AccountLegalEntityName = accountLegalEntityName
                    },
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = true,
                    Account = null
                },
                new Domain.Entities.ProviderPermission
                {
                    AccountId          = 1,
                    UkPrn              = providerId,
                    AccountLegalEntity = new AccountLegalEntity
                    {
                        AccountLegalEntityName = accountLegalEntityName
                    },
                    AccountLegalEntityId = 2,
                    CanCreateCohort      = false,
                    Account = new Domain.Entities.Account {
                        Name = "test", IsLevy = false
                    }
                }
            };

            providerPermissionRepository.Setup(x => x.GetByProviderId(providerId)).ReturnsAsync(providerPermissions);

            //Act
            var actual = await service.GetPermissionsByProviderId(providerId);

            //Assert
            Assert.AreEqual(2, actual.Count);
        }