Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding serialization for Amazon.Util.Internal.ConstantClass #16

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sdk/src/Core/Internal/Emitters/JsonSegmentMarshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using System.Net.Http;
using System.Reflection;
using Amazon.Runtime;
using Amazon.XRay.Recorder.Core.Internal.Entities;
using ThirdParty.LitJson;

Expand All @@ -42,6 +43,7 @@ public JsonSegmentMarshaller()
JsonMapper.RegisterExporter<Cause>(CauseExporter);
JsonMapper.RegisterExporter<Annotations>(AnnotationsExporter);
JsonMapper.RegisterExporter<HttpMethod>(HttpMethodExporter);
JsonMapper.RegisterExporter<ConstantClass>(ConstantClassExporter);
}

/// <summary>
Expand Down Expand Up @@ -303,5 +305,10 @@ private static void HttpMethodExporter(HttpMethod method, JsonWriter writer)
{
writer.Write(method.Method);
}

private static void ConstantClassExporter(ConstantClass constantClass, JsonWriter writer)
{
writer.Write(constantClass.Value);
}
}
}
21 changes: 21 additions & 0 deletions sdk/test/UnitTests/JsonSegmentMarshallerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Globalization;
using System.IO;
using System.Net.Http;
using Amazon.DynamoDBv2;
using Amazon.XRay.Recorder.Core.Internal.Emitters;
using Amazon.XRay.Recorder.Core.Internal.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -58,6 +59,26 @@ public void TestMarshallHttpMethod()

Assert.AreEqual(expect, actual);
}

[TestMethod]
public void TestMarshallConstantClass()
{
var segment = new Segment("test", "1-11111111-111111111111111111111111");
segment.Id = "1111111111111111";
segment.StartTime = 1;
segment.EndTime = 2;

// Some random instance of ConstantClass. Their constructor is private so we cant construct one
segment.Aws["value"] = ReturnConsumedCapacity.INDEXES;


_marshaller.Marshall(segment);

var expect = "{\"format\":\"json\",\"version\":1}\n{\"trace_id\":\"1-11111111-111111111111111111111111\",\"id\":\"1111111111111111\",\"start_time\":1,\"end_time\":2,\"name\":\"test\",\"aws\":{\"value\":\"INDEXES\"}}";
var actual = _marshaller.Marshall(segment);

Assert.AreEqual(expect, actual);
}

[TestMethod]
public void TestMarshallSimpleSegment()
Expand Down