public void CreateMessage_Should_SetMessage() { // Arrange var message = new Message(); var messageViewModel = new MessageViewModel(message); // Act // Assert Assert.Same(message, messageViewModel.Message); }
public void MessageReadByCurrent_Should_NotBeMarkedRead() { // Arrange var message = new Message { Id = "123456", UnreadByCurrent = true }; var messageViewModel = new MessageViewModel(message); // Act // Assert Assert.False(messageViewModel.Read); }
public void Message_Should_HaveAuthor() { // Arrange var user = new User { Id = "abcdef", Username = "******" }; var message = new Message { User = user }; var messageViewModel = new MessageViewModel(message); // Act // Assert Assert.NotNull(messageViewModel.User); Assert.Same(user, messageViewModel.User); }
public void CreateMessage_Should_SetDefaultProperties() { // Arrange var message = new Message { Id = "123456", Text = "my message", Html = "<div>my message</div>", SentDate = DateTime.Now, UnreadByCurrent = false }; var messageViewModel = new MessageViewModel(message); // Act // Assert Assert.Equal("123456", messageViewModel.Id); Assert.Equal("my message", messageViewModel.Text); Assert.Equal("<div>my message</div>", messageViewModel.Html); Assert.Equal(DateTime.Now.ToString(), messageViewModel.SentDate.ToString()); Assert.Null(messageViewModel.User); Assert.True(messageViewModel.Read); }
public MessageViewModel(Message message) { // Properties Message = message; Id = message.Id; Text = message.Text; Html = message.Html; SentDate = message.SentDate; User = message.User; Read = !message.UnreadByCurrent; if (IsInDesignMode) { // Code runs in Blend --> create design time data. } else { // Code runs "for real" } }
public void UpdateMessage_Should_UpdateTextContent() { // Arrange var message = new Message { Id = "123456", Text = "my first message" }; var messageViewModel = new MessageViewModel(message); // Act messageViewModel.UpdateMessage("my updated message"); // Assert Assert.Equal("my updated message", messageViewModel.Text); Assert.Equal("my updated message", message.Text); }
public void ReadMessage_Should_MarkMessageAsRead() { // Arrange var message = new Message { Id = "123456", Text = "my first message", UnreadByCurrent = true }; var messageViewModel = new MessageViewModel(message); // Act messageViewModel.MarkAsRead(); // Assert Assert.True(messageViewModel.Read); Assert.False(message.UnreadByCurrent); }
private async Task NotifyNewMessageAsync(Message message) { // Do not add an existing messages to the chat if (Messages.Any(m => m.Id == message.Id)) return; // Add message to the room _eventService.PushMessage .OnNext(new Tuple<string, IMessageViewModel>(Room.Id, new MessageViewModel(message))); // If the message was not read, update unread notifications when user is not reading if (message.UnreadByCurrent) { // Add in-app notification (unread count), except for the current selected room if (_mainViewModel.SelectedRoom != this) { var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher; await dispatcher.RunAsync(CoreDispatcherPriority.High, () => UnreadMessagesCount++); } // Send notification (new message) if (!Room.DisabledNotifications && _mainViewModel.CurrentUser.Id != message.User.Id) { string id = $"{Room.Name}_message_{Room.Id}"; _localNotificationService.SendNotification(Room.Name, message.Text, id, Room.Name); } } }
public Task<Message> UpdateMessageAsync(string roomId, string messageId, string message) { UpdatedMessages++; var m = new Message { Id = messageId, EditedDate = DateTime.Now, Text = message }; return Task.FromResult(m); }
public Task<Message> SendMessageAsync(string roomId, string message) { MessagesSent++; var m = new Message { Id = string.Format("xadg41w{0}", MessagesSent), SentDate = DateTime.Now, Text = message }; return Task.FromResult(m); }