Esempio n. 1
0
        public void TestGetNextChatMessageServiceGET()
        {
            IMarshaller marshaller = _erector.Container.Resolve <IMarshaller>();

            IGetNextChatMessageService getNextChatMessageService = _erector.Container.Resolve <IGetNextChatMessageService>();

            IMessageBus <string>           messageBus           = _erector.Container.Resolve <IMessageBus <string> >();
            IMessageBusReaderBank <string> messageBusReaderBank = _erector.Container.Resolve <IMessageBusReaderBank <string> >();

            messageBusReaderBank.SpecifyTheMessageBus(messageBus);
            IMessageBusWriter <string> messageBusWriter = _erector.Container.Resolve <IMessageBusWriter <string> >();

            messageBusWriter.SpecifyTheMessageBus(messageBus);

            IMessageBusBank <string> messageBusBank = _erector.Container.Resolve <IMessageBusBank <string> >();

            messageBusBank.RegisterMessageBus(getNextChatMessageService.ServiceGUID, messageBus);

            getNextChatMessageService.MessageBusBank       = messageBusBank;
            getNextChatMessageService.MessageBusReaderBank = messageBusReaderBank;
            getNextChatMessageService.MessageBusReaderBank.AddAnotherReader(getNextChatMessageService.ProcessMessage);
            getNextChatMessageService.MessageBusWiter = messageBusWriter;

            IChatMessageEnvelope requestEnvelope = _erector.Container.Resolve <IChatMessageEnvelope>();

            requestEnvelope.ChatMessageID = 123;

            //Test ITack cannot be null
            string tackCannotBeNull;

            try
            {
                tackCannotBeNull = getNextChatMessageService.Get(requestEnvelope);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                string message = ex.Message;
                Assert.AreEqual(message, getNextChatMessageService.ExceptionMessage_ITackCannotBeNull);
            }

            getNextChatMessageService.Tack = GetMockedITack();
            requestEnvelope = GetValidChatMessageEnvelope();
            requestEnvelope.CreatedDateTime = DateTime.Now;
            IChatMessageEnvelope responseEnvelope;

            //Read next message
            string read = getNextChatMessageService.Get(requestEnvelope);

            Assert.IsFalse(String.IsNullOrEmpty(read));
            responseEnvelope = marshaller.UnMarshall <IChatMessageEnvelope>(read);
            Assert.IsNotNull(responseEnvelope);
            Assert.IsTrue(responseEnvelope.ChatMessageID > requestEnvelope.ChatMessageID);
            Assert.AreEqual(responseEnvelope.ChatChannelID, requestEnvelope.ChatChannelID);
            Assert.IsTrue(DateTime.Compare(responseEnvelope.CreatedDateTime, requestEnvelope.CreatedDateTime) > 0);
        }
Esempio n. 2
0
        public void TestGetNextChatMessageServiceSendResponse()
        {
            IMarshaller marshaller = _erector.Container.Resolve <IMarshaller>();

            IGetNextChatMessageService getNextChatMessageService = _erector.Container.Resolve <IGetNextChatMessageService>();

            string clientGuid = Guid.NewGuid().ToString();
            IMessageBus <string> messageBus_Client  = _erector.Container.Resolve <IMessageBus <string> >();
            IMessageBus <string> messageBus_Service = _erector.Container.Resolve <IMessageBus <string> >();

            messageBus_Client.JsonSchema =
                (message) =>
            {
                //NOTE: Require this schema for the client only since I'm not sending anything to the service.
                return(_erector.Container.Resolve <IChatMessageEnvelope>().GetMyJSONSchema());
            };

            IMessageBusBank <string> messageBusBank = _erector.Container.Resolve <IMessageBusBank <string> >();

            messageBusBank.RegisterMessageBus(getNextChatMessageService.ServiceGUID, messageBus_Service);
            messageBusBank.RegisterMessageBus(clientGuid, messageBus_Client);


            IChatMessageEnvelope requestEnvelope = GetValidChatMessageEnvelope();
            string requestPayload = marshaller.MarshallPayloadJSON(requestEnvelope);
            bool   success        = false;

            //MessageBusBank cannot be null
            try
            {
                success = getNextChatMessageService.SendResponse(clientGuid, requestPayload);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                string message = ex.Message;
                Assert.AreEqual(message, getNextChatMessageService.ExceptionMessage_MessageBusBankCannotBeNull);
            }
            success = false;

            //Client should recieve message in their message bus.
            getNextChatMessageService.MessageBusBank = messageBusBank;
            success = getNextChatMessageService.SendResponse(clientGuid, requestPayload);
            Assert.IsTrue(success);
            string clientMessage = messageBus_Client.ReceiveMessage();

            Assert.IsFalse(String.IsNullOrEmpty(clientMessage));
            Assert.AreEqual(requestPayload, clientMessage);
        }
Esempio n. 3
0
        public bool CompositionRoute()
        {
            lock (_thisLock)
            {
                try
                {
                    //NOTE: Set up message bus banks
                    _messageBusBankRouters  = _erector.Container.Resolve <IMessageBusBank <string> >();
                    _messageBusBankServices = _erector.Container.Resolve <IMessageBusBank <string> >();

                    //**** Set up Network A ****/
                    //NOTE: Set up router A
                    IRoutingService <string> routingServiceA = _erector.Container.Resolve <IRoutingService <string> >();
                    ISkyWatch skyWatchA = _erector.Container.Resolve <ISkyWatch>();

                    //NOTE: Set up the ModifyChatMessageService A
                    IModifyChatMessageService modifyChatMessageServiceA = _erector.Container.Resolve <IModifyChatMessageService>();
                    ServiceFarmServiceCompositionRoute(modifyChatMessageServiceA, routingServiceA, ChatServiceNames.ModifyChatMessageService);
                    ChatMessageServiceCompositionRoute(modifyChatMessageServiceA, routingServiceA, skyWatchA);

                    //NOTE: Set up the GetNextChatMessageService A
                    IGetNextChatMessageService getNextChatMessageServiceA = _erector.Container.Resolve <IGetNextChatMessageService>();
                    ServiceFarmServiceCompositionRoute(getNextChatMessageServiceA, routingServiceA, ChatServiceNames.GetNextChatMessageService);
                    ChatMessageServiceCompositionRoute(getNextChatMessageServiceA, routingServiceA, skyWatchA);

                    //NOTE: Set up the GetLatestChatMessageService A
                    IGetLatestChatMessageService getLatestChatMessageServiceA = _erector.Container.Resolve <IGetLatestChatMessageService>();
                    ServiceFarmServiceCompositionRoute(getLatestChatMessageServiceA, routingServiceA, ChatServiceNames.GetLatestChatMessageService);
                    ChatMessageServiceCompositionRoute(getLatestChatMessageServiceA, routingServiceA, skyWatchA);


                    return(true);
                }
                catch (Exception ex)
                {
                    _log.Error(String.Format("CompositionRoute() - Exception: \n{0}\n{1} \n\n InnerException: \n{2}\n{3}\n\n", ex.Message, ex.StackTrace, ex.InnerException.Message, ex.InnerException.StackTrace));
                    throw new ApplicationException(ex.Message, ex);
                }
            }
        }