public void Validate_ValidCommand_ShouldBeTrue()
        {
            var command = new CreateMessageChatCommand
            {
                Content        = "Hello there",
                ConversationId = Guid.NewGuid(),
                RegUserName    = "******"
            };

            var validator = new CreateMessageChatCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
        public void Validate_RegUserNameEmpty_ShouldBeFalse()
        {
            var command = new CreateMessageChatCommand
            {
                Content        = "Hello there",
                ConversationId = Guid.Empty,
                RegUserName    = string.Empty
            };

            var validator = new CreateMessageChatCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public void Validate_ContentExceedMaximunLength_ShouldBeFalse()
        {
            var command = new CreateMessageChatCommand
            {
                Content        = new string('a', 5001),
                ConversationId = Guid.NewGuid(),
                RegUserName    = "******"
            };

            var validator = new CreateMessageChatCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
Beispiel #4
0
        public async Task Handle_LoginUserIsNotMemberOfConversation_ShouldRaiseNotOwnedException()
        {
            ////Arrange
            var sut = new CreateMessageChatCommandHandler(_context);

            var command = new CreateMessageChatCommand
            {
                Content        = "hello",
                ConversationId = validConversationId,
                RegUserName    = "******",
                RegUserId      = ""
            };

            //// Act
            await Assert.ThrowsAsync <NotOwnedException>(() => sut.Handle(command, CancellationToken.None));
        }
Beispiel #5
0
        public async Task Handle_GivenConversationIdInvalid_ShouldRaiseNotFoundException()
        {
            ////Arrange
            var sut = new CreateMessageChatCommandHandler(_context);

            var command = new CreateMessageChatCommand
            {
                Content        = "hello",
                ConversationId = invalidConversationId,
                RegUserName    = "******",
                RegUserId      = loginUser1.ToString()
            };

            //// Act
            await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None));
        }
Beispiel #6
0
        public async Task GivenValidRequest_ReturnsSuccessCode()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new CreateMessageChatCommand
            {
                Content        = "hello there",
                RegUserName    = "******",
                ConversationId = new Guid("B73477A4-F61D-46FA-873C-7D71C01DFBDF"),
                RegUserId      = "020cdee0-8ecd-408a-b662-cd4d9cdf0100"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PostAsync($"/api/MessageChat", content);

            response.EnsureSuccessStatusCode();
        }
Beispiel #7
0
        public async Task Handle_GivenValidRequest_ShouldRegisSuccess()
        {
            ////Arrange
            var sut = new CreateMessageChatCommandHandler(_context);

            var command = new CreateMessageChatCommand
            {
                Content        = "hello",
                ConversationId = validConversationId,
                RegUserName    = "******",
                RegUserId      = loginUser1.ToString()
            };

            //// Act
            var messageChatId = await sut.Handle(command, CancellationToken.None);

            var messageChat = await _context.MessageChats.FindAsync(messageChatId);

            messageChat.ConversationId.ShouldBe(validConversationId);
            messageChat.Content.ShouldBe("hello");
        }
 public async Task <ActionResult <Guid> > Create(CreateMessageChatCommand command)
 {
     return(await Mediator.Send(command));
 }