microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/update-release-process

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Tests/Microsoft.Teams.Api.Tests/Entities/CitationEntityTests.cs

186lines · modecode

1using System.Text.Json;
2
3using Microsoft.Teams.Api.Entities;
4
5namespace Microsoft.Teams.Api.Tests.Entities;
6
7public class CitationEntityTests
8{
9 [Fact]
10 public void CitationEntity_JsonSerialize()
11 {
12 var appearance = new CitationAppearance()
13 {
14 Name = "doc",
15 Abstract = "document abstract",
16 Keywords = ["sample", "doc"],
17 Text = "full citation text"
18 };
19 var messageEntity = new MessageEntity()
20 {
21 Type = "https://schema.org/Message",
22 OType = "Message",
23 OContext = "https://schema.org",
24 AdditionalType = ["some", "string"]
25 };
26 var entity = new CitationEntity(messageEntity)
27 {
28 Citation = [new CitationEntity.Claim()
29 {
30 Position = 2,
31 Appearance = appearance.ToDocument()
32 }]
33 };
34
35 var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions()
36 {
37 WriteIndented = true,
38 IndentSize = 2,
39 DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
40 });
41
42 Assert.Equal(File.ReadAllText(
43 @"../../../Json/Entities/CitationEntity.json"
44 ), json);
45 }
46
47
48 [Fact]
49 public void CitationEntity_JsonSerialize_Derived()
50 {
51 var appearance = new CitationAppearance()
52 {
53 Name = "doc",
54 Abstract = "document abstract",
55 Keywords = ["sample", "doc"],
56 Text = "full citation text"
57 };
58 var messageEntity = new MessageEntity()
59 {
60 Type = "https://schema.org/Message",
61 OType = "Message",
62 OContext = "https://schema.org",
63 AdditionalType = ["some", "string"]
64 };
65 CitationEntity entity = new CitationEntity(messageEntity)
66 {
67 Citation = [new CitationEntity.Claim()
68 {
69 Position = 2,
70 Appearance = appearance.ToDocument()
71 }]
72 };
73
74 var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions()
75 {
76 WriteIndented = true,
77 IndentSize = 2,
78 DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
79 });
80
81 Assert.Equal(File.ReadAllText(
82 @"../../../Json/Entities/CitationEntity.json"
83 ), json);
84 }
85
86 [Fact]
87 public void CitationEntity_JsonSerialize_Interface_Derived()
88 {
89 var appearance = new CitationAppearance()
90 {
91 Name = "doc",
92 Abstract = "document abstract",
93 Keywords = ["sample", "doc"],
94 Text = "full citation text"
95 };
96 var messageEntity = new MessageEntity()
97 {
98 Type = "https://schema.org/Message",
99 OType = "Message",
100 OContext = "https://schema.org",
101 AdditionalType = ["some", "string"]
102 };
103 Entity entity = new CitationEntity(messageEntity)
104 {
105 Citation = [new CitationEntity.Claim()
106 {
107 Position = 2,
108 Appearance = appearance.ToDocument()
109 }]
110 };
111
112 var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions()
113 {
114 WriteIndented = true,
115 IndentSize = 2,
116 DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
117 });
118
119 Assert.Equal(File.ReadAllText(
120 @"../../../Json/Entities/CitationEntity.json"
121 ), json);
122 }
123
124
125 [Fact]
126 public void CitationEntity_JsonDeserialize()
127 {
128 var json = File.ReadAllText(@"../../../Json/Entities/CitationEntity.json");
129 var entity = JsonSerializer.Deserialize<CitationEntity>(json);
130 var appearance = new CitationAppearance()
131 {
132 Name = "doc",
133 Abstract = "document abstract",
134 Keywords = ["sample", "doc"],
135 Text = "full citation text"
136 };
137 var messageEntity = new MessageEntity()
138 {
139 Type = "https://schema.org/Message",
140 OType = "Message",
141 OContext = "https://schema.org",
142 AdditionalType = ["some", "string"]
143 };
144 var expected = new CitationEntity(messageEntity)
145 {
146 Citation = [new CitationEntity.Claim()
147 {
148 Position = 2,
149 Appearance = appearance.ToDocument()
150 }]
151 };
152
153 Assert.Equivalent(expected, entity);
154 }
155
156 [Fact]
157 public void CitationEntity_JsonDeserialize_Derived()
158 {
159 var json = File.ReadAllText(@"../../../Json/Entities/CitationEntity.json");
160 var entity = JsonSerializer.Deserialize<Entity>(json);
161 var appearance = new CitationAppearance()
162 {
163 Name = "doc",
164 Abstract = "document abstract",
165 Keywords = ["sample", "doc"],
166 Text = "full citation text"
167 };
168 var messageEntity = new MessageEntity()
169 {
170 Type = "https://schema.org/Message",
171 OType = "Message",
172 OContext = "https://schema.org",
173 AdditionalType = ["some", "string"]
174 };
175 var expected = new CitationEntity(messageEntity)
176 {
177 Citation = [new CitationEntity.Claim()
178 {
179 Position = 2,
180 Appearance = appearance.ToDocument()
181 }]
182 };
183
184 Assert.Equivalent(expected, entity);
185 }
186}