Skip to content

Commit a7c9a57

Browse files
committed
feat: taxonomy implementation with test cases
1 parent 7498881 commit a7c9a57

File tree

5 files changed

+407
-3
lines changed

5 files changed

+407
-3
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
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 GetEntriesWithAnyTaxonomyTerms()
28+
{
29+
Taxonomy query = client.Taxonomies();
30+
query.Exists("taxonomies.one");
31+
var result = await query.Find<Entry>();
32+
if (result == null && result.Items.Count() == 0)
33+
{
34+
Assert.False(true, "Query.Exec is not match with expected result.");
35+
}
36+
else if (result != null)
37+
{
38+
bool IsTrue = false;
39+
foreach (Entry data in result.Items)
40+
{
41+
IsTrue = data.GetContentType() != null;
42+
if (!IsTrue)
43+
{
44+
break;
45+
}
46+
}
47+
Assert.True(IsTrue);
48+
}
49+
else
50+
{
51+
Assert.False(true, "Result doesn't mathced the count.");
52+
}
53+
}
54+
55+
[Fact]
56+
public async Task GetEntriesWithTaxonomyTermsandAlsoMatchingItsChildrenTerm()
57+
{
58+
Taxonomy query = client.Taxonomies();
59+
query.EqualAndBelow("taxonomies.one", "term_one");
60+
var result = await query.Find<Entry>();
61+
if (result == null && result.Items.Count() == 0)
62+
{
63+
Assert.False(true, "Query.Exec is not match with expected result.");
64+
}
65+
else if (result != null)
66+
{
67+
bool IsTrue = false;
68+
foreach (Entry data in result.Items)
69+
{
70+
IsTrue = data.GetContentType() != null;
71+
if (!IsTrue)
72+
{
73+
break;
74+
}
75+
}
76+
Assert.True(IsTrue);
77+
}
78+
else
79+
{
80+
Assert.False(true, "Result doesn't mathced the count.");
81+
}
82+
}
83+
84+
}
85+
}
86+

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)