public async Task <IEnumerable <KeyValuePair <string, string> > > GetMessageData(SagaMessage message) { var request = new RestRequestWithCache(string.Format(MessageBodyEndpoint, message.MessageId), message.Status == MessageStatus.Successful ? RestRequestWithCache.CacheStyle.Immutable : RestRequestWithCache.CacheStyle.IfNotModified); var body = await Execute(request, response => response.Content).ConfigureAwait(false); if (body == null) { return(Enumerable.Empty <KeyValuePair <string, string> >()); } return(body.StartsWith("<?xml") ? GetXmlData(body) : JsonPropertiesHelper.ProcessValues(body)); }
public void Saga_entity_compatible_with_serviceinsight() { var entity = new SagaEntity { IntProperty = 42, DateProperty = new DateTime(2017, 10, 26, 13, 3, 13, DateTimeKind.Utc), NullableDateProperty = new DateTime(2013, 10, 26, 13, 3, 13, DateTimeKind.Utc), GuidProperty = Guid.Empty, StringProperty = "String", TimeProperty = new TimeSpan(1, 2, 3, 4), NullableTimeProperty = new TimeSpan(5, 6, 7, 8), NestedObjectProperty = new NestedObject { IntProperty = 1 } }; var sagaDataJson = SimpleJson.SerializeObject(entity, new SagaEntitySerializationStrategy()); var sagaDataProperties = JsonPropertiesHelper.ProcessValues(sagaDataJson); var jsonObj = SimpleJson.DeserializeObject(sagaDataJson) as JsonObject; Assert.IsNotNull(jsonObj, "SimpleJson.DeserializeObject"); foreach (var p in sagaDataProperties) { Assert.IsTrue(jsonObj.ContainsKey(p.Key), $"{p.Key} not found"); var expected = jsonObj[p.Key].ToString(); var value = p.Value; //ServiceInsight uses default ToString() implementation, so adjust for that: switch (p.Key) { case "DateProperty": case "NullableDateProperty": expected = DateTime.Parse(expected).ToUniversalTime().ToString(); break; case "NestedObjectProperty": value = p.Value.Replace(Environment.NewLine, string.Empty).Replace(" ", string.Empty).Replace(",NServiceBus", ", NServiceBus"); break; default: break; } Assert.AreEqual(expected, value, p.Key); } }