public void TestWrite()
        {
            IMessageBusWriter <string> messageBusWriter = _erector.Container.Resolve <IMessageBusWriter <string> >();
            string messageBusGUID           = null;
            IMessageBus <string> messageBus = GetMockedMessageBus <string>();
            bool   writeSucceeded           = false;
            string message = "Jesus Loves You.";

            try
            {
                writeSucceeded = messageBusWriter.Write(message);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual(ex.Message, messageBusWriter.ExceptionMessage_MessageBusCannotBeNull);
            }
            messageBusGUID = messageBusWriter.SpecifyTheMessageBus(messageBus);
            Assert.IsFalse(String.IsNullOrEmpty(messageBusGUID));
            try
            {
                writeSucceeded = messageBusWriter.Write(String.Empty);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual(ex.Message, messageBusWriter.ExceptionMessage_MessageCannotBeNullOrEmpty);
            }
            writeSucceeded = messageBusWriter.Write(message);
            Assert.IsTrue(writeSucceeded);
            messageBusWriter.Dispose();
        }
Exemple #2
0
        public bool RegisterClientProxyMessageBus(IClientProxy clientProxy)
        {
            lock (_thisLock)
            {
                try
                {
                    IMessageBus <string> messageBus = _erector.Container.Resolve <IMessageBus <string> >();
                    messageBus.SkipValidation = true;

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

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

                    clientProxy.MessageBusReaderBank = messageBusReaderBank;
                    clientProxy.MessageBusWiter      = messageBusWriter;

                    return(_messageBusBankServices.RegisterMessageBus(clientProxy.ServiceGUID, messageBus));
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(ex.Message, ex);
                }
            }
        }
Exemple #3
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);
        }
        public void TestSpecifyTheMessageBus()
        {
            IMessageBusWriter <string> messageBusWriter = _erector.Container.Resolve <IMessageBusWriter <string> >();
            string messageBusGUID = null;

            try
            {
                messageBusGUID = messageBusWriter.SpecifyTheMessageBus(null);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual(ex.Message, messageBusWriter.ExceptionMessage_MessageBusCannotBeNull);
            }
            IMessageBus <string> messageBus = GetMockedMessageBus <string>();

            messageBusGUID = messageBusWriter.SpecifyTheMessageBus(messageBus);
            Assert.IsFalse(String.IsNullOrEmpty(messageBusGUID));
            messageBusWriter.Dispose();
        }
Exemple #5
0
        public void ServiceFarmServiceCompositionRoute(IServiceFarmServiceBase serviceFarmServiceBase, IRoutingService <string> routingService, string ChatServiceName)
        {
            IMessageBus <string> messageBus = _erector.Container.Resolve <IMessageBus <string> >();

            messageBus.JsonSchema =
                (message) =>
            {
                IEnvelope envelope    = _marshaller.UnMarshall <IEnvelope>(message);
                string    serviceName = envelope.ServiceRoute.Split('.')[1];
                if (serviceName == ChatServiceNames.ModifyChatMessageService || serviceName == ChatServiceNames.GetNextChatMessageService)
                {
                    return(_erector.Container.Resolve <IChatMessageEnvelope>().GetMyJSONSchema());
                }
                else
                {
                    return(String.Empty);
                }
            };

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

            messageBusReaderBank.SpecifyTheMessageBus(messageBus);

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

            messageBusWriter.SpecifyTheMessageBus(messageBus);

            //TODO Refactor reader setup so that this behaves like the router and uses an Initializer method
            messageBusReaderBank.AddAnotherReader(serviceFarmServiceBase.ProcessMessage);
            messageBusReaderBank.AddAnotherReader(serviceFarmServiceBase.ProcessMessage);
            serviceFarmServiceBase.MessageBusReaderBank = messageBusReaderBank;

            serviceFarmServiceBase.MessageBusWiter = messageBusWriter;
            serviceFarmServiceBase.MessageBusBank  = _messageBusBankServices;

            IRoute <string> route = _erector.Container.Resolve <IRoute <string> >();

            route.Route = String.Format("{0}.{1}", routingService.RoutingServiceGUID, ChatServiceName);
            route.RegisterRouteHandler = serviceFarmServiceBase.HandleMessageFromRouter;
            routingService.RegisterRoute(route);

            _messageBusBankServices.RegisterMessageBus(serviceFarmServiceBase.ServiceGUID, messageBus);
            _serviceList.Add(serviceFarmServiceBase);
        }
Exemple #6
0
        public void TestModifyChatMessageServiceCreateUpdateDelete()
        {
            IMarshaller marshaller = _erector.Container.Resolve <IMarshaller>();

            IModifyChatMessageService modifyChatMessageService = _erector.Container.Resolve <IModifyChatMessageService>();

            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(modifyChatMessageService.ServiceGUID, messageBus);

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

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

            requestEnvelope.ChatMessageID = 123;

            //Test ITack cannot be null
            string tackCannotBeNull;

            try
            {
                tackCannotBeNull = modifyChatMessageService.Post(requestEnvelope);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                string message = ex.Message;
                Assert.AreEqual(message, modifyChatMessageService.ExceptionMessage_ITackCannotBeNull);
            }
            try
            {
                tackCannotBeNull = modifyChatMessageService.Put(requestEnvelope);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                string message = ex.Message;
                Assert.AreEqual(message, modifyChatMessageService.ExceptionMessage_ITackCannotBeNull);
            }
            try
            {
                tackCannotBeNull = modifyChatMessageService.Delete(requestEnvelope);
                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                string message = ex.Message;
                Assert.AreEqual(message, modifyChatMessageService.ExceptionMessage_ITackCannotBeNull);
            }

            modifyChatMessageService.Tack = GetMockedITack();
            requestEnvelope = _erector.Container.Resolve <IChatMessageEnvelope>();
            IChatMessageEnvelope responseEnvelope;

            //Create
            string created = modifyChatMessageService.Post(requestEnvelope);

            Assert.IsFalse(String.IsNullOrEmpty(created));
            responseEnvelope = marshaller.UnMarshall <IChatMessageEnvelope>(created);
            Assert.AreEqual(responseEnvelope.ChatMessageID, requestEnvelope.ChatMessageID);
            Assert.IsTrue(DateTime.Compare(responseEnvelope.CreatedDateTime, DateTime.MinValue) > 0);
            requestEnvelope = _erector.Container.Resolve <IChatMessageEnvelope>();
            requestEnvelope.ChatMessageID = 123;


            //Update
            string updated = modifyChatMessageService.Put(requestEnvelope);

            Assert.IsFalse(String.IsNullOrEmpty(updated));
            responseEnvelope = marshaller.UnMarshall <IChatMessageEnvelope>(updated);
            Assert.AreEqual(responseEnvelope.ChatMessageID, requestEnvelope.ChatMessageID);
            Assert.IsTrue(DateTime.Compare(responseEnvelope.ModifiedDateTime, requestEnvelope.ModifiedDateTime) > 0);
            requestEnvelope = _erector.Container.Resolve <IChatMessageEnvelope>();
            requestEnvelope.ChatMessageID = 123;


            //Delete
            string deleted = modifyChatMessageService.Delete(requestEnvelope);

            Assert.IsFalse(String.IsNullOrEmpty(deleted));
            responseEnvelope = marshaller.UnMarshall <IChatMessageEnvelope>(deleted);
            Assert.AreEqual(responseEnvelope.ChatMessageID, requestEnvelope.ChatMessageID);
            Assert.IsTrue(DateTime.Compare(responseEnvelope.ModifiedDateTime, requestEnvelope.ModifiedDateTime) > 0);
        }