Skip to content

Commit 673b7c7

Browse files
authored
Merge pull request #185 from contentstack/enh/DX-7309-webhook-migration
Refactor WebhookModel to use System.Text.Json for serialization
2 parents ef37861 + dc598c4 commit 673b7c7

2 files changed

Lines changed: 28 additions & 30 deletions

File tree

Contentstack.Management.Core.Unit.Tests/Models/WebhookTest.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Should_Create_Webhook()
6464
ContentstackResponse response = _stack.Webhook().Create(_fixture.Create<WebhookModel>());
6565

6666
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
67-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
67+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
6868
}
6969

7070
[TestMethod]
@@ -73,7 +73,7 @@ public async System.Threading.Tasks.Task Should_Create_Webhook_Async()
7373
ContentstackResponse response = await _stack.Webhook().CreateAsync(_fixture.Create<WebhookModel>());
7474

7575
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
76-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
76+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
7777
}
7878

7979
[TestMethod]
@@ -82,7 +82,7 @@ public void Should_Query_Webhook()
8282
ContentstackResponse response = _stack.Webhook().Query().Find();
8383

8484
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
85-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
85+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
8686
}
8787

8888
[TestMethod]
@@ -91,7 +91,7 @@ public async System.Threading.Tasks.Task Should_Query_Webhook_Async()
9191
ContentstackResponse response = await _stack.Webhook().Query().FindAsync();
9292

9393
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
94-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
94+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
9595
}
9696

9797
[TestMethod]
@@ -100,7 +100,7 @@ public void Should_Fetch_Webhook()
100100
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Fetch();
101101

102102
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
103-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
103+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
104104
}
105105

106106
[TestMethod]
@@ -109,7 +109,7 @@ public async System.Threading.Tasks.Task Should_Find_Webhook_Async()
109109
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).FetchAsync();
110110

111111
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
112-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
112+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
113113
}
114114

115115
[TestMethod]
@@ -118,7 +118,7 @@ public void Should_Update_Webhook()
118118
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Update(_fixture.Create<WebhookModel>());
119119

120120
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
121-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
121+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
122122
}
123123

124124
[TestMethod]
@@ -127,7 +127,7 @@ public async System.Threading.Tasks.Task Should_Update_Webhook_Async()
127127
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).UpdateAsync(_fixture.Create<WebhookModel>());
128128

129129
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
130-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
130+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
131131
}
132132

133133
[TestMethod]
@@ -136,7 +136,7 @@ public void Should_Delete_Webhook()
136136
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Delete();
137137

138138
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
139-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
139+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
140140
}
141141

142142
[TestMethod]
@@ -145,7 +145,7 @@ public async System.Threading.Tasks.Task Should_Delete_Webhook_Async()
145145
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).DeleteAsync();
146146

147147
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
148-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
148+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
149149
}
150150

151151
[TestMethod]
@@ -154,7 +154,7 @@ public void Should_Executions_Webhook()
154154
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Executions();
155155

156156
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
157-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
157+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
158158
}
159159

160160
[TestMethod]
@@ -163,7 +163,7 @@ public async System.Threading.Tasks.Task Should_Executions_Webhook_Async()
163163
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).ExecutionsAsync();
164164

165165
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
166-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
166+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
167167
}
168168

169169
[TestMethod]
@@ -172,7 +172,7 @@ public void Should_Retry_Webhook()
172172
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Retry(_fixture.Create<string>());
173173

174174
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
175-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
175+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
176176
}
177177

178178
[TestMethod]
@@ -181,7 +181,7 @@ public async System.Threading.Tasks.Task Should_Retry_Webhook_Async()
181181
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).RetryAsync(_fixture.Create<string>());
182182

183183
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
184-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
184+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
185185
}
186186

187187
[TestMethod]
@@ -190,7 +190,7 @@ public void Should_Logs_Webhook()
190190
ContentstackResponse response = _stack.Webhook(_fixture.Create<string>()).Logs(_fixture.Create<string>());
191191

192192
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
193-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
193+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
194194
}
195195

196196
[TestMethod]
@@ -199,7 +199,7 @@ public async System.Threading.Tasks.Task Should_Logs_Webhook_Async()
199199
ContentstackResponse response = await _stack.Webhook(_fixture.Create<string>()).LogsAsync(_fixture.Create<string>());
200200

201201
Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
202-
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
202+
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
203203
}
204204
}
205205
}
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json;
2+
using System.Text.Json.Serialization;
33
namespace Contentstack.Management.Core.Models
44
{
5-
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
65
public class WebhookModel
76
{
8-
[JsonProperty(propertyName: "name")]
7+
[JsonPropertyName("name")]
98
public string Name { get; set; }
10-
[JsonProperty(propertyName: "destinations")]
9+
[JsonPropertyName("destinations")]
1110
public List<WebhookTarget> destinations { get; set; }
12-
[JsonProperty(propertyName: "channels")]
11+
[JsonPropertyName("channels")]
1312
public List<string> Channels { get; set; }
14-
[JsonProperty(propertyName: "branches")]
13+
[JsonPropertyName("branches")]
1514
public List<string> Branches { get; set; }
16-
[JsonProperty(propertyName: "retry_policy")]
15+
[JsonPropertyName("retry_policy")]
1716
public string RetryPolicy { get; set; }
18-
[JsonProperty(propertyName: "disabled")]
17+
[JsonPropertyName("disabled")]
1918
public bool Disabled { get; set; } = false;
20-
[JsonProperty(propertyName: "concise_payload")]
19+
[JsonPropertyName("concise_payload")]
2120
public bool ConcisePayload { get; set; } = true;
2221
}
2322

24-
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
2523
public class WebhookTarget
2624
{
27-
[JsonProperty(propertyName: "target_url")]
25+
[JsonPropertyName("target_url")]
2826
public string TargetUrl { get; set; }
29-
[JsonProperty(propertyName: "http_basic_auth")]
27+
[JsonPropertyName("http_basic_auth")]
3028
public string HttpBasicAuth { get; set; }
31-
[JsonProperty(propertyName: "http_basic_password")]
29+
[JsonPropertyName("http_basic_password")]
3230
public string HttpBasicPassword { get; set; }
33-
[JsonProperty(propertyName: "custom_header")]
31+
[JsonPropertyName("custom_header")]
3432
public List<Dictionary<string, object>> CustomHeader { get; set; }
3533
}
3634
}

0 commit comments

Comments
 (0)