예제 #1
0
        public async Task WhenSendingMessage_MessageIsSaved()
        {
            var user = await RunAsDefaultUserAsync();

            var chat = ArrangeDb.SeedWorkChat(user);
            await ArrangeDb.SaveChangesAsync();

            var request = new SendMessageCommand {
                ChatId = chat.Id, Text = "test message", UserId = user.Id
            };

            await SendAsync(request);

            var chatDb = await AssertDb.Chats.Include(x => x.Messages).SingleAsync();

            var message = chatDb.Messages.Single();

            message.Should().BeEquivalentTo(new
            {
                SenderId = user.Id,
                Text     = "test message",
                ChatId   = chat.Id
            });

            message.SentDate.Should().BeCloseTo(DateTime.Now, 5000);
        }
예제 #2
0
        public async Task GivenUserThatIsNotChatParticipant_WhenSendingMessage_ForbiddenExceptionIsThrown()
        {
            var user = await RunAsDefaultUserAsync();

            var bob  = ArrangeDb.SeedBobJohnes();
            var chat = ArrangeDb.SeedWorkChat(user);
            await ArrangeDb.SaveChangesAsync();

            var request = new SendMessageCommand {
                ChatId = chat.Id, Text = "test message", UserId = bob.Id
            };

            await FluentActions.Invoking(async() => await SendAsync(request)).Should().ThrowAsync <Forbidden403Exception>();
        }
예제 #3
0
        public async Task WhenRequesterIsNotChatParticipant_ThrowsForbidden403Exception()
        {
            var user = await RunAsDefaultUserAsync();

            var chat = ArrangeDb.SeedWorkChat(BobJohnes);
            await ArrangeDb.SaveChangesAsync();

            var request = new GetNewParticipantsSelector.Query
            {
                ChatId = chat.Id,
                UserId = user.Id
            };

            await FluentActions.Invoking(async() => await SendAsync(request)).Should().ThrowAsync <Forbidden403Exception>();
        }
예제 #4
0
        public async Task ReturnsUsersThatAreNotParticipantsAlready()
        {
            var user = await RunAsDefaultUserAsync();

            var adele = ArrangeDb.SeedAdeleVance();
            var chat  = ArrangeDb.SeedWorkChat(user, BobJohnes, JohnCena);
            await ArrangeDb.SaveChangesAsync();

            var request = new GetNewParticipantsSelector.Query
            {
                ChatId = chat.Id,
                UserId = user.Id
            };

            var response = await SendAsync(request);

            response.Single().Id.Should().Be(adele.Id);
        }
예제 #5
0
        public async Task GivenSomeChatsSavedInDb_ReturnsOnlyChatsWhereUserIsParticipant()
        {
            // Arrange
            var user = await RunAsDefaultUserAsync();

            var chat1 = new Persistence.Entities.Chat("Chat1");
            var chat2 = new Persistence.Entities.Chat("Chat2");

            chat2.AddParticipant(user);

            ArrangeDb.AddRange(chat1, chat2);
            await ArrangeDb.SaveChangesAsync();

            var query = new GetMyChatsList.Query {
                UserId = user.Id, PaginationQuery = new Pagination.PaginationQuery()
            };

            // Act
            var response = await SendAsync(query);

            // Assert
            response.Data.Should().HaveCount(1);
            response.Data.First().Id.Should().Be(chat2.Id);
        }