Esempio n. 1
0
        public async Task <IActionResult> DeleteMessage([Required][ValidateGuid][FromRoute] string messageId)
        {
            var message = await _messagesService.GetMessageByIdAsync(messageId);

            if (message == null)
            {
                return(NotFound(new ApiError("Message with specified Id was not found", HttpStatusCode.NotFound)));
            }

            var chat = await _chatsService.GetByIdAsync(message.ChatId);

            var isChatParticipant = await _authorizationService.AuthorizeAsync(User, chat, "ChatParticipant");

            if (!isChatParticipant.Succeeded)
            {
                return(NotFound(new ApiError("Message with specified Id was not found", HttpStatusCode.NotFound)));
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, message, "SameOrAdminUser");

            if (!authResult.Succeeded)
            {
                var authError = new ApiError("You are not message author or chat admin", HttpStatusCode.Unauthorized);
                return(StatusCode(StatusCodes.Status403Forbidden, authError));
            }

            await _messagesService.DeleteMessageAsync(messageId);

            return(Ok());
        }
        When_Delete_Message_Async_Is_Executed_For_Existing_Partner_Message_Id_Then_Messages_And_Message_Content_Repositories_Are_Called()
        {
            _messagesRepositoryMock.Setup(x => x.DeleteMessageAsync(It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            _messageContentRepositoryMock.Setup(x => x.DeleteContentAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(It.IsAny <bool>()));

            await _service.DeleteMessageAsync(PartnerMessageId);

            _messagesRepositoryMock.Verify(x => x.DeleteMessageAsync(It.IsAny <string>()), Times.Once);
            _messageContentRepositoryMock.Verify(x => x.DeleteContentAsync(It.IsAny <string>()), Times.Once);
        }
 public async Task DeleteMessageAsync(string partnerMessageId)
 {
     await _messagesService.DeleteMessageAsync(partnerMessageId);
 }