Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: taxonomy implementation with test cases #47

Merged
merged 3 commits into from
Jul 24, 2024
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
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ fileignoreconfig:
- filename: Contentstack.Core/Models/Asset.cs
checksum: 98b819cb9b1e6a9a9e5394ac23c07bc642a41c0c7512d169afc63afe3baa6fb3
- filename: Contentstack.Core/Models/Query.cs
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
- filename: Contentstack.Core/Models/Taxonomy.cs
checksum: db8bcefdc7aafde4286e7fb6d67348bec49f1ac27b54d84fddca8124135bd779
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version: 2.15.0
#### Date: Jul-30-2024

##### New Feature:
- Taxonomy class added

### Version: 2.14.0
#### Date: May-28-2024

Expand Down
178 changes: 178 additions & 0 deletions Contentstack.Core.Tests/TaxonomyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using System;
using Xunit;
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using Contentstack.Core.Tests.Models;
using Newtonsoft.Json.Linq;
using System.Reflection.PortableExecutable;

namespace Contentstack.Core.Tests
{

public class TaxonomyTest
{
ContentstackClient client = StackConfig.GetStack();

private String numbersContentType = "numbers_content_type";
String source = "source";

public double EPSILON { get; private set; }

[Fact]

public async Task TaxonomyExists()
{
// Description: Taxonomy Exists - Get Entries With Any Taxonomy Terms ($exists)
Taxonomy query = client.Taxonomies();
query.Exists("taxonomies.one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.Fail("Query.Exec is not match with expected result.");
}
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
if (!IsTrue)
{
break;
}
}
Assert.True(IsTrue);
}
else
{
Assert.Fail("Result doesn't mathced the count.");
}
}

[Fact]
public async Task TaxonomyEqualAndBelow()
{
// Description: Taxonomy EqualAndBelow - Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)
Taxonomy query = client.Taxonomies();
query.EqualAndBelow("taxonomies.one", "term_one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.Fail("Query.Exec is not match with expected result.");
}
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
if (!IsTrue)
{
break;
}
}
Assert.True(IsTrue);
}
else
{
Assert.Fail("Result doesn't mathced the count.");
}
}

[Fact]
public async Task TaxonomyBelow()
{
// Description: Taxonomy Below - Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)
Taxonomy query = client.Taxonomies();
query.Below("taxonomies.one", "term_one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.Fail("Query.Exec is not match with expected result.");
}
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
if (!IsTrue)
{
break;
}
}
Assert.True(IsTrue);
}
else
{
Assert.Fail("Result doesn't mathced the count.");
}
}

[Fact]
public async Task TaxonomyEqualAndAbove()
{
// Description: Taxonomy EqualAndAbove - Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)
Taxonomy query = client.Taxonomies();
query.EqualAndAbove("taxonomies.one", "term_one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.Fail("Query.Exec is not match with expected result.");
}
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
if (!IsTrue)
{
break;
}
}
Assert.True(IsTrue);
}
else
{
Assert.Fail("Result doesn't mathced the count.");
}
}

[Fact]
public async Task TaxonomyAbove()
{
// Description: Taxonomy Above - Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)
Taxonomy query = client.Taxonomies();
query.Above("taxonomies.one", "term_one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.Fail("Query.Exec is not match with expected result.");
}
else if (result != null)
{
bool IsTrue = false;
foreach (Entry data in result.Items)
{
IsTrue = data.GetContentType() != null;
if (!IsTrue)
{
break;
}
}
Assert.True(IsTrue);
}
else
{
Assert.Fail("Result doesn't mathced the count.");
}
}

}
}

16 changes: 16 additions & 0 deletions Contentstack.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,22 @@ public AssetLibrary AssetLibrary()
return asset;
}

/// <summary>
/// Represents a Taxonomy. Creates Taxonomy Instance.
/// </summary>
/// <returns>Current instance of Taxonomy, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
/// Taxonomy taxonomy = stack.Taxonomy();
/// </code>
/// </example>
public Taxonomy Taxonomies()
{
Taxonomy tx = new Taxonomy(this);
return tx;
}

/// <summary>
/// Get version.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ public Query LessThan(String key, Object value)
/// </example>
public Query LessThanOrEqualTo(String key, Object value)
{

if (key != null && value != null)
{

Expand Down Expand Up @@ -745,7 +744,6 @@ public Query NotEqualTo(String key, Object value)
{
throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null);
}

return this;

}
Expand Down
Loading
Loading