コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 private bool ChatViewModelOnAddNewMessage(object sender, SimpleConversation conversation)
 {
     return(CurrentChatViewModel == null || conversation != CurrentChatViewModel.Conversation || AddNewMessage?.Invoke(this, conversation) == true);
 }