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