예제 #1
0
        public async Task <IActionResult> EditClaim(ScopeClaimModel claimModel)
        {
            var claimScope = await _scopeService.Find(claimModel.ScopeName);

            if (claimScope == null)
            {
                ModelState.AddModelError("FindScope", $"Scope with the name {claimModel.ScopeName} could not be found.");
                return(PartialView("ScopeClaimList"));
            }

            var claimToRemove = claimScope.Claims.SingleOrDefault(scopeClaim => scopeClaim.Name == claimModel.ClaimId);

            if (claimToRemove == default(ScopeClaim))
            {
                ModelState.AddModelError("FindClaim", $"Claim with the name {claimModel.ClaimId} was not found in the scope {claimModel.ScopeName}");
                return(PartialView("ScopeClaimList"));
            }

            int index = claimScope.Claims.IndexOf(claimToRemove);

            claimScope.Claims[index] = claimModel.ScopeClaim;

            await _scopeService.Save(claimScope);

            var scopeModel = new ScopeModel(claimScope);

            ModelState.Clear();
            PartialViewResult partialViewResult = PartialView("ScopeClaimList", scopeModel);

            return(partialViewResult);
        }
        public async Task <int> UpdateScopeClaim(ScopeClaimModel model)
        {
            var storedProcedure = "dbo.ScopeClaim_Update";

            return(await _dataGateway.Execute(storedProcedure,
                                              new
            {
                Id = model.Id,
                scopeId = model.ScopeId,
                claimid = model.ClaimId,
            },
                                              _connectionString.SqlConnectionString));
        }
        public async Task <int> CreateScopeClaim(ScopeClaimModel model)
        {
            var storedProcedure = "dbo.ScopeClaim_Create";

            DynamicParameters p = new DynamicParameters();

            p.Add("scopeId", model.ScopeId);
            p.Add("claimId", model.ClaimId);
            p.Add("Id", DbType.Int32, direction: ParameterDirection.Output);

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

            return(p.Get <int>("Id"));
        }
예제 #4
0
        public async Task UpdateScopeClaim_ScopeClaimsExist_ScopeClaimIdsAccurate(int id, int expectedUpdatedScopeId, int expectedUpdatedClaimId)
        {
            // Arrange
            IScopeClaimRepository scopeClaimRepository = new ScopeClaimRepository(new SQLServerGateway(), new ConnectionStringData());
            ScopeClaimModel       scopeClaimModel      = new ScopeClaimModel();

            scopeClaimModel.Id      = id;
            scopeClaimModel.ScopeId = expectedUpdatedScopeId;
            scopeClaimModel.ClaimId = expectedUpdatedClaimId;

            // Act
            await scopeClaimRepository.UpdateScopeClaim(scopeClaimModel);

            var actual = await scopeClaimRepository.GetScopeClaimById(id);

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

            // Assert
            Assert.IsTrue(actualScopeId == expectedUpdatedScopeId &&
                          actualClaimId == expectedUpdatedClaimId);
        }
예제 #5
0
        public async Task Init()
        {
            await TestCleaner.CleanDatabase();

            var numTestRows = 20;

            IDataGateway          dataGateway          = new SQLServerGateway();
            IConnectionStringData connectionString     = new ConnectionStringData();
            IClaimRepository      claimRepository      = new ClaimRepository(dataGateway, connectionString);
            IScopeRepository      scopeRepository      = new ScopeRepository(dataGateway, connectionString);
            IScopeClaimRepository scopeClaimRepository = new ScopeClaimRepository(dataGateway, connectionString);

            for (int i = 1; i <= numTestRows; ++i)
            {
                ScopeClaimModel scopeClaimModel = new ScopeClaimModel();
                scopeClaimModel.Id      = i;
                scopeClaimModel.ScopeId = i;
                scopeClaimModel.ClaimId = i;

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

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

                await scopeRepository.CreateScope(scopeModel);

                await claimRepository.CreateClaim(claimModel);

                await scopeClaimRepository.CreateScopeClaim(scopeClaimModel);
            }
        }