예제 #1
0
        public async Task UpdateAccessPolicyPairing_AccessPolicyPairingsExist_AccessPolicyPairingIdAccurate(int id, int expectedScopeId, int expectedClaimId, int expectedAccessPolicyId)
        {
            // Arrange

            IAccessPolicyPairingRepository accessPolicyPairingRepository = new AccessPolicyPairingRepository(new SQLServerGateway(), new ConnectionStringData());

            AccessPolicyPairingModel accessPolicyPairingModel = new AccessPolicyPairingModel();

            accessPolicyPairingModel.Id             = id;
            accessPolicyPairingModel.ScopeId        = expectedScopeId;
            accessPolicyPairingModel.ClaimId        = expectedClaimId;
            accessPolicyPairingModel.AccessPolicyId = expectedAccessPolicyId;

            // Act
            await accessPolicyPairingRepository.UpdateAccessPolicyPairing(accessPolicyPairingModel);

            var actual = await accessPolicyPairingRepository.GetAccessPolicyPairingById(id);

            var actualScopeId        = actual.ScopeId;
            var actualClaimId        = actual.ClaimId;
            var actualAccessPolicyId = actual.AccessPolicyId;


            // Assert
            Assert.IsTrue(actualScopeId == expectedScopeId &&
                          actualClaimId == expectedClaimId &&
                          actualAccessPolicyId == expectedAccessPolicyId);
        }
예제 #2
0
        public async Task Init()
        {
            await TestCleaner.CleanDatabase();

            var numTestRows = 20;

            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IScopeRepository               scopeRepository               = new ScopeRepository(dataGateway, connectionString);
            IResourceRepository            resourceRepository            = new ResourceRepository(dataGateway, connectionString);
            IClaimRepository               claimRepository               = new ClaimRepository(dataGateway, connectionString);
            IAccessPolicyRepository        accessPolicyRepository        = new AccessPolicyRepository(dataGateway, connectionString);
            IAccessPolicyPairingRepository accessPolicyPairingRepository = new AccessPolicyPairingRepository(dataGateway, connectionString);


            for (int i = 1; i <= numTestRows; ++i)
            {
                ResourceModel resourceModel = new ResourceModel();
                resourceModel.Id   = i;
                resourceModel.Name = "TestResource" + i;

                ScopeModel scopeModel = new ScopeModel();
                scopeModel.Id          = i;
                scopeModel.Type        = "TestScope" + i;
                scopeModel.Description = "TestDescription" + i;

                ClaimModel claimModel = new ClaimModel();
                claimModel.Id        = i;
                claimModel.Type      = "TestClaim" + i;
                claimModel.Value     = "TestDescription" + i;
                claimModel.IsDefault = true;

                var resourceId = await resourceRepository.CreateResource(resourceModel);

                var claimId = await claimRepository.CreateClaim(claimModel);

                var scopeId = await scopeRepository.CreateScope(scopeModel);

                AccessPolicyModel accessPolicyModel = new AccessPolicyModel();
                accessPolicyModel.Id         = i;
                accessPolicyModel.Name       = "TestAccessPolicy" + i;
                accessPolicyModel.ResourceId = resourceId;
                accessPolicyModel.Priority   = i % 4;

                var accessPolicyId = await accessPolicyRepository.CreateAccessPolicy(accessPolicyModel);

                AccessPolicyPairingModel accessPolicyPairingModel = new AccessPolicyPairingModel();
                accessPolicyPairingModel.Id             = i;
                accessPolicyPairingModel.ScopeId        = scopeId;
                accessPolicyPairingModel.ClaimId        = claimId;
                accessPolicyPairingModel.AccessPolicyId = accessPolicyId;

                await accessPolicyPairingRepository.CreateAccessPolicyPairing(accessPolicyPairingModel);
            }
        }
예제 #3
0
        public async Task <int> UpdateAccessPolicyPairing(AccessPolicyPairingModel model)
        {
            var storedProcedure = "dbo.AccessPolicyPairing_Update";

            return(await _dataGateway.Execute(storedProcedure,
                                              new
            {
                Id = model.Id,
                scopeId = model.ScopeId,
                claimId = model.ClaimId,
                accessPolicyId = model.AccessPolicyId
            },
                                              _connectionString.SqlConnectionString));
        }
예제 #4
0
        public async Task <int> CreateAccessPolicyPairing(AccessPolicyPairingModel model)
        {
            var storedProcedure = "dbo.AccessPolicyPairing_Create";

            DynamicParameters p = new DynamicParameters();

            p.Add("scopeId", model.ScopeId);
            p.Add("claimId", model.ClaimId);
            p.Add("accessPolicyId", model.AccessPolicyId);

            p.Add("Id", DbType.Int32, direction: ParameterDirection.Output);

            await _dataGateway.Execute(storedProcedure, p, _connectionString.SqlConnectionString);

            return(p.Get <int>("Id"));
        }