Skip to content

Commit 028e2f3

Browse files
authored
Merge pull request #50 from bingenito/enum-serialization
Serialized Fdc3 enum values should be camel case
2 parents 934484a + b3703cc commit 028e2f3

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

src/Fdc3.NewtonsoftJson/MorganStanley.Fdc3.NewtonsoftJson.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<RootNamespace>MorganStanley.Fdc3.NewtonsoftJson</RootNamespace>
55
<AssemblyName>MorganStanley.Fdc3.NewtonsoftJson</AssemblyName>
66
<VersionPrefix>2.0.0</VersionPrefix>
7-
<VersionSuffix>alpha.4</VersionSuffix>
7+
<VersionSuffix>alpha.5</VersionSuffix>
88
<Product>.NET FDC3 Newtonsoft JSON</Product>
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile>

src/Fdc3.NewtonsoftJson/Serialization/Fdc3JsonSerializerSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Fdc3JsonSerializerSettings()
3030
{
3131
NamingStrategy = new Fdc3CamelCaseNamingStrategy()
3232
};
33-
this.Converters = new JsonConverter[] { new StringEnumConverter(), new RecipientJsonConverter() };
33+
this.Converters = new JsonConverter[] { new StringEnumConverter(new CamelCaseNamingStrategy()), new RecipientJsonConverter() };
3434
}
3535
}
3636
}

src/Fdc3/MorganStanley.Fdc3.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<RootNamespace>MorganStanley.Fdc3</RootNamespace>
55
<AssemblyName>MorganStanley.Fdc3</AssemblyName>
66
<VersionPrefix>2.0.0</VersionPrefix>
7-
<VersionSuffix>alpha.4</VersionSuffix>
7+
<VersionSuffix>alpha.5</VersionSuffix>
88
<Product>.NET FDC3</Product>
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Morgan Stanley makes this available to you under the Apache License,
3+
* Version 2.0 (the "License"). You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* See the NOTICE file distributed with this work for additional information
8+
* regarding copyright ownership. Unless required by applicable law or agreed
9+
* to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*/
14+
15+
using MorganStanley.Fdc3.Context;
16+
using MorganStanley.Fdc3.NewtonsoftJson.Serialization;
17+
using Newtonsoft.Json;
18+
19+
namespace MorganStanley.Fdc3.NewtonsoftJson.Tests;
20+
21+
public class ChannelTests
22+
{
23+
[Fact]
24+
public void Channel_SerializedJsonHasCamelCaseId()
25+
{
26+
IChannel channel = new MockChannel();
27+
string serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings());
28+
Assert.Contains("\"id\":", serializedChannel);
29+
}
30+
31+
[Fact]
32+
public void Channel_SerializedJsonHasCamelCaseEnumValue()
33+
{
34+
IChannel channel = new MockChannel(ChannelType.App);
35+
string serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings());
36+
Assert.Contains("\"app\"", serializedChannel);
37+
38+
channel = new MockChannel(ChannelType.User);
39+
serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings());
40+
Assert.Contains("\"user\"", serializedChannel);
41+
42+
channel = new MockChannel(ChannelType.Private);
43+
serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings());
44+
Assert.Contains("\"private\"", serializedChannel);
45+
}
46+
47+
[Fact]
48+
public void Channel_ParsedChannelTypeFromJson()
49+
{
50+
string json = "{\"id\":\"value\",\"type\":\"user\",\"displayMetadata\":{}}";
51+
IChannel? channel = JsonConvert.DeserializeObject<MockChannel>(json);
52+
Assert.Equal("value", channel?.Id);
53+
Assert.Equal(ChannelType.User, channel?.Type);
54+
55+
json = "{\"id\":\"value\",\"type\":\"app\",\"displayMetadata\":{}}";
56+
channel = JsonConvert.DeserializeObject<MockChannel>(json);
57+
Assert.Equal(ChannelType.App, channel?.Type);
58+
}
59+
60+
61+
public class MockChannel : IChannel
62+
{
63+
public MockChannel()
64+
{
65+
}
66+
67+
internal MockChannel(ChannelType channelType)
68+
{
69+
this.Type = channelType;
70+
}
71+
72+
public string Id { get; set; } = "value";
73+
74+
public ChannelType Type { get; set; }
75+
76+
public IDisplayMetadata? DisplayMetadata { get; set; } = new DisplayMetadata();
77+
78+
public Task<IListener> AddContextListener<T>(string? contextType, ContextHandler<T> handler) where T : IContext
79+
{
80+
throw new NotImplementedException();
81+
}
82+
83+
public Task Broadcast(IContext context)
84+
{
85+
throw new NotImplementedException();
86+
}
87+
88+
public Task<IContext?> GetCurrentContext(string? contextType)
89+
{
90+
throw new NotImplementedException();
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)