Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using Contentstack.Management.Core.Tests.Helpers;
using Contentstack.Management.Core.Tests.Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;

namespace Contentstack.Management.Core.Tests.IntegrationTest
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public void Test009_Should_Get_Taxonomy_Locales()
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Locales();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Locales failed: {response.OpenResponse()}", "LocalesSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["taxonomies"], "Taxonomies in locales response");
}

Expand All @@ -207,7 +207,7 @@ public async Task Test010_Should_Get_Taxonomy_Locales_Async()
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).LocalesAsync();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"LocalesAsync failed: {response.OpenResponse()}", "LocalesAsyncSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["taxonomies"], "Taxonomies in locales response");
}

Expand All @@ -219,8 +219,8 @@ public void Test011_Should_Localize_Taxonomy()
_weCreatedTestLocale = false;
ContentstackResponse localesResponse = _stack.Locale().Query().Find();
AssertLogger.IsTrue(localesResponse.IsSuccessStatusCode, $"Query locales failed: {localesResponse.OpenResponse()}", "QueryLocalesSuccess");
var jobj = localesResponse.OpenJObjectResponse();
var localesArray = jobj["locales"] as JArray ?? jobj["items"] as JArray;
var jobj = localesResponse.OpenJsonObjectResponse();
var localesArray = jobj["locales"] as JsonArray ?? jobj["items"] as JsonArray;
if (localesArray == null || localesArray.Count == 0)
{
AssertLogger.Inconclusive("Stack has no locales; skipping taxonomy localize tests.");
Expand Down Expand Up @@ -537,7 +537,7 @@ public void Test024_Should_Get_Term_Ancestors()
TestOutputLogger.LogContext("ChildTermUid", _childTermUid ?? "");
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).Ancestors();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Ancestors failed: {response.OpenResponse()}", "AncestorsSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj, "Ancestors response");
}

Expand All @@ -550,7 +550,7 @@ public async Task Test025_Should_Get_Term_Ancestors_Async()
TestOutputLogger.LogContext("ChildTermUid", _childTermUid ?? "");
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_childTermUid).AncestorsAsync();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"AncestorsAsync failed: {response.OpenResponse()}", "AncestorsAsyncSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj, "Ancestors async response");
}

Expand All @@ -563,7 +563,7 @@ public void Test026_Should_Get_Term_Descendants()
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Descendants();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Descendants failed: {response.OpenResponse()}", "DescendantsSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj, "Descendants response");
}

Expand All @@ -576,7 +576,7 @@ public async Task Test027_Should_Get_Term_Descendants_Async()
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).DescendantsAsync();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"DescendantsAsync failed: {response.OpenResponse()}", "DescendantsAsyncSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj, "Descendants async response");
}

Expand All @@ -589,7 +589,7 @@ public void Test028_Should_Get_Term_Locales()
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).Locales();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term Locales failed: {response.OpenResponse()}", "TermLocalesSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["terms"], "Terms in locales response");
}

Expand All @@ -602,7 +602,7 @@ public async Task Test029_Should_Get_Term_Locales_Async()
TestOutputLogger.LogContext("RootTermUid", _rootTermUid ?? "");
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms(_rootTermUid).LocalesAsync();
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Term LocalesAsync failed: {response.OpenResponse()}", "TermLocalesAsyncSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["terms"], "Terms in locales async response");
}

Expand Down Expand Up @@ -710,7 +710,7 @@ public void Test034_Should_Search_Terms()
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
ContentstackResponse response = _stack.Taxonomy(_taxonomyUid).Terms().Search("Root");
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Search terms failed: {response.OpenResponse()}", "SearchTermsSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["terms"] ?? jobj["items"], "Terms or items in search response");
}

Expand All @@ -722,7 +722,7 @@ public async Task Test035_Should_Search_Terms_Async()
TestOutputLogger.LogContext("TaxonomyUid", _taxonomyUid ?? "");
ContentstackResponse response = await _stack.Taxonomy(_taxonomyUid).Terms().SearchAsync("Root");
AssertLogger.IsTrue(response.IsSuccessStatusCode, $"SearchAsync terms failed: {response.OpenResponse()}", "SearchAsyncTermsSuccess");
var jobj = response.OpenJObjectResponse();
var jobj = response.OpenJsonObjectResponse();
AssertLogger.IsNotNull(jobj["terms"] ?? jobj["items"], "Terms or items in search async response");
}

Expand Down
16 changes: 8 additions & 8 deletions Contentstack.Management.Core.Unit.Tests/Models/TaxonomyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Contentstack.Management.Core.Queryable;
using Contentstack.Management.Core.Unit.Tests.Mokes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System.Text.Json;

