public void Invoke_ValidData_AddsMessageToDatabaseWithCorrectValues() { var messageData = new MessageModel { Text = "Testmessage", UserRoom = new UserRoomModel() }; DataAccess.Models.Message messageSaved = null; var mockedMessageRepository = new Mock <IMessageRepository>(); mockedMessageRepository.Setup(r => r.Add(It.IsAny <DataAccess.Models.Message>())) .Callback <DataAccess.Models.Message>(u => messageSaved = u); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var action = new AddNewMessage(mockedMessageRepository.Object, mockedUnitOfWork.Object); // action action.Invoke(messageData); // assert mockedMessageRepository.Verify(r => r.Add(It.IsAny <DataAccess.Models.Message>()), Times.Once()); mockedUnitOfWork.Verify(r => r.Save(), Times.Exactly(1)); Assert.Equal("Testmessage", messageSaved.Text); }
public void Invoke_InvalidData_AddNorSaveAreCalled() { // prepare var messageToAdd = new MessageModel(); var mockedMessageRepository = new Mock <IMessageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var action = new AddNewMessage(mockedMessageRepository.Object, mockedUnitOfWork.Object); // action var result = action.Invoke(messageToAdd); // assert Assert.Equal(Guid.Empty, result); mockedMessageRepository.Verify(r => r.Add(It.IsAny <DataAccess.Models.Message>()), Times.Never); mockedUnitOfWork.Verify(r => r.Save(), Times.Never); }
public void Invoke_NoUserRoom_AddNorSaveAreCalled() { var messageData = new MessageModel { Text = "Testmessage" }; var mockedMessageRepository = new Mock <IMessageRepository>(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var action = new AddNewMessage(mockedMessageRepository.Object, mockedUnitOfWork.Object); // action var result = action.Invoke(messageData); // assert mockedMessageRepository.Verify(r => r.Add(It.IsAny <DataAccess.Models.Message>()), Times.Never); mockedUnitOfWork.Verify(r => r.Save(), Times.Never); Assert.Equal(Guid.Empty, result); }
private void ConversationCollectionOnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { SetLastMessage(); if (e.Action != NotifyCollectionChangedAction.Add) { return; } if (!AddNewMessage?.Invoke(this, Conversation) == true) { return; } foreach (var unused in e.NewItems) { Conversation.NewMessages++; } NewMessagesChanged?.Invoke(this, EventArgs.Empty); }
private bool ChatViewModelOnAddNewMessage(object sender, SimpleConversation conversation) { return(CurrentChatViewModel == null || conversation != CurrentChatViewModel.Conversation || AddNewMessage?.Invoke(this, conversation) == true); }