public MessageReceivedEventArgs(Contact contact, string message) { this.Message = new ReceivedMessage(contact, message); }
public void WhenSendingMessage_ThenUpdatesAndNotifiesSendingMessage() { var contact = new Contact(); var message = "message"; Action<IOperationResult<IEnumerable<Contact>>> getContactsCallback = null; Action<IOperationResult> sendMessageCallback = null; var serviceMock = new Mock<IChatService>(MockBehavior.Strict); serviceMock .SetupSet(svc => svc.Connected = true); serviceMock .Setup(svc => svc.GetContacts(It.IsAny<Action<IOperationResult<IEnumerable<Contact>>>>())) .Callback<Action<IOperationResult<IEnumerable<Contact>>>>(cb => getContactsCallback = cb); serviceMock .Setup(svc => svc.SendMessage(contact, message, It.IsAny<Action<IOperationResult>>())) .Callback<Contact, string, Action<IOperationResult>>((c, m, cb) => sendMessageCallback = cb); var getContactsOperationMock = new Mock<IOperationResult<IEnumerable<Contact>>>(); getContactsOperationMock.SetupGet(or => or.Result).Returns(new[] { contact }); var viewModel = new ChatViewModel(serviceMock.Object); InteractionRequestedEventArgs args = null; viewModel.SendMessageRequest.Raised += (s, e) => args = e; getContactsCallback(getContactsOperationMock.Object); viewModel.ContactsView.MoveCurrentTo(contact); var tracker = new PropertyChangeTracker(viewModel); Assert.IsFalse(viewModel.SendingMessage); viewModel.SendMessage(); Assert.IsFalse(viewModel.SendingMessage); var sendMessage = args.Context as SendMessageViewModel; sendMessage.Result = true; sendMessage.Message = message; args.Callback(); Assert.IsTrue(viewModel.SendingMessage); CollectionAssert.AreEqual(new[] { "SendingMessage" }, tracker.ChangedProperties); tracker.Reset(); sendMessageCallback(new Mock<IOperationResult>().Object); Assert.IsFalse(viewModel.SendingMessage); CollectionAssert.AreEqual(new[] { "SendingMessage" }, tracker.ChangedProperties); }
public ReceivedMessage(Contact contact, string message) { this.Contact = contact; this.Message = message; }
public void WhenAcceptingTheSendMessageInteraction_ThenSendsMessage() { var contact = new Contact(); var message = "message"; Action<IOperationResult<IEnumerable<Contact>>> getContactsCallback = null; Action<IOperationResult> sendMessageCallback = null; var serviceMock = new Mock<IChatService>(MockBehavior.Strict); serviceMock .SetupSet(svc => svc.Connected = true); serviceMock .Setup(svc => svc.GetContacts(It.IsAny<Action<IOperationResult<IEnumerable<Contact>>>>())) .Callback<Action<IOperationResult<IEnumerable<Contact>>>>(cb => getContactsCallback = cb); serviceMock .Setup(svc => svc.SendMessage(contact, message, It.IsAny<Action<IOperationResult>>())) .Callback<Contact, string, Action<IOperationResult>>((c, m, cb) => sendMessageCallback = cb); var getContactsOperationMock = new Mock<IOperationResult<IEnumerable<Contact>>>(); getContactsOperationMock.SetupGet(or => or.Result).Returns(new[] { contact }); var viewModel = new ChatViewModel(serviceMock.Object); InteractionRequestedEventArgs args = null; viewModel.SendMessageRequest.Raised += (s, e) => args = e; getContactsCallback(getContactsOperationMock.Object); viewModel.ContactsView.MoveCurrentTo(contact); viewModel.SendMessage(); Assert.IsNotNull(args); var sendMessage = args.Context as SendMessageViewModel; sendMessage.Result = true; sendMessage.Message = message; args.Callback(); serviceMock.VerifyAll(); }
public ReceivedMessage(Contact contact, string message) { Contact = contact; Message = message; }