Skip to content

Commit 34869ae

Browse files
authored
Merge pull request #47 from contentstack/feat/DX-86-Taxonomy-Implementation
feat: taxonomy implementation with test cases
2 parents 7498881 + 2179fa2 commit 34869ae

File tree

7 files changed

+506
-4
lines changed

7 files changed

+506
-4
lines changed

.talismanrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ fileignoreconfig:
1010
- filename: Contentstack.Core/Models/Asset.cs
1111
checksum: 98b819cb9b1e6a9a9e5394ac23c07bc642a41c0c7512d169afc63afe3baa6fb3
1212
- filename: Contentstack.Core/Models/Query.cs
13-
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
13+
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
14+
- filename: Contentstack.Core/Models/Taxonomy.cs
15+
checksum: db8bcefdc7aafde4286e7fb6d67348bec49f1ac27b54d84fddca8124135bd779

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Version: 2.15.0
2+
#### Date: Jul-30-2024
3+
4+
##### New Feature:
5+
- Taxonomy class added
6+
17
### Version: 2.14.0
28
#### Date: May-28-2024
39

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using Xunit;
3+
using Contentstack.Core;
4+
using Contentstack.Core.Configuration;
5+
using Contentstack.Core.Models;
6+
using System.Threading.Tasks;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using Contentstack.Core.Tests.Models;
10+
using Newtonsoft.Json.Linq;
11+
using System.Reflection.PortableExecutable;
12+
13+
namespace Contentstack.Core.Tests
14+
{
15+
16+
public class TaxonomyTest
17+
{
18+
ContentstackClient client = StackConfig.GetStack();
19+
20+
private String numbersContentType = "numbers_content_type";
21+
String source = "source";
22+
23+
public double EPSILON { get; private set; }
24+
25+
[Fact]
26+
27+
public async Task TaxonomyExists()
28+
{
29+
// Description: Taxonomy Exists - Get Entries With Any Taxonomy Terms ($exists)
30+
Taxonomy query = client.Taxonomies();
31+
query.Exists("taxonomies.one");
32+
var result = await query.Find<Entry>();
33+
if (result == null && result.Items.Count() == 0)
34+
{
35+
Assert.Fail("Query.Exec is not match with expected result.");
36+
}
37+
else if (result != null)
38+
{
39+
bool IsTrue = false;
40+
foreach (Entry data in result.Items)
41+
{
42+
IsTrue = data.GetContentType() != null;
43+
if (!IsTrue)
44+
{
45+
break;
46+
}
47+
}
48+
Assert.True(IsTrue);
49+
}
50+
else
51+
{
52+
Assert.Fail("Result doesn't mathced the count.");
53+
}
54+
}
55+
56+
[Fact]
57+
public async Task TaxonomyEqualAndBelow()
58+
{
59+
// Description: Taxonomy EqualAndBelow - Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)
60+
Taxonomy query = client.Taxonomies();
61+
query.EqualAndBelow("taxonomies.one", "term_one");
62+
var result = await query.Find<Entry>();
63+
if (result == null && result.Items.Count() == 0)
64+
{
65+
Assert.Fail("Query.Exec is not match with expected result.");
66+
}
67+
else if (result != null)
68+
{
69+
bool IsTrue = false;
70+
foreach (Entry data in result.Items)
71+
{
72+
IsTrue = data.GetContentType() != null;
73+
if (!IsTrue)
74+
{
75+
break;
76+
}
77+
}
78+
Assert.True(IsTrue);
79+
}
80+
else
81+
{
82+
Assert.Fail("Result doesn't mathced the count.");
83+
}
84+
}
85+
86+
[Fact]
87+
public async Task TaxonomyBelow()
88+
{
89+
// Description: Taxonomy Below - Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)
90+
Taxonomy query = client.Taxonomies();
91+
query.Below("taxonomies.one", "term_one");
92+
var result = await query.Find<Entry>();
93+
if (result == null && result.Items.Count() == 0)
94+
{
95+
Assert.Fail("Query.Exec is not match with expected result.");
96+
}
97+
else if (result != null)
98+
{
99+
bool IsTrue = false;
100+
foreach (Entry data in result.Items)
101+
{
102+
IsTrue = data.GetContentType() != null;
103+
if (!IsTrue)
104+
{
105+
break;
106+
}
107+
}
108+
Assert.True(IsTrue);
109+
}
110+
else
111+
{
112+
Assert.Fail("Result doesn't mathced the count.");
113+
}
114+
}
115+
116+
[Fact]
117+
public async Task TaxonomyEqualAndAbove()
118+
{
119+
// Description: Taxonomy EqualAndAbove - Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)
120+
Taxonomy query = client.Taxonomies();
121+
query.EqualAndAbove("taxonomies.one", "term_one");
122+
var result = await query.Find<Entry>();
123+
if (result == null && result.Items.Count() == 0)
124+
{
125+
Assert.Fail("Query.Exec is not match with expected result.");
126+
}
127+
else if (result != null)
128+
{
129+
bool IsTrue = false;
130+
foreach (Entry data in result.Items)
131+
{
132+
IsTrue = data.GetContentType() != null;
133+
if (!IsTrue)
134+
{
135+
break;
136+
}
137+
}
138+
Assert.True(IsTrue);
139+
}
140+
else
141+
{
142+
Assert.Fail("Result doesn't mathced the count.");
143+
}
144+
}
145+
146+
[Fact]
147+
public async Task TaxonomyAbove()
148+
{
149+
// Description: Taxonomy Above - Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)
150+
Taxonomy query = client.Taxonomies();
151+
query.Above("taxonomies.one", "term_one");
152+
var result = await query.Find<Entry>();
153+
if (result == null && result.Items.Count() == 0)
154+
{
155+
Assert.Fail("Query.Exec is not match with expected result.");
156+
}
157+
else if (result != null)
158+
{
159+
bool IsTrue = false;
160+
foreach (Entry data in result.Items)
161+
{
162+
IsTrue = data.GetContentType() != null;
163+
if (!IsTrue)
164+
{
165+
break;
166+
}
167+
}
168+
Assert.True(IsTrue);
169+
}
170+
else
171+
{
172+
Assert.Fail("Result doesn't mathced the count.");
173+
}
174+
}
175+
176+
}
177+
}
178+

Contentstack.Core/ContentstackClient.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,22 @@ public AssetLibrary AssetLibrary()
409409
return asset;
410410
}
411411

412+
/// <summary>
413+
/// Represents a Taxonomy. Creates Taxonomy Instance.
414+
/// </summary>
415+
/// <returns>Current instance of Taxonomy, this will be useful for a chaining calls.</returns>
416+
/// <example>
417+
/// <code>
418+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
419+
/// Taxonomy taxonomy = stack.Taxonomy();
420+
/// </code>
421+
/// </example>
422+
public Taxonomy Taxonomies()
423+
{
424+
Taxonomy tx = new Taxonomy(this);
425+
return tx;
426+
}
427+
412428
/// <summary>
413429
/// Get version.
414430
/// </summary>

Contentstack.Core/Models/Query.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ public Query LessThan(String key, Object value)
590590
/// </example>
591591
public Query LessThanOrEqualTo(String key, Object value)
592592
{
593-
594593
if (key != null && value != null)
595594
{
596595

@@ -745,7 +744,6 @@ public Query NotEqualTo(String key, Object value)
745744
{
746745
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null);
747746
}
748-
749747
return this;
750748

751749
}

0 commit comments

Comments
 (0)