public async Task <IActionResult> RemoveGroup(string id)
        {
            mLogger.LogDebug($"Requesting deleting group id {id}");

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            try
            {
                IResponse <ITasksGroup> result = await mTasksGroupService.RemoveAsync(id).ConfigureAwait(false);

                mLogger.LogDebug($"Remove result {(result.IsSuccess ? "succeeded" : "failed")}");

                if (!result.IsSuccess)
                {
                    return(StatusCode(StatusCodes.Status405MethodNotAllowed, result.Message));
                }

                TasksGroupResource tasksGroupResource = mMapper.Map <ITasksGroup, TasksGroupResource>(result.ResponseObject);
                return(Ok(tasksGroupResource));
            }
            catch (Exception ex)
            {
                mLogger.LogError(ex, "Remove operation failed with error");
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 2
0
        public async Task RemoveGroupAsync_ThrowsException_InternalServerErrorStatusCode()
        {
            ITasksGroupService fakeTasksGroupService = A.Fake <ITasksGroupService>();

            A.CallTo(() => fakeTasksGroupService.RemoveAsync(A <string> .Ignored))
            .Throws <Exception>();

            using TestServer testServer        = ApiTestHelper.BuildTestServerWithFakes(fakeTasksGroupService);
            using HttpClient httpClient        = testServer.CreateClient();
            using HttpResponseMessage response = await httpClient.DeleteAsync($"{MainRoute}/some-id").ConfigureAwait(false);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
Esempio n. 3
0
        public async Task RemoveGroupAsync_RemoveSuccess_SuccessStatusCode()
        {
            ITasksGroupService fakeTasksGroupService = A.Fake <ITasksGroupService>();

            A.CallTo(() => fakeTasksGroupService.RemoveAsync(A <string> .Ignored))
            .Returns(new SuccessResponse <ITasksGroup>(A.Fake <ITasksGroup>(), ""));

            using TestServer testServer        = ApiTestHelper.BuildTestServerWithFakes(fakeTasksGroupService);
            using HttpClient httpClient        = testServer.CreateClient();
            using HttpResponseMessage response = await httpClient.DeleteAsync($"{MainRoute}/some-id").ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
        }