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); }
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>(); }
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>(); }
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); }
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); }