-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from bingenito/enum-serialization
Serialized Fdc3 enum values should be camel case
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Tests/MorganStanley.Fdc3.NewtonsoftJson.Tests/ChannelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Morgan Stanley makes this available to you under the Apache License, | ||
* Version 2.0 (the "License"). You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* See the NOTICE file distributed with this work for additional information | ||
* regarding copyright ownership. Unless required by applicable law or agreed | ||
* to in writing, software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
|
||
using MorganStanley.Fdc3.Context; | ||
using MorganStanley.Fdc3.NewtonsoftJson.Serialization; | ||
using Newtonsoft.Json; | ||
|
||
namespace MorganStanley.Fdc3.NewtonsoftJson.Tests; | ||
|
||
public class ChannelTests | ||
{ | ||
[Fact] | ||
public void Channel_SerializedJsonHasCamelCaseId() | ||
{ | ||
IChannel channel = new MockChannel(); | ||
string serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings()); | ||
Assert.Contains("\"id\":", serializedChannel); | ||
} | ||
|
||
[Fact] | ||
public void Channel_SerializedJsonHasCamelCaseEnumValue() | ||
{ | ||
IChannel channel = new MockChannel(ChannelType.App); | ||
string serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings()); | ||
Assert.Contains("\"app\"", serializedChannel); | ||
|
||
channel = new MockChannel(ChannelType.User); | ||
serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings()); | ||
Assert.Contains("\"user\"", serializedChannel); | ||
|
||
channel = new MockChannel(ChannelType.Private); | ||
serializedChannel = JsonConvert.SerializeObject(channel, new Fdc3JsonSerializerSettings()); | ||
Assert.Contains("\"private\"", serializedChannel); | ||
} | ||
|
||
[Fact] | ||
public void Channel_ParsedChannelTypeFromJson() | ||
{ | ||
string json = "{\"id\":\"value\",\"type\":\"user\",\"displayMetadata\":{}}"; | ||
IChannel? channel = JsonConvert.DeserializeObject<MockChannel>(json); | ||
Assert.Equal("value", channel?.Id); | ||
Assert.Equal(ChannelType.User, channel?.Type); | ||
|
||
json = "{\"id\":\"value\",\"type\":\"app\",\"displayMetadata\":{}}"; | ||
channel = JsonConvert.DeserializeObject<MockChannel>(json); | ||
Assert.Equal(ChannelType.App, channel?.Type); | ||
} | ||
|
||
|
||
public class MockChannel : IChannel | ||
{ | ||
public MockChannel() | ||
{ | ||
} | ||
|
||
internal MockChannel(ChannelType channelType) | ||
{ | ||
this.Type = channelType; | ||
} | ||
|
||
public string Id { get; set; } = "value"; | ||
|
||
public ChannelType Type { get; set; } | ||
|
||
public IDisplayMetadata? DisplayMetadata { get; set; } = new DisplayMetadata(); | ||
|
||
public Task<IListener> AddContextListener<T>(string? contextType, ContextHandler<T> handler) where T : IContext | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task Broadcast(IContext context) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Task<IContext?> GetCurrentContext(string? contextType) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |