Esempio n. 1
0
        public void ProcessReceivedMessageInputValidMessageAssertValid()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();

            var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date };
            var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer);

            var inputGateway = RouterGatewayFactory.CreateInputGateway(_receiverEndPoint.Object, 5);

            var eventargs = new EventReceiverEndPointHandlerArgs
            {
                Message = Encoding.UTF8.GetBytes(jsonDataContractSerializer.Serialize(messageBus))
            };

            _receiverEndPoint.Setup(r => r.Start()).Raises(r => r.OnReceivedMessage += null, new object[] { null, eventargs });

            MessageBus messageReceived = null;
            inputGateway.OnMessage += (sender, args) => messageReceived = jsonDataContractSerializer.Deserialize<MessageBus>(args.Message);

            inputGateway.Start();

            Assert.AreEqual(messageBus.Body, messageReceived.Body);
            Assert.AreEqual(messageBus.Header.Type, messageReceived.Header.Type);
            Assert.AreEqual(messageBus.Header.BodyType, messageReceived.Header.BodyType);
        }
Esempio n. 2
0
        public void SendMessageAssertTrue()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();

            var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date };
            var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer);

            var message = string.Empty;

            _senderEndPoint.Setup(s => s.Send(It.IsAny<string>(),It.IsAny<int>())).Callback<string,int>((s,p) => message = s);

            var outputGateway = RouterGatewayFactory.CreateOutputGateway(_senderEndPoint.Object);
            var serialize = jsonDataContractSerializer.Serialize(messageBus);
            outputGateway.Send(Encoding.UTF8.GetBytes(serialize));
            Assert.AreEqual(serialize, message);
        }
Esempio n. 3
0
        public void SerializeSpanishLettersMessageBus()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();

            var messageBus = new MessageBus
            {
                Body = "El señor de l'ametlla del vallès está de vacaciones",
                Header = { BodyType = "System.string", CreatedAt = new DateTime(2010, 10, 10) }
            };

            var serialize = jsonDataContractSerializer.Serialize(messageBus);

            var deserialized = jsonDataContractSerializer.Deserialize(serialize, Encoding.UTF8, typeof(MessageBus)) as MessageBus;

            Assert.AreEqual(messageBus.Body, deserialized.Body);
            Assert.AreEqual(messageBus.Header, deserialized.Header);
        }
Esempio n. 4
0
        public void SerializeMessageBus()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();
            var callerContexts = new Stack<CallerContext>();
            callerContexts.Push(new CallerContext { Identification = new Identification() { Id = "IdTest", Type = "TypeTest" } });
            var messageBus = new MessageBus
                                 {
                                     Body = "Test",
                                     Header = { BodyType = "Un tipo de body cualquiera me vale.", CreatedAt = new DateTime(2010, 10, 10), CallStack = callerContexts }
                                 };

            var serialize = jsonDataContractSerializer.Serialize(messageBus);

            var bytes = MessageBusParser.ToBytes(messageBus);
            var routerHeader = MessageBusParser.GetHeaderFromBytes(bytes);
            var message = MessageBusParser.GetMessageFromBytes(bytes);

            Assert.AreEqual(serialize, message);
            Assert.AreEqual("IdTest", routerHeader.Identification.Id);
            Assert.AreEqual("TypeTest", routerHeader.Identification.Type);
        }
Esempio n. 5
0
        public void SendMessageAssertTrue()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();

            var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date };
            var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer);

            var message = string.Empty;

            _senderEndPoint.Setup(s => s.Send(It.IsAny<string>(), It.IsAny<int>())).Callback<string, int>((s,p) => message = s);

            var outputGateway = AgentGatewayFactory.CreateOutputGateway(_identification, _senderEndPoint.Object);

            outputGateway.Send(messageFake);

            var deserialized = jsonDataContractSerializer.Deserialize<MessageBus>(message);

            Assert.AreEqual(messageBus.Body, deserialized.Body);
            Assert.AreEqual(messageBus.Header.Type, deserialized.Header.Type);
            Assert.AreEqual(messageBus.Header.BodyType, deserialized.Header.BodyType);
        }
Esempio n. 6
0
        public void ProcessReceivedMessageInputValidMessageAssertValid()
        {
            var jsonDataContractSerializer = new JsonDataContractSerializer();

            var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date };
            var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer);

            var inputGateway = AgentGatewayFactory.CreateInputGateway<IMessage>(_receiverEndPoint.Object, 5);

            var eventargs = new EventReceiverEndPointHandlerArgs
                                {
                                    Message = Encoding.UTF8.GetBytes(jsonDataContractSerializer.Serialize(messageBus))
                                };

            _receiverEndPoint.Setup(r => r.Start()).Raises(r => r.OnReceivedMessage += null,
                                                            new object[] { null, eventargs });

            IMessage messageReceived = null;
            inputGateway.OnMessage += (sender, args) => messageReceived = args.Message;

            inputGateway.Start();

            Assert.AreEqual(messageFake.CreatedAt, ((IMessageFake)messageReceived).CreatedAt);
        }