public void TestDeSerializeMessage() { var chunkReq = new Message() { SenderId = System.Guid.NewGuid(), ConversationId = System.Guid.NewGuid(), MessageId = MessageType.UNKNOWN, MessageCount = 0 }; var converter = new JsonMessageConverter(); var blob = string.Format("{{\"SenderId\":\"{0}\",\"MessageId\":{1},\"ConversationId\":\"{2}\",\"MessageCount\":{3}}}", chunkReq.SenderId.ToString(), (int)chunkReq.MessageId, chunkReq.ConversationId.ToString(), chunkReq.MessageCount); var message = converter.DeSerialize(System.Text.Encoding.UTF8.GetBytes(blob)); Assert.AreEqual(chunkReq.SenderId, message.SenderId); Assert.AreEqual(chunkReq.MessageId, message.MessageId); Assert.AreEqual(chunkReq.ConversationId, message.ConversationId); Assert.AreEqual(chunkReq.MessageCount, message.MessageCount); }
public void Start() { var converter = new JsonMessageConverter(); var comm = new UdpCommunicator(new IPEndPoint(IPAddress.Any, 4000), converter); comm.Start(); var router = new MessageRouter(comm); var content = new Content() { FileName = "test_file.txt", ByteSize = 1024, ContentHash = new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }, Description = "Test file", LocalPath = "." }; var chunks = new HashSet <int>(new List <int>() { 0, 1, 2, 3 }); var worker = new ChunkReceiver(content, chunks, new Guid("11f684d9-53a5-4fd9-948f-5526e881f60c")); router.AddConversation(worker, new IPEndPoint(IPAddress.Loopback, 4001)); Console.ReadLine(); comm.Stop(); }
public void NestedObject() { var bar = new Bar(); bar.Foo.Name = "spam"; var converter = new JsonMessageConverter(); var message = converter.ToMessage(bar, new MessageProperties()); var marshalled = (Bar)converter.FromMessage(message); Assert.AreEqual(bar, marshalled); }
public void Hashtable() { var hashtable = new Dictionary <string, object>(); hashtable.Add("TICKER", "VMW"); hashtable.Add("PRICE", "103.2"); var converter = new JsonMessageConverter(); var message = converter.ToMessage(hashtable, new MessageProperties()); var marhsalledHashtable = (Dictionary <string, object>)converter.FromMessage(message); Assert.AreEqual("VMW", marhsalledHashtable["TICKER"]); Assert.AreEqual("103.2", marhsalledHashtable["PRICE"]); }
public void ConvertBackAndForward_SimpleClass_PropertiesAreEqual() { var source = new TestClass() { Id = 1, TestProperty = "foo" }; var converter = new JsonMessageConverter(); var result = converter.Serialize(source); var copy = converter.Deserialize <TestClass>(result); Assert.IsNotNull(copy); Assert.AreEqual(source.Id, copy.Id); Assert.AreEqual(source.TestProperty, copy.TestProperty); }
public void SimpleTrade() { var trade = new SimpleTrade(); trade.AccountName = "Acct1"; trade.IsBuyRequest = true; trade.OrderType = "Market"; trade.Price = new decimal(103.30); trade.Quantity = 100; trade.RequestId = "R123"; trade.Ticker = "VMW"; trade.UserName = "******"; var converter = new JsonMessageConverter(); var message = converter.ToMessage(trade, new MessageProperties()); var marshalledTrade = (SimpleTrade)converter.FromMessage(message); Assert.AreEqual(trade, marshalledTrade); }
public Form1() { InitializeComponent(); seederDataGridView.CellFormatting += formatBytes; this.FormClosing += CleanUp; persistenceManager = new PersistenceManager(); persistenceManager.Clear(PersistenceManager.StorageType.Remote); seederDataGridView.DataSource = persistenceManager.ReadContent().LocalContent; searchDataGridView.DataSource = persistenceManager.ReadContent().RemoteContent; converter = new JsonMessageConverter(); comm = new UdpCommunicator(new IPEndPoint(IPAddress.Any, Properties.Settings.Default.HostPort), converter); comm.Start(); router = new MessageRouter(comm); router.OnConversationRequest += HandleNewConversation; RegistryEndpoint = new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.RegistryAddress), Properties.Settings.Default.RegistryPort); }
public void TestDeSerializeAcknowledge() { var ack = new Acknowledge(Guid.NewGuid(), Guid.NewGuid(), 0, "Ack"); var converter = new JsonMessageConverter(); var blob = string.Format("{{\"SenderId\":\"{0}\",\"MessageId\":{1},\"ConversationId\":\"{2}\",\"MessageCount\":{3},\"StatusInformation\":\"{4}\"}}", ack.SenderId.ToString(), (int)ack.MessageId, ack.ConversationId.ToString(), ack.MessageCount, ack.StatusInformation); var message = (Acknowledge)converter.DeSerialize(System.Text.Encoding.UTF8.GetBytes(blob)); Assert.AreEqual(ack.SenderId, message.SenderId); Assert.AreEqual(ack.MessageId, message.MessageId); Assert.AreEqual(ack.ConversationId, message.ConversationId); Assert.AreEqual(ack.MessageCount, message.MessageCount); Assert.AreEqual(ack.StatusInformation, message.StatusInformation); }
public void Start() { var converter = new JsonMessageConverter(); var comm = new UdpCommunicator(new IPEndPoint(IPAddress.Any, 4001), converter); comm.Start(); var router = new MessageRouter(comm); router.OnConversationRequest += HandleNewConversation; ContentInfo = new Content() { FileName = "test_file.txt", ByteSize = 1024, ContentHash = new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }, Description = "Test file", LocalPath = "TestData" }; Console.ReadLine(); comm.Stop(); }
public void TestInt2809JavaTypePropertiesFromAmqp() { var config = new ConfigurationBuilder().Build(); var services = new ServiceCollection().BuildServiceProvider(); var context = new GenericApplicationContext(services, config); var channel = new Mock <RC.IModel>(); channel.Setup(c => c.IsOpen).Returns(true); var connection = new Mock <Messaging.RabbitMQ.Connection.IConnection>(); connection.Setup(c => c.IsOpen).Returns(true); connection.Setup(c => c.CreateChannel(It.IsAny <bool>())).Returns(channel.Object); var connectionFactory = new Mock <Messaging.RabbitMQ.Connection.IConnectionFactory>(); connectionFactory.Setup(f => f.CreateConnection()).Returns(connection.Object); var container = new DirectMessageListenerContainer(); container.ConnectionFactory = connectionFactory.Object; var adapter = new RabbitInboundChannelAdapter(context, container); var qchannel = new QueueChannel(context); adapter.OutputChannel = qchannel; object payload = new Foo("bar1"); var headers = new MessageHeaders(); var amqpMessage = new JsonMessageConverter().ToMessage(payload, headers); var listener = container.MessageListener as IChannelAwareMessageListener; listener.OnMessage(amqpMessage, null); var receive = qchannel.Receive(1000); var result = new JsonToObjectTransformer(context).Transform(receive) as IMessage; Assert.NotNull(result); Assert.Equal(payload, result.Payload); var sourceData = result.Headers.Get <IMessage>(IntegrationMessageHeaderAccessor.SOURCE_DATA); Assert.Null(sourceData); }
public void JsonMessageConverterTest() { var transaction = new TransactionMock(100, 200); var changes = new List <ReliableCollectionChange>(); var dictKey = new Guid(); var dictValue = new User("ashish"); var itemAddedEventArg = new NotifyDictionaryItemAddedEventArgs <Guid, User>(transaction, dictKey, dictValue); changes.Add(new ReliableCollectionChange("mydict", new List <EventArgs>() { itemAddedEventArg })); var notifyEvent = new NotifyTransactionAppliedEvent(transaction, changes); var jsonMessageConverter = new JsonMessageConverter(this.knownTypes); var encodedEvent = jsonMessageConverter.Serialize(notifyEvent); var decodedEvent = jsonMessageConverter.Deserialize <NotifyTransactionAppliedEvent>(encodedEvent); Assert.Equal(100, decodedEvent.Transaction.CommitSequenceNumber); Assert.Equal(200, decodedEvent.Transaction.TransactionId); Assert.Equal(1, decodedEvent.Changes.Count()); var firstRCChange = decodedEvent.Changes.First(); Assert.Equal("mydict", firstRCChange.CollectionName); Assert.Equal(1, firstRCChange.EventArgs.Count()); var firstEventArg = firstRCChange.EventArgs.First(); Assert.True(firstEventArg is NotifyDictionaryItemAddedEventArgs <Guid, User>); var decodedItemAddedArg = firstEventArg as NotifyDictionaryItemAddedEventArgs <Guid, User>; Assert.Equal(dictKey, decodedItemAddedArg.Key); Assert.Equal(dictValue.name, decodedItemAddedArg.Value.name); }
public Registry() { Converter = new JsonMessageConverter(); Communicator = new UdpCommunicator(new IPEndPoint(IPAddress.Any, 5000), Converter); Router = new MessageRouter(Communicator); }