예제 #1
0
        public void YammerMessagePoster_PostReply_ShouldSucceed()
        {
            var testBody = "This is a body";
            var serviceResponseText = @"Testing";
            var testMessage = new Message();
            var deserializedResponse = new MessagesFetchResponse
            {
                Messages = new List<Message>
                                                              {
                                                                  testMessage
                                                              }
            };

            _serviceManager.Setup(s => s.PostMessageReply(It.IsAny<string>(), It.IsAny<long>())).Returns(serviceResponseText);
            _deserializer.Setup(s => s.DeserializeMessagesResponse(It.IsAny<string>())).Returns(deserializedResponse);

            var result = _messagePoster.PostReply(testBody, 1);

            Assert.AreEqual(testMessage, result);
            _serviceManager.Verify(v => v.PostMessageReply(It.Is<string>(i => i == testBody), It.Is<long>(i=>i==1)), Times.Once());
            _deserializer.Verify(v => v.DeserializeMessagesResponse(It.Is<string>(i => i == serviceResponseText)), Times.Once());
        }
        public void YammerMessageFetcher_GetLatestMessages_ShouldSucceed()
        {
            var responseText = "Testing";
            var responseMessages = new List<Message>
                                       {
                                           new Message(),
                                           new Message(),
                                           new Message()
                                       };
            var responseObject = new MessagesFetchResponse
                                     {
                                         Messages = responseMessages
                                     };

            _service.Setup(s => s.GetLatestMessagesTextFromServer()).Returns(responseText);
            _deserializer.Setup(s => s.DeserializeMessagesResponse(It.IsAny<string>())).Returns(responseObject);

            var result = _messageFetcher.GetLatestMessages();

            Assert.AreEqual(responseMessages, result);
            _service.Verify(v=>v.GetLatestMessagesTextFromServer(), Times.Once());
            _deserializer.Verify(v=>v.DeserializeMessagesResponse(It.Is<string>(i=>i==responseText)), Times.Once());
        }
        public void YammerMessageFetcher_GetUnprocessedMessages_ShouldFetchMoreMessagesWhenNecessary()
        {
            var firstResponseText = "Testing";
            var secondResponseText = "Testing2";
            var firstResponseMessages = new List<Message>
                                       {
                                           new Message{ID = 6},
                                           new Message{ID = 5},
                                           new Message{ID = 4}
                                       };
            var secondResponseMessages = new List<Message>
                                       {
                                           new Message{ID = 3},
                                           new Message{ID = 2},
                                           new Message{ID = 1}
                                       };
            var firstResponseObject = new MessagesFetchResponse
            {
                Messages = firstResponseMessages
            };
            var secondResponseObject = new MessagesFetchResponse
            {
                Messages = secondResponseMessages
            };

            _service.Setup(s => s.GetLatestMessagesTextFromServer()).Returns(firstResponseText);
            _service.Setup(s=>s.GetLatestMessagesTextFromServerAfterMessageID(It.IsAny<long>())).Returns(secondResponseText);
            _deserializer.Setup(s => s.DeserializeMessagesResponse(It.Is<string>(i=>i==firstResponseText))).Returns(firstResponseObject);
            _deserializer.Setup(s => s.DeserializeMessagesResponse(It.Is<string>(i=>i==secondResponseText))).Returns(secondResponseObject);
            _databaseManager.Setup(s => s.IsMessageInDatabase(It.Is<long>(i => i > 1))).Returns(false);
            _databaseManager.Setup(s => s.IsMessageInDatabase(It.Is<long>(i => i == 1))).Returns(true);

            var result = _messageFetcher.GetUnprocessedMessages();

            Assert.AreEqual(5, result.Count());
            _service.Verify(v => v.GetLatestMessagesTextFromServer(), Times.Once());
            _service.Verify(v => v.GetLatestMessagesTextFromServerAfterMessageID(It.Is<long>(i => i == 4)), Times.Once());
            _deserializer.Verify(v => v.DeserializeMessagesResponse(It.Is<string>(i => i == firstResponseText)), Times.Once());
            _deserializer.Verify(v => v.DeserializeMessagesResponse(It.Is<string>(i => i == secondResponseText)), Times.Once());
            _databaseManager.Verify(v => v.SaveMessages(It.Is<IEnumerable<Message>>(i => 5 == i.Count())), Times.Once());
            _databaseManager.Verify(v => v.SaveChanges(), Times.Once());
        }