示例#1
0
 public MessageReceivedEventArgs(Contact contact, string message)
 {
     this.Message = new ReceivedMessage(contact, message);
 }
示例#2
0
        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);
        }
示例#3
0
 public ReceivedMessage(Contact contact, string message)
 {
     this.Contact = contact;
     this.Message = message;
 }
示例#4
0
        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();
        }
示例#5
0
 public ReceivedMessage(Contact contact, string message)
 {
     Contact = contact;
     Message = message;
 }