namespace Contentstack.Management.Core.Unit.Tests.Models
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public void Should_Create_Taxonomy()
ContentstackResponse response = _stack.Taxonomy().Create(_fixture.Create<TaxonomyModel>());

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -71,7 +71,7 @@ public async System.Threading.Tasks.Task Should_Create_Taxonomy_Async()
ContentstackResponse response = await _stack.Taxonomy().CreateAsync(_fixture.Create<TaxonomyModel>());

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -80,7 +80,7 @@ public void Should_Query_Taxonomy()
ContentstackResponse response = _stack.Taxonomy().Query().Find();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -89,7 +89,7 @@ public async System.Threading.Tasks.Task Should_Query_Taxonomy_Async()
ContentstackResponse response = await _stack.Taxonomy().Query().FindAsync();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -98,7 +98,7 @@ public void Should_Fetch_Taxonomy()
ContentstackResponse response = _stack.Taxonomy(_fixture.Create<string>()).Fetch();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -107,7 +107,7 @@ public async System.Threading.Tasks.Task Should_Fetch_Taxonomy_Async()
ContentstackResponse response = await _stack.Taxonomy(_fixture.Create<string>()).FetchAsync();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand Down Expand Up @@ -182,7 +182,7 @@ public void Query_Throws_When_Uid_Is_Set()
public void Localize_When_Api_Returns_400_Returns_Unsuccessful_Response()
{
var httpMsg = MockResponse.Create(HttpStatusCode.BadRequest, null, "{\"error_message\":\"Invalid locale\",\"error_code\":400}");
var badResponse = new ContentstackResponse(httpMsg, JsonSerializer.Create(new JsonSerializerSettings()));
var badResponse = new ContentstackResponse(httpMsg, new JsonSerializerOptions());
var client = new ContentstackClient();
client.ContentstackPipeline.ReplaceHandler(new MockHttpHandler(badResponse));
client.contentstackOptions.Authtoken = _fixture.Create<string>();
Expand Down
16 changes: 8 additions & 8 deletions Contentstack.Management.Core.Unit.Tests/Models/TermTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Should_Create_Term()
ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Terms().Create(_fixture.Create<TermModel>());

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -70,7 +70,7 @@ public async System.Threading.Tasks.Task Should_Create_Term_Async()
ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).Terms().CreateAsync(_fixture.Create<TermModel>());

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -80,7 +80,7 @@ public void Should_Query_Terms()
ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Terms().Query().Find();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -90,7 +90,7 @@ public async System.Threading.Tasks.Task Should_Query_Terms_Async()
ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).Terms().Query().FindAsync();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -101,7 +101,7 @@ public void Should_Fetch_Term()
ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Terms(termUid).Fetch();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -112,7 +112,7 @@ public async System.Threading.Tasks.Task Should_Fetch_Term_Async()
ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).Terms(termUid).FetchAsync();

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -122,7 +122,7 @@ public void Should_Search_Terms()
ContentstackResponse response = _stack.Taxonomy(taxonomyUid).Terms().Search("test");

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand All @@ -132,7 +132,7 @@ public async System.Threading.Tasks.Task Should_Search_Terms_Async()
ContentstackResponse response = await _stack.Taxonomy(taxonomyUid).Terms().SearchAsync("test");

Assert.AreEqual(_contentstackResponse.OpenResponse(), response.OpenResponse());
Assert.AreEqual(_contentstackResponse.OpenJObjectResponse().ToString(), response.OpenJObjectResponse().ToString());
Assert.AreEqual(_contentstackResponse.OpenJsonObjectResponse().ToString(), response.OpenJsonObjectResponse().ToString());
}

[TestMethod]
Expand Down
25 changes: 12 additions & 13 deletions Contentstack.Management.Core/Models/TaxonomyModel.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Contentstack.Management.Core.Models
{
/// <summary>
/// Model for Taxonomy create/update and API response.
/// </summary>
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class TaxonomyModel
{
[JsonProperty(propertyName: "uid")]
[JsonPropertyName("uid")]
public string Uid { get; set; }

[JsonProperty(propertyName: "name")]
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonProperty(propertyName: "description")]
[JsonPropertyName("description")]
public string Description { get; set; }

[JsonProperty(propertyName: "locale")]
[JsonPropertyName("locale")]
public string Locale { get; set; }

[JsonProperty(propertyName: "terms_count")]
[JsonPropertyName("terms_count")]
public int? TermsCount { get; set; }

[JsonProperty(propertyName: "referenced_terms_count")]
[JsonPropertyName("referenced_terms_count")]
public int? ReferencedTermsCount { get; set; }

[JsonProperty(propertyName: "referenced_entries_count")]
[JsonPropertyName("referenced_entries_count")]
public int? ReferencedEntriesCount { get; set; }

[JsonProperty(propertyName: "referenced_content_type_count")]
[JsonPropertyName("referenced_content_type_count")]
public int? ReferencedContentTypeCount { get; set; }

[JsonProperty(propertyName: "created_at")]
[JsonPropertyName("created_at")]
public string CreatedAt { get; set; }

[JsonProperty(propertyName: "updated_at")]
[JsonPropertyName("updated_at")]
public string UpdatedAt { get; set; }

[JsonProperty(propertyName: "uuid")]
[JsonPropertyName("uuid")]
public string Uuid { get; set; }
}
}
Loading
Loading