public async Task CheckGettingGroupsOldMessagesAsync() { ApplicationDbContext db = GetDb(); var chatGroupRepository = new EfDeletableEntityRepository <ChatGroup>(db); var repository = new EfDeletableEntityRepository <ChatMessage>(db); var userChatGroupsRepository = new EfDeletableEntityRepository <UserChatGroup>(db); var service = new ChatsService( repository, chatGroupRepository, userChatGroupsRepository); await service.CreateUsersGroupAsync(this.sender, this.receiver, "chat name"); var groupId = await service.GetGroupIdAsync("chat name"); var firstChatMessage = new ChatMessage() { Id = Guid.NewGuid().ToString(), Receiver = this.receiver, Sender = this.sender, ChatGroupId = groupId, }; var secondChatMessage = new ChatMessage() { Id = Guid.NewGuid().ToString(), Receiver = this.receiver, Sender = this.sender, ChatGroupId = groupId, }; await repository.AddAsync(firstChatMessage); await repository.AddAsync(secondChatMessage); await repository.SaveChangesAsync(); var messages = await service.GetOldMessagesAsync <TestChatModel>(groupId); Assert.Equal(2, messages.Count()); }