Skip to content

Commit

Permalink
Ensure that dates are sent in ISO 8601 format
Browse files Browse the repository at this point in the history
  • Loading branch information
karolz-ms committed Apr 19, 2017
1 parent 307a52f commit b68da9c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ internal class ShoeBoxEventData
public List<ShoeBoxRecord> records = new List<ShoeBoxRecord>();
}

private static readonly JsonSerializerSettings serializerSetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
private static readonly JsonSerializerSettings serializerSetting = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
DateFormatHandling = DateFormatHandling.IsoDateFormat
};

public static MessagingEventData ToMessagingEventData(this EventData eventData, out int messageSize)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>Microsoft.Diagnostics.EventFlow.Outputs.EventHub</AssemblyName>
<AssemblyOriginatorKeyFile>../../PublicKey.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionPrefix>1.1.1</VersionPrefix>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Microsoft.Diagnostics.EventFlow.Outputs.EventHub</PackageId>
<PackageTags>Microsoft;Diagnostics;EventFlow;Outputs;Event Hub;Event Hubs</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7072db92-0fda-4b87-abfd-897882c9284a")]

[assembly: InternalsVisibleTo("Microsoft.Diagnostics.EventFlow.Outputs.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

using System;
using System.IO;
using System.Text.RegularExpressions;
using Xunit;

namespace Microsoft.Diagnostics.EventFlow.Outputs.Tests
{
#if NET46
public class EventHubOutputTests
{
[Fact]
public void UsesIsoDateFormat()
{
EventData e = new EventData();
e.Payload.Add("DateTimeProperty", new DateTime(2017, 4, 19, 10, 15, 23, DateTimeKind.Utc));
e.Payload.Add("DateTimeOffsetProperty", new DateTimeOffset(2017, 4, 19, 10, 16, 07, TimeSpan.Zero));

var messagingData = EventDataExtensions.ToMessagingEventData(e, out int messageSize);
StreamReader sr = new StreamReader(messagingData.GetBodyStream());
string messageBody = sr.ReadToEnd();

var dateTimeRegex = new Regex(@"""DateTimeProperty"" \s* : \s* ""2017-04-19T10:15:23Z""", RegexOptions.IgnorePatternWhitespace, TimeSpan.FromMilliseconds(100));
Assert.Matches(dateTimeRegex, messageBody);

var dateTimeOffsetRegex = new Regex(@"""DateTimeOffsetProperty"" \s* : \s* ""2017-04-19T10:16:07\+00:00""", RegexOptions.IgnorePatternWhitespace, TimeSpan.FromMilliseconds(100));
Assert.Matches(dateTimeOffsetRegex, messageBody);
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
<AssemblyName>Microsoft.Diagnostics.EventFlow.Outputs.Tests</AssemblyName>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>../../PublicKey.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.1.0</RuntimeFrameworkVersion>
</PropertyGroup>
Expand All @@ -16,7 +19,9 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<ProjectReference Include="..\..\src\Microsoft.Diagnostics.EventFlow.Inputs.EventSource\Microsoft.Diagnostics.EventFlow.Inputs.EventSource.csproj" />
<ProjectReference Include="..\..\src\Microsoft.Diagnostics.EventFlow.Outputs.EventHub\Microsoft.Diagnostics.EventFlow.Outputs.EventHub.csproj" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="1.1.0" />
<PackageReference Include="WindowsAzure.ServiceBus" Version="3.3.2" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
Expand All @@ -26,6 +31,7 @@
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System;
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

using System;
using Moq;
using Xunit;

Expand Down

0 comments on commit b68da9c

Please sign in to comment.