コード例 #1
0
        public MessagesNancyModule(IMessageListViewModelRetriever messageListViewModelRetriever
                                   , IHandlerFactory handlerFactory)
            : base("/messages")
        {
            Get("/{storeName}/{pageNumber?1}", parameters =>
            {
                var logger = LogProvider.GetLogger("MessagesNancyModule");
                logger.Log(LogLevel.Debug, () => "GET on messages");

                string storeName = parameters.storeName;
                int pageNumber   = parameters.pageNumber;
                ViewModelRetrieverResult <MessageListModel, MessageListModelError> messageListModelResult = messageListViewModelRetriever.Get(storeName, pageNumber);

                if (!messageListModelResult.IsError)
                {
                    return(Response.AsJson(messageListModelResult.Result));
                }
                switch (messageListModelResult.Error)
                {
                case (MessageListModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError));

                case (MessageListModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Misconfigured Message Viewer, unable to retrieve messages for store {0}", storeName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Post("/{storeName}/repost/{msgList}", parameters =>
            {
                try
                {
                    var handler        = handlerFactory.GetHandler <RepostCommand>();
                    string ids         = parameters.msgList;
                    var repostModelIds = ids.Split(',');
                    var repostCommand  = new RepostCommand {
                        StoreName = parameters.storeName, MessageIds = repostModelIds.ToList()
                    };
                    handler.Handle(repostCommand);

                    return(Response.AsJson <int>(0, HttpStatusCode.OK));
                }
                catch (Exception e)
                {
                    return(e);
                }
            });
        }
コード例 #2
0
        public void When_retrieving_messages_for_a_store()
        {
            _result = _messageListViewModelRetriever.Get(storeName, 1);

            //should_return_MessageListModel
            var model = _result.Result;

            Assert.NotNull(model);
            Assert.AreEqual(_messages.Count, model.MessageCount);

            //should_return_expected_message_state
            var foundMessage = model.Messages.Single(m => m.MessageId == _message1.Id);

            Assert.NotNull(foundMessage);

            Assert.AreEqual(_message1.Header.HandledCount, foundMessage.HandledCount);
            Assert.AreEqual(_message1.Header.MessageType.ToString(), foundMessage.MessageType);
            Assert.AreEqual(_message1.Header.Topic, foundMessage.Topic);
            Assert.AreEqual(_message1.Header.TimeStamp, foundMessage.TimeStamp);

            foreach (var key in _message1.Header.Bag.Keys)
            {
                foundMessage.Bag.Contains(key);
                foundMessage.Bag.Contains(_message1.Header.Bag[key].ToString());
            }
            Assert.AreEqual(_message1.Body.Value, foundMessage.MessageBody);

            //foundMessage.TimeStampUI.ShouldContain("ago");//fragile time-based
        }
コード例 #3
0
        public void When_searching_messages_for_matching_row_body()
        {
            _result = _messageListViewModelRetriever.Filter(_storeName, "topic3");

            //should_return_expected_model
            var model = _result.Result;

            model.Should().NotBeNull();
            model.MessageCount.Should().Be(1);
        }
コード例 #4
0
        public void When_searching_messages_for_non_matching_rows()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "zxy");

            // should_return_empty_model
            var model = _result.Result;

            model.Should().NotBeNull();
            model.MessageCount.Should().Be(0);
        }
        public void When_searching_messages_for_non_matching_rows()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "zxy");

            // should_return_empty_model
            var model = _result.Result;

            Assert.NotNull(model);
            Assert.AreEqual(0, model.MessageCount);
        }
コード例 #6
0
        public void When_searching_messages_for_matching_row_body()
        {
            _result = _messageListViewModelRetriever.Filter(_storeName, "topic3");

            //should_return_expected_model
            var model = _result.Result;

            Assert.NotNull(model);
            Assert.AreEqual(1, model.MessageCount);
        }
        public void When_filtering_messages_for_existent_store_that_is_not_viewer()
        {
            _result = _messageListViewModelRetriever.Filter(_storeName, "term");

            // should_not_return_MessageListModel
            var model = _result.Result;

            Assert.Null(model);
            Assert.True(_result.IsError);
            Assert.AreEqual(MessageListModelError.StoreMessageViewerNotImplemented, _result.Error);
        }
        public void When_filtering_messages_for_non_existent_store()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "term");

            //should_not_return_MessageListModel
            var model = _result.Result;

            model.Should().BeNull();
            _result.IsError.Should().BeTrue();
            _result.Error.Should().Be(MessageListModelError.StoreNotFound);
        }
        public void When_filtering_messages_for_existent_store_that_is_not_viewer()
        {
            _result = _messageListViewModelRetriever.Filter(_storeName, "term");

            // should_not_return_MessageListModel
            var model = _result.Result;

            model.Should().BeNull();
            _result.IsError.Should().BeTrue();
            _result.Error.Should().Be(MessageListModelError.StoreMessageViewerNotImplemented);
        }
        public void When_filtering_messages_for_non_existent_store()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "term");

            //should_not_return_MessageListModel
            var model = _result.Result;

            Assert.Null(model);
            Assert.True(_result.IsError);
            Assert.AreEqual(MessageListModelError.StoreNotFound, _result.Error);
        }
