public async Task RoomChatShowsOnlyFiftyMessages() { var chatRooms = this.GetChatRooms(); var chatRoomRepositoryMock = new Mock <IRepository <ChatRoom> >(); var userRepositoryMock = new Mock <IRepository <ApplicationUser> >(); chatRoomRepositoryMock.Setup(x => x.All()).Returns(chatRooms.AsQueryable()); chatRoomRepositoryMock.Setup(x => x.FindAsync(It.IsAny <object[]>())) .Returns((object[] name) => Task.FromResult(chatRooms.FirstOrDefault(c => c.Name == name.First().ToString()))); var chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object, userRepositoryMock.Object); var messages = await chatRoomManager.GetMessagesAsync("Default Room"); Assert.IsTrue(messages.Count() <= 50); }
public async Task RoomChatShowsMessagesOrderedByTimespan() { var chatRooms = this.GetChatRooms(); var chatRoomRepositoryMock = new Mock <IRepository <ChatRoom> >(); var userRepositoryMock = new Mock <IRepository <ApplicationUser> >(); chatRoomRepositoryMock.Setup(x => x.All()).Returns(chatRooms.AsQueryable()); chatRoomRepositoryMock.Setup(x => x.FindAsync(It.IsAny <object[]>())) .Returns((object[] name) => Task.FromResult(chatRooms.FirstOrDefault(c => c.Name == name.First().ToString()))); var chatRoomManager = new ChatRoomManager(chatRoomRepositoryMock.Object, userRepositoryMock.Object); var messages = await chatRoomManager.GetMessagesAsync("Second Room"); var messagesInCorrectOrder = new List <Message> { new Message { Date = new DateTime(2019, 08, 17, 8, 20, 0), Content = "Message 2", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 21, 0), Content = "Message 3", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 22, 0), Content = "Message 4", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 23, 0), Content = "Message 5", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 24, 0), Content = "Message 6", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 25, 0), Content = "Message 7", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 26, 0), Content = "Message 8", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 27, 0), Content = "Message 9", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 28, 0), Content = "Message 10", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 29, 0), Content = "Message 11", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 30, 0), Content = "Message 12", UserId = "3" }, new Message { Date = new DateTime(2019, 08, 17, 8, 31, 0), Content = "Message 13", UserId = "1" }, new Message { Date = new DateTime(2019, 08, 17, 8, 32, 0), Content = "Message 14", UserId = "2" }, new Message { Date = new DateTime(2019, 08, 17, 8, 33, 0), Content = "Message 15", UserId = "3" }, new Message { Date = new DateTime(2019, 08, 17, 8, 34, 0), Content = "Message 16", UserId = "4" }, }; CollectionAssert.AreEqual(messages.Select(x => x.Date).ToList(), messagesInCorrectOrder.Select(x => x.Date).ToList()); }