Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }