本文整理汇总了C#中JsonSerializer.BytesToMessage方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.BytesToMessage方法的具体用法?C# JsonSerializer.BytesToMessage怎么用?C# JsonSerializer.BytesToMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.BytesToMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_be_able_to_republish_message
public void Should_be_able_to_republish_message()
{
var serializer = new JsonSerializer();
var error = serializer.BytesToMessage<Error>(Encoding.UTF8.GetBytes(errorMessage));
var connectionFactory = new ConnectionFactory
{
HostName = "localhost",
UserName = "guest",
Password = "guest"
};
using (var connection = connectionFactory.CreateConnection())
using (var model = connection.CreateModel())
{
try
{
model.ExchangeDeclarePassive(error.Exchange);
var properties = model.CreateBasicProperties();
error.BasicProperties.CopyTo(properties);
var body = Encoding.UTF8.GetBytes(error.Message);
model.BasicPublish(error.Exchange, error.RoutingKey, properties, body);
}
catch (OperationInterruptedException)
{
Console.WriteLine("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'",
error.Exchange, connectionFactory.HostName, connectionFactory.VirtualHost);
}
}
}
示例2: Should_fail_to_deseralize_some_other_random_message
public void Should_fail_to_deseralize_some_other_random_message()
{
const string randomMessage = "{\"Text\":\"Hello World\"}";
var serializer = new JsonSerializer();
var error = serializer.BytesToMessage<Error>(Encoding.UTF8.GetBytes(randomMessage));
error.Message.ShouldBeNull();
}
示例3: Should_deserialise_error_message_correctly
public void Should_deserialise_error_message_correctly()
{
var serializer = new JsonSerializer();
var error = serializer.BytesToMessage<Error>(Encoding.UTF8.GetBytes(errorMessage));
error.RoutingKey.ShouldEqual("originalRoutingKey");
error.Message.ShouldEqual("{ Text:\"Hello World\"}");
}