public async Task TopViewsTest() { int messagesCount = 10; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); var topMessageToView = messages[4].Id; var secondMessageToView = messages[7].Id; await controller.AddViewToMessage(new List <Guid> { topMessageToView }); await controller.AddViewToMessage(new List <Guid> { topMessageToView }); await controller.AddViewToMessage(new List <Guid> { topMessageToView, secondMessageToView }); messages = await controller.GetTopViewedMessages(new SkipTakeMessagesRequest()); Assert.AreEqual(1, messages.Count); Assert.AreEqual(messages[0].Id, topMessageToView); }
public async Task GetAllCommentsOfUserMessages() { MessagesController messagesController = GetMessagesController(); MessageCommentsController messageCommentsController = GetMessageCommentsController(); await messagesController.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await messagesController.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _defaultCommentsText, MessageId = messages[0].Id }); List <MessageCommentResponse> comments = await messageCommentsController.GetAllCommentsOfUserMessages(); Assert.AreEqual(1, comments.Count); Assert.AreEqual(_defaultCommentsText, comments[0].Text); Assert.AreEqual(messages[0].Id, comments[0].MessageId); }
public async Task EmptyMessageCollectionTest() { MessagesController controller = GetMessagesController(); List <MessageResponse> messages = await controller.GetMessages(); Assert.IsEmpty(messages); }
public async Task AddCommentToAnotherComment() { MessagesController messagesController = GetMessagesController(); MessageCommentsController messageCommentsController = GetMessageCommentsController(); await messagesController.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await messagesController.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _defaultCommentsText, MessageId = messages[0].Id }); List <MessageCommentResponse> comments = await messageCommentsController.GetComments(messages[0].Id); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _secondCommentsText, MessageId = comments[0].MessageId }); comments = await messageCommentsController.GetComments(messages[0].Id); Assert.AreEqual(2, comments.Count); Assert.AreEqual(_defaultCommentsText, comments[0].Text); Assert.AreEqual(_secondCommentsText, comments[1].Text); }
public async Task EmptyMessageCollectionTest() { MessagesController controller = GetMessagesController(); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); Assert.IsEmpty(messages); }
public async Task LikeOneMessage() { MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await controller.LikeMessage(messages[0].Id); messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); Assert.AreEqual(1, messages[0].LikesCount); }
public async Task ViewsTest() { int messagesCount = 10; int messageToView = 4; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await controller.AddViewToMessage(new List <Guid> { messages[messageToView].Id }); messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); Assert.AreEqual(1, messages[messageToView].Views); Assert.AreEqual(0, messages[0].Views); }
public async Task SkipTest() { int messagesCount = 10; int messagesToSkip = 3; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); var messages = await controller.GetMessages(skip : messagesToSkip); Assert.AreEqual(messagesCount - messagesToSkip, messages.Count); }
public async Task TakeTest() { int messagesCount = 10; int messagesToTake = 4; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(take : messagesToTake); Assert.AreEqual(messagesToTake, messages.Count); }
public async Task TakeTest() { int messagesCount = 10; int messagesToTake = 4; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation, Take = messagesToTake }); Assert.AreEqual(messagesToTake, messages.Count); }
public async Task SkipTest() { int messagesCount = 10; int messagesToSkip = 3; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); var messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation, Skip = messagesToSkip }); Assert.AreEqual(messagesCount - messagesToSkip, messages.Count); }
public async Task OneMessageTest() { MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText }); List <MessageResponse> messages = await controller.GetMessages(); Assert.AreEqual(1, messages.Count); Assert.AreEqual(_defaultMessageText, messages[0].Text); Assert.AreEqual(TestUserName, messages[0].From); }
public void TestGetMessages() { IActionResult actionResult = controller.GetMessages(); Assert.NotNull(actionResult); OkObjectResult result = actionResult as OkObjectResult; Assert.NotNull(result); List <Message> messages = result.Value as List <Message>; Assert.True(messages.Count > 0); }
public async Task MessagesOrderTest() { int messagesCount = 10; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(); Assert.AreEqual(messagesCount, messages.Count); for (var i = 0; i < messagesCount; ++i) { Assert.AreEqual(i.ToString(), messages[i].Text); } }
public async Task DeleteMessageTest() { var deleteDate = DateTime.UtcNow.AddSeconds(DeleteMessageDelayInSeconds); MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText, DeleteAt = deleteDate }); await Task.Delay(TimeSpan.FromSeconds(DeleteMessageDelayInSeconds * 2)); List <MessageResponse> messages = await controller.GetMessages(); Assert.IsEmpty(messages); }
public async Task GetIdsOfUserMessages() { MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <Guid> messagesGuid = await controller.GetIdsOfUserMessages(); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); Assert.AreEqual(1, messagesGuid.Count); Assert.AreEqual(_defaultMessageText, messages.First(x => x.Id == messagesGuid[0]).Text); }
public void GetMessages_ShouldReturnMessages() { // Arrange var messageRepo = A.Fake <IMessageRepository>(); A.Dummy <IMessageFactory>(); var messages = A.Fake <IEnumerable <Message> >(); A.CallTo(() => messageRepo.List()).Returns(messages); var controller = new MessagesController(messageRepo); // Act controller.GetMessages(); // Assert A.CallTo(() => messageRepo.List()).MustHaveHappened(); }
public async Task SkipTakeTest() { int messagesCount = 10; int messagesToSkip = 4; int messagesToTake = 2; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(messagesToSkip, messagesToTake); Assert.AreEqual(messagesToTake, messages.Count); for (int i = 0; i < messagesToTake; ++i) { Assert.AreEqual((messagesToSkip + i).ToString(), messages[i].Text); } }
public override MessagesListResponseData Handle(MessagesListRequestData _) { if (CommandInvoker == null) { throw new ChatException(401); } var offsetUnparsed = Request.QueryString["offset"]; if (offsetUnparsed == null || !int.TryParse(offsetUnparsed, out int offset)) { offset = 0; } else if (offset < 0) { throw new ChatException(400); } var countUnparsed = Request.QueryString["count"]; if (countUnparsed == null || !int.TryParse(countUnparsed, out int count)) { count = 10; } else if (count <= 0 || count > 100) { throw new ChatException(400); } var messages = messagesController.GetMessages(offset, count); return(new MessagesListResponseData { Messages = messages .Select(m => new SendMessageResponseData { Id = m.Id, Message = m.Text, Author = m.Author }) .ToList() }); }
public async Task GetMessages_ShouldReturnAllMessages() { List <Message> allMessages = GetMessages(); _messageRepo.Setup(repo => repo.GetMessageBasedOnUser(null, 1, 50)) .Returns(Task.FromResult(allMessages)); var controller = new MessagesController(_messageRepo.Object); var actionResult = await controller.GetMessages(); var result = actionResult.Value; Assert.IsInstanceOf <List <Message> >(result); List <Message> listResult = (List <Message>)result; Assert.AreEqual(allMessages.Count, listResult.Count); for (int i = 0; i < allMessages.Count; i++) { Assert.AreEqual(allMessages[i].MessageId, listResult[i].MessageId); } }
public async Task DeleteOneOfTwoMessagesTest() { var deleteDate = DateTime.UtcNow.AddSeconds(DeleteMessageDelayInSeconds); MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText, DeleteAt = deleteDate }); await controller.SendMessage(new AddMessageRequest { Text = _secondMessageText }); await Task.Delay(TimeSpan.FromSeconds(DeleteMessageDelayInSeconds * 2)); List <MessageResponse> messages = await controller.GetMessages(); Assert.AreEqual(1, messages.Count); Assert.AreEqual(_secondMessageText, messages[0].Text); }
public async Task AddMessageWithPhotos() { MessagesController controller = GetMessagesController(); await controller.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation, Photos = new List <string>() { _image1, _image2 } }); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); string image1 = await controller.GetMessageImage(messages[0].Photos.First()); string image2 = await controller.GetMessageImage(messages[0].Photos.Last()); Assert.AreEqual(2, messages[0].Photos.Count()); Assert.AreEqual(_image1, image1); Assert.AreEqual(_image2, image2); }
public async Task MessageCommentsOrderTest() { int messageCommentsCount = 10; MessagesController messagesController = GetMessagesController(); MessageCommentsController messageCommentsController = GetMessageCommentsController(); await messagesController.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await messagesController.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await SendCommentsWithNumbers(messageCommentsController, messageCommentsCount, messages[0].Id); List <MessageCommentResponse> comments = await messageCommentsController.GetComments(messages[0].Id); Assert.AreEqual(messageCommentsCount, comments.Count); for (int i = 0; i < messageCommentsCount; i++) { Assert.AreEqual(i.ToString(), comments[i].Text); } }
public async void GetMessages() { // Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("SocialMediumForMusicians3").Options; var storeOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(options, storeOptions)) { var m1 = new Musician() { Id = "1", Email = "*****@*****.**", Name = "Aaa", Price = 10.03M, Types = new List <MusicianType>() { MusicianType.Jamming, MusicianType.Session, MusicianType.Teacher }, Instruments = new List <string>() { "Drums" } }; var m2 = new Musician() { Id = "2", Email = "*****@*****.**", Name = "Bbb", Price = 20.03M, Types = new List <MusicianType>() { MusicianType.Jamming }, Instruments = new List <string>() { "Guitar", "Bass Guitar", "Drums" } }; var m3 = new Musician() { Id = "3", Email = "*****@*****.**", Name = "Ccc", Price = 20.03M, Types = new List <MusicianType>() { MusicianType.Teacher }, Instruments = new List <string>() { "Drums" } }; context.AddRange(new List <Musician>() { m1, m2, m3 }); var mes1 = new Message() { Author = m3, Recipent = m1, Content = "aaa", SentAt = new System.DateTime(2020, 02, 02) }; var mes2 = new Message() { Author = m3, Recipent = m1, Content = "bbb", SentAt = new System.DateTime(2020, 02, 03) }; var mes3 = new Message() { Author = m2, Recipent = m1, Content = "ccc", SentAt = new System.DateTime(2020, 02, 04) }; var mes4 = new Message() { Author = m1, Recipent = m3, Content = "ddd", SentAt = new System.DateTime(2020, 02, 05) }; context.AddRange(new List <Message>() { mes1, mes2, mes3, mes4 }); context.SaveChanges(); } PaginationApiResult <MessageDTO> resultAllM1; PaginationApiResult <MessageDTO> resultThreadM1M3; // Act using (var context = new ApplicationDbContext(options, storeOptions)) { var controller = new MessagesController(context); resultAllM1 = (await controller.GetMessages(id: "1", pageIndex: 0, pageSize: 2)).Value; resultThreadM1M3 = (await controller.GetMessages(id: "1", authorId: "3")).Value; } // Assert Assert.Equal(3, resultAllM1.TotalCount); Assert.Equal(2, resultAllM1.Elements.Count); Assert.Equal("ccc", resultAllM1.Elements[0].Content); Assert.Equal(3, resultThreadM1M3.TotalCount); Assert.Equal(3, resultThreadM1M3.Elements.Count); Assert.Equal("aaa", resultThreadM1M3.Elements[0].Content); }