Пример #1
0
        public async Task <IActionResult> DeleteAProvince([FromRoute] string province)
        {
            if (String.IsNullOrEmpty(province))
            {
                var error = new BadRequestException("Province cannot be null or empty");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var deleted = await locationsRepository.DeleteAProvince(province);

                if (deleted == null)
                {
                    var error = new NotFoundException("The given province cannot be found on database");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }
                var response = new DeletedResponse <string>(deleted, $"Successfully deleted location '{deleted}'");
                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
        public async Task Should_remove_hearing()
        {
            var       client = new Mock <ITestApiClient>();
            const int COUNT  = 1;

            var deletedResponse = new DeletedResponse()
            {
                NumberOfDeletedHearings = COUNT
            };

            client.Setup(x => x.DeleteTestDataByPartialCaseTextAsync(It.IsAny <DeleteTestHearingDataRequest>()))
            .ReturnsAsync(deletedResponse);

            var controller = new HearingsController(client.Object, _loggerMock.Object);

            var result = await controller.DeleteTestDataByPartialCaseText(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var response = (DeletedResponse)typedResult.Value;

            response.Should().NotBeNull();
            response.NumberOfDeletedHearings.Should().Be(COUNT);
        }
Пример #3
0
        public async Task <IActionResult> DeleteALocation([FromRoute] int locationID)
        {
            if (locationID == 0)
            {
                var error = new BadRequestException("The given location ID is invalid");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var deleted = await locationsRepository.DeleteALocation(locationID);

                if (deleted == null)
                {
                    var error = new NotFoundException("The given location cannot be found on database");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }
                var response = new DeletedResponse <int>(deleted.Id, $"Successfully deleted location '{deleted.Id}'");
                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
Пример #4
0
        private async Task DeleteMessages(string channelId, List <Message> messageHistories)
        {
            if (messageHistories == null)
            {
                return;
            }
            int deleteInterval = 300;

            foreach (Message item in messageHistories)
            {
                if (string.IsNullOrEmpty(item.user) || item.user.Equals(UserIdOfToken))
                {
                    DeletedResponse response;
                    do
                    {
                        try
                        {
                            response = await SlackClient.DeleteMessageAsync(channelId, item.ts);
                        }
                        catch (NullReferenceException)
                        {
                            response = new DeletedResponse()
                            {
                                ok = true
                            };
                        }
                        Thread.Sleep(deleteInterval);
                    } while ((response != null && !response.ok) && response.error.Equals(Config.SlackRateLimitError));

                    MessageDeleted?.Invoke();
                }
            }
        }
Пример #5
0
        public async Task <IActionResult> DeleteAProject([FromRoute] string projectNumber)
        {
            if (String.IsNullOrEmpty(projectNumber))
            {
                var error = new BadRequestException("The given project number is null/empty");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var deletedCount = await projectsRepository.DeleteAProject(projectNumber);

                if (deletedCount != 1)
                {
                    var error = new NotFoundException("The given project number cannot be found on database");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }
                var response = new DeletedResponse <string>(projectNumber, $"Successfully deleted project with number '{projectNumber}'");
                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
Пример #6
0
        private static DeletedResponse DeleteMessage(SlackSocketClient client, string channel, DateTime messageTimestamp)
        {
            DeletedResponse deletedResponse = null;

            using (var sync = new InSync(nameof(SlackClient.DeleteMessage)))
            {
                client.DeleteMessage(response =>
                {
                    deletedResponse = response;
                    sync.Proceed();
                }, channel, messageTimestamp);
            }

            return(deletedResponse);
        }
Пример #7
0
        public void TestConnectPostAndDelete()
        {
            // given
            SlackSocketClient client  = this.fixture.CreateUserClient();
            string            channel = this.fixture.Config.TestChannel;

            // when
            DateTime        messageTimestamp = PostMessage(client, channel);
            DeletedResponse deletedResponse  = DeleteMessage(client, channel, messageTimestamp);

            // then
            Assert.NotNull(deletedResponse);
            Assert.True(deletedResponse.ok);
            Assert.Equal(channel, deletedResponse.channel);
            Assert.Equal(messageTimestamp, deletedResponse.ts);
        }
Пример #8
0
        public void TestConnectPostAndDelete()
        {
            // given
            SlackSocketClient client  = ClientHelper.GetClient(_config.Slack.UserAuthToken);
            string            channel = _config.Slack.TestChannel;

            // when
            DateTime        messageTimestamp = PostMessage(client, channel);
            DeletedResponse deletedResponse  = DeleteMessage(client, channel, messageTimestamp);

            // then
            Assert.IsNotNull(deletedResponse, "No response was found");
            Assert.IsTrue(deletedResponse.ok, "Message not deleted!");
            Assert.AreEqual(channel, deletedResponse.channel, "Got invalid channel? Something's not right here...");
            Assert.AreEqual(messageTimestamp, deletedResponse.ts, "Got invalid time stamp? Something's not right here...");
        }
Пример #9
0
        public async Task <IActionResult> DeleteASkill([FromRoute] int disciplineID, [FromRoute] string skillName)
        {
            if (String.IsNullOrEmpty(skillName))
            {
                var error = new BadRequestException("Skill Name cannot be null or empty");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            if (disciplineID == 0)
            {
                var error = new BadRequestException("The given discipline ID is invalid");
                return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
            }

            try
            {
                var deleted = await skillsRepository.DeleteASkill(skillName, disciplineID);

                if (deleted == null)
                {
                    var error = new NotFoundException("The given skill cannot be found on database");
                    return(StatusCode(StatusCodes.Status404NotFound, new CustomException <NotFoundException>(error).GetException()));
                }

                var response = new DeletedResponse <int>(deleted.Id, $"Successfully deleted skill '{deleted.Id}'");
                return(StatusCode(StatusCodes.Status200OK, response));
            }
            catch (Exception err)
            {
                var errMessage = $"Source: {err.Source}\n  Message: {err.Message}\n  StackTrace: {err.StackTrace}\n";
                if (err is SqlException)
                {
                    var error = new InternalServerException(errMessage);
                    return(StatusCode(StatusCodes.Status500InternalServerError, new CustomException <InternalServerException>(error).GetException()));
                }
                else
                {
                    var error = new BadRequestException(errMessage);
                    return(StatusCode(StatusCodes.Status400BadRequest, new CustomException <BadRequestException>(error).GetException()));
                }
            }
        }
Пример #10
0
        private static DeletedResponse DeleteMessage(SlackSocketClient client, string channel, DateTime messageTimestamp)
        {
            DeletedResponse deletedResponse = null;
            var             waiter          = new EventWaitHandle(false, EventResetMode.ManualReset);

            client.DeleteMessage(response =>
            {
                deletedResponse = response;
                waiter.Set();
            }, channel, messageTimestamp);

            Policy
            .Handle <AssertFailedException>()
            .WaitAndRetry(15, x => TimeSpan.FromSeconds(0.2), (exception, span) => Console.WriteLine("Retrying in {0} seconds", span.TotalSeconds))
            .Execute(() =>
            {
                Assert.IsTrue(waiter.WaitOne(), "Still waiting for things to happen...");
            });

            return(deletedResponse);
        }
        public async Task <IActionResult> DeleteTestDataByPartialCaseText(DeleteTestHearingDataRequest request)
        {
            _logger.LogDebug($"DeleteHearingsByPartialCaseText");

            List <Guid> hearingIds;

            try
            {
                hearingIds = await _bookingsApiService.DeleteHearingsByPartialCaseText(request);
            }
            catch (BookingsApiException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }

            try
            {
                foreach (var hearingId in hearingIds)
                {
                    await _videoApiClient.DeleteAudioApplicationAsync(hearingId);

                    _logger.LogInformation("Successfully deleted audio application with hearing id {hearingId}", hearingId);
                }
            }
            catch (VideoApiException e)
            {
                if (e.StatusCode != (int)HttpStatusCode.NotFound)
                {
                    _logger.LogError(e, "Failed to delete audio application with error {message}", e.Message);
                    return(StatusCode(e.StatusCode, e.Response));
                }
            }

            var response = new DeletedResponse()
            {
                NumberOfDeletedHearings = hearingIds.Count
            };

            return(Ok(response));
        }