Skip to content

Commit

Permalink
feat: taxonomy implementation with test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeem-cs committed Jul 22, 2024
1 parent 6de805c commit a5c87cc
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 3 deletions.
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
86 changes: 86 additions & 0 deletions Contentstack.Core.Tests/TaxonomyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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 GetEntriesWithAnyTaxonomyTerms()
{
Taxonomy query = client.Taxonomies();
query.Exists("taxonomies.one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.False(true, "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.False(true, "Result doesn't mathced the count.");
}
}

[Fact]
public async Task GetEntriesWithTaxonomyTermsandAlsoMatchingItsChildrenTerm()
{
Taxonomy query = client.Taxonomies();
query.EqualAndBelow("taxonomies.one", "term_one");
var result = await query.Find<Entry>();
if (result == null && result.Items.Count() == 0)
{
Assert.False(true, "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.False(true, "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

0 comments on commit a5c87cc

Please sign in to comment.