Exemple #1
0
        public async Task <IActionResult> Edit(ApiScopeInputModel apiScopeInputModel, string button)
        {
            if (button == ControllerConstants.CANCEL)
            {
                return(RedirectToAction(nameof(Index)));
            }

            try
            {
                if (ModelState.IsValid)
                {
                    await ApiScopeService.UpsertApiScopeAsync(apiScopeInputModel);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (AlreadyExistsException ex)
            {
                ModelState.Merge(ex.ModelStateDictionary);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(ControllerConstants.ERROR, ex.Message);
            }

            return(View(apiScopeInputModel));
        }
Exemple #2
0
        public void GivenItHasANewApiScope_WhenItCallsInsertApiScopes_ThenShouldInsert()
        {
            // Given
            var apiScopeInputModel = new ApiScopeInputModel()
            {
                Name        = "API1",
                DisplayName = "API 1"
            };

            ApiScopeDataAccessMock
            .Setup(apiScopeDataAccess => apiScopeDataAccess.InsertAsync(It.IsAny <ApiScopeData>()))
            .Returns(Task.CompletedTask);

            // When
            ApiScopeService.UpsertApiScopeAsync(apiScopeInputModel).GetAwaiter().GetResult();

            // Then
            ApiScopeDataAccessMock.Verify(dataAccess => dataAccess.InsertAsync(It.IsAny <ApiScopeData>()), Times.Once);
            ApiScopeDataAccessMock.Verify(dataAccess => dataAccess.ReplaceAsync(It.IsAny <ApiScopeData>(), ExpressionItsAny), Times.Never);
        }