示例#1
0
        public void Validate_NameIsGreaterThan200_ShouldBeFalse()
        {
            var command = new CreateConversationCommand
            {
                Name    = new string('a', 201),
                Type    = "Is Not Empty",
                Members = new List <UserModel>
                {
                    new UserModel
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "Long"
                    },
                    new UserModel
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "Quan"
                    },
                }
            };

            var validator = new CreateConversationCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public async Task GivenValidType_ReturnsOk()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new CreateConversationCommand
            {
                Type    = "pair",
                Members = new List <UserModel>
                {
                    new UserModel()
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "TestUser1"
                    },
                    new UserModel()
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "TestUser1"
                    }
                }
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

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

            response.EnsureSuccessStatusCode();
        }
示例#3
0
        public async Task <ActionResult <ConversationMessageModel> > CreateOrGet(CreateConversationCommand command)
        {
            try
            {
                var conversation = await Mediator.Send(new GetConversationQuery
                {
                    MembersId = command.Members.Select(member => member.UserId.ToString()).ToList()
                });


                if (conversation == null)
                {
                    conversation = await Mediator.Send(command);
                }

                var messageChats = await Mediator.Send(new GetMessageChatsQuery
                {
                    ConversationId = conversation.Id,
                    PageIndex      = 1
                });

                return(new ConversationMessageModel
                {
                    Conversation = conversation,
                    LstMessageChat = messageChats.ToList()
                });
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public async Task Handle_GivenTypeInvalid_ShouldRaiseNotTypeException()
        {
            ////Arrange
            var sut = new CreateConversationCommandHandler(_context, _mapper);

            var command = new CreateConversationCommand
            {
                Type    = "invalid",
                Members = new List <UserModel>
                {
                    new UserModel
                    {
                        DisplayName = "Valid User 1",
                        UserId      = validUserId1
                    },
                    new UserModel
                    {
                        DisplayName = "Valid User 2",
                        UserId      = validUserId2
                    },
                }
            };

            //// Act
            await Assert.ThrowsAsync <NotTypeException>(() => sut.Handle(command, CancellationToken.None));
        }
示例#5
0
        public void Validate_TypeIsEmpty_ShouldBeFalse()
        {
            var command = new CreateConversationCommand
            {
                Type    = "",
                Members = new List <UserModel>
                {
                    new UserModel
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "Long"
                    },
                    new UserModel
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "Quan"
                    },
                }
            };

            var validator = new CreateConversationCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
示例#6
0
        public void Validate_MemberIsEmpty_ShouldBeFalse()
        {
            var command = new CreateConversationCommand
            {
                Type    = "Is Not Empty",
                Members = new List <UserModel>
                {
                }
            };

            var validator = new CreateConversationCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
示例#7
0
        public async Task <ActionResult <ConversationMessageModel> > Create(CreateConversationCommand command)
        {
            try
            {
                var conversation = await Mediator.Send(command);

                return(new ConversationMessageModel
                {
                    Conversation = conversation,
                    LstMessageChat = new List <MessageChatModel>()
                });
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
示例#8
0
        public void Validate_MemberIsLessThanTwo_ShouldBeFalse()
        {
            var command = new CreateConversationCommand
            {
                Type    = "Is Not Empty",
                Members = new List <UserModel>
                {
                    new UserModel
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "Long"
                    }
                }
            };

            var validator = new CreateConversationCommandValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
        public async Task GivenInvalidUserId_ReturnHttpStatusCodeOK_andNewConversationWithEmptyListMessage()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            // init DB for test
            var context = _factory.InitializeDbForTests();
            var command = new CreateConversationCommand()
            {
                Type    = "pair",
                Members = new List <UserModel>()
                {
                    new UserModel()
                    {
                        UserId      = new Guid("020cdee0-8ecd-408a-b662-cd4d9cdf0100"),
                        DisplayName = "TestUser1"
                    },
                    new UserModel()
                    {
                        UserId      = Guid.NewGuid(),
                        DisplayName = "TestUser2"
                    }
                },
            };
            var content = IntegrationTestHelper.GetRequestContent(command);

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

            response.EnsureSuccessStatusCode();

            var vm = await IntegrationTestHelper.GetResponseContent <ConversationMessageModel>(response);

            vm.ShouldBeOfType <ConversationMessageModel>();
            vm.Conversation.ShouldNotBeNull();
            vm.Conversation.Id.ShouldBe(Guid.Empty);
            vm.LstMessageChat.Count.ShouldBe(0);
            // release DB
            _factory.DisposeDbForTests(context);
        }
示例#10
0
        public async Task GivenValidUserId_ReturnConversationMessageModel_HaveMessageList()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            // init DB for test
            var context = _factory.InitializeDbForTests();
            var command = new CreateConversationCommand()
            {
                Type    = "pair",
                Members = new List <UserModel>()
                {
                    new UserModel()
                    {
                        UserId      = new Guid("9c7ff9c5-90bd-4207-9dff-01da2ceece21"),
                        DisplayName = "TestUser4"
                    },
                    new UserModel()
                    {
                        UserId      = new Guid("020cdee0-8ecd-408a-b662-cd4d9cdf0100"),
                        DisplayName = "TestUser5"
                    }
                },
            };
            var content = IntegrationTestHelper.GetRequestContent(command);

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

            response.EnsureSuccessStatusCode();

            var vm = await IntegrationTestHelper.GetResponseContent <ConversationMessageModel>(response);

            vm.ShouldBeOfType <ConversationMessageModel>();
            vm.Conversation.Id.ShouldBe(new Guid("b73477a4-f61d-46fa-873c-7d71c01dfbd2"));
            vm.LstMessageChat.Count.ShouldBe(1);
            // release DB
            _factory.DisposeDbForTests(context);
        }
        public async Task Handle_GivenValidRequest_ShouldCreateConversationSuccess()
        {
            ////Arrange
            var sut = new CreateConversationCommandHandler(_context, _mapper);

            var command = new CreateConversationCommand
            {
                Name    = "conversationName",
                Type    = "pair",
                Members = new List <UserModel>
                {
                    new UserModel
                    {
                        DisplayName = "Valid User 1",
                        UserId      = validUserId1
                    },
                    new UserModel
                    {
                        DisplayName = "Valid User 2",
                        UserId      = validUserId2
                    },
                },
                IsPublic = true
            };

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

            var entity = _context.Conversations.Find(result.Id);

            entity.ShouldNotBeNull();
            entity.Name.ShouldBe("conversationName");
            entity.Type.ShouldBe("pair");
            entity.Members.Count.ShouldBe(2);
            entity.isPublic.ShouldBe(true);
        }
示例#12
0
 public ConversationCreatorViewModel(MainWindow window)
 {
     this.window        = window;
     CreateConversation = new CreateConversationCommand(canCreate, Create);
 }