コード例 #11
0
        public void When_fitlering_messages_with_store_that_cannot_get()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "term");

            //should_return_error
            var model = _result.Result;

            Assert.Null(model);
            Assert.True(_result.IsError);
            Assert.AreEqual(MessageListModelError.StoreMessageViewerGetException, _result.Error);
            Assert.NotNull(_result.Exception);
            Assert.IsInstanceOf <AggregateException>(_result.Exception);
        }
        public void When_fitlering_messages_with_store_that_cannot_get()
        {
            _result = _messageListViewModelRetriever.Filter(storeName, "term");

            //should_return_error
            var model = _result.Result;

            model.Should().BeNull();
            _result.IsError.Should().BeTrue();
            _result.Error.Should().Be(MessageListModelError.StoreMessageViewerGetException);
            _result.Exception.Should().NotBeNull();
            _result.Exception.Should().BeOfType <AggregateException>();
        }
コード例 #13
0
        private IAmAMessageStore <Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult <MessageStoreViewerModel, MessageStoreViewerModelError> errorResult)
        {
            IAmAMessageStore <Message> foundStore = _storeViewerFactory.Connect(storeName);

            if (foundStore == null)
            {
                {
                    errorResult = new ViewModelRetrieverResult <MessageStoreViewerModel, MessageStoreViewerModelError>(
                        MessageStoreViewerModelError.StoreNotFound);
                    return(null);
                }
            }
            errorResult = null;
            return(foundStore);
        }
コード例 #14
0
        private IAmAMessageStoreViewer <Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult <MessageListModel, MessageListModelError> errorResult)
        {
            IAmAMessageStore <Message> foundStore = _messageStoreViewerFactory.Connect(storeName);

            if (foundStore == null)
            {
                errorResult = new ViewModelRetrieverResult <MessageListModel, MessageListModelError>(MessageListModelError.StoreNotFound);
                return(null);
            }
            var foundViewer = foundStore as IAmAMessageStoreViewer <Message>;

            if (foundViewer == null)
            {
                errorResult = new ViewModelRetrieverResult <MessageListModel, MessageListModelError>(MessageListModelError.StoreMessageViewerNotImplemented);
                return(null);
            }
            errorResult = null;
            return(foundViewer);
        }
コード例 #15
0
 public IAmAMessageStoreViewer<Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult<MessageListModel, MessageListModelError> errorResult)
 {
     IAmAMessageStore<Message> foundStore = _messageStoreViewerFactory.Connect(storeName);
     if (foundStore == null)
     {
         {
             errorResult = new ViewModelRetrieverResult<MessageListModel, MessageListModelError>(
                 MessageListModelError.StoreNotFound);
             return null;
         }
     }
     var foundViewer = foundStore as IAmAMessageStoreViewer<Message>;
     if (foundViewer == null)
     {
         {
             errorResult = new ViewModelRetrieverResult<MessageListModel, MessageListModelError>(
                 MessageListModelError.StoreMessageViewerNotImplemented);
             return null;
         }
     }
     errorResult = null;
     return foundViewer;
 }
コード例 #16
0
        public StoresNancyModule(
            IMessageStoreActivationStateListViewModelRetriever messageStoreActivationStateListViewModelRetriever,
            IMessageStoreViewerModelRetriever messageStoreViewerModelRetriever,
            IMessageListViewModelRetriever messageSearchListItemRetriever)
            : base("/stores")
        {
            Get("/", x =>
            {
                var result = messageStoreActivationStateListViewModelRetriever.Get();
                if (!result.IsError)
                {
                    return(Response.AsJson(result.Result));
                }
                switch (result.Error)
                {
                case (MessageStoreActivationStateListModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError("Mis-configured message viewer - unable to read config store"), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Get("/{name}", parameters =>
            {
                string storeName = parameters.Name;

                var result = messageStoreViewerModelRetriever.Get(storeName);
                if (!result.IsError)
                {
                    return(Response.AsJson(result.Result));
                }
                switch (result.Error)
                {
                case (MessageStoreViewerModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", storeName)), HttpStatusCode.NotFound));

                case (MessageStoreViewerModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", storeName)), HttpStatusCode.NotFound));

                case (MessageStoreViewerModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError));

                case (MessageStoreViewerModelError.GetActivationStateFromConfigError):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Mis-configured Message Viewer, unable to retrieve detail for store {0}", storeName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });

            Get("/search/{storeName}/{searchTerm}", parameters =>
            {
                string messageStoreName = parameters.storeName;
                string searchTerm       = parameters.searchTerm;

                ViewModelRetrieverResult <MessageListModel, MessageListModelError> searchModelResult = messageSearchListItemRetriever.Filter(messageStoreName, searchTerm);
                if (!searchModelResult.IsError)
                {
                    return(Response.AsJson(searchModelResult.Result));
                }
                switch (searchModelResult.Error)
                {
                case (MessageListModelError.StoreNotFound):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unknown store {0}", messageStoreName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerNotImplemented):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Found store {0} does not implement IMessageStoreViewer", messageStoreName)), HttpStatusCode.NotFound));

                case (MessageListModelError.StoreMessageViewerGetException):
                    return(Response.AsJson(new MessageViewerError(
                                               string.Format("Unable to retrieve messages for store {0}", messageStoreName)), HttpStatusCode.InternalServerError));

                default:
                    throw new Exception("Code can't reach here");
                }
            });
        }
コード例 #17
0
 private IAmAMessageStore<Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult<MessageStoreViewerModel, MessageStoreViewerModelError> errorResult)
 {
     IAmAMessageStore<Message> foundStore = _storeViewerFactory.Connect(storeName);
     if (foundStore == null)
     {
         {
             errorResult = new ViewModelRetrieverResult<MessageStoreViewerModel, MessageStoreViewerModelError>(
                     MessageStoreViewerModelError.StoreNotFound);
             return null;
         }
     }
     errorResult = null;
     return foundStore;
 }