Skip to content

Commit 24ad6be

Browse files
authored
Merge pull request #50 from contentstack/next
Taxonomy & Variants Implementation with test cases
2 parents 5aef08e + 1ed0f93 commit 24ad6be

File tree

12 files changed

+687
-26
lines changed

12 files changed

+687
-26
lines changed

.github/workflows/nuget-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Push generated package to GitHub registry
2222
run: |
2323
cd out
24-
dotnet nuget push "contentstack.csharp.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate --no-symbols true --source https://api.nuget.org/v3/index.json
24+
dotnet nuget push "contentstack.csharp.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate --no-symbols --source https://api.nuget.org/v3/index.json
2525
2626
publish-git:
2727
runs-on: windows-latest
@@ -41,4 +41,4 @@ jobs:
4141
- name: Push generated package to GitHub registry
4242
run: |
4343
cd out
44-
dotnet nuget push "contentstack.csharp.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate --no-symbols true --source https://api.nuget.org/v3/index.json
44+
dotnet nuget push "contentstack.csharp.*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate --no-symbols --source https://api.nuget.org/v3/index.json

.talismanrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ fileignoreconfig:
1010
- filename: Contentstack.Core/Models/Asset.cs
1111
checksum: 98b819cb9b1e6a9a9e5394ac23c07bc642a41c0c7512d169afc63afe3baa6fb3
1212
- filename: Contentstack.Core/Models/Query.cs
13-
checksum: 9237bb4d3e862fad7f3c6d9bad47873758a18617dc9c90d28015dcea267fcd9e
13+
checksum: ceea632e4ea870f35ad3bd313e9f8b4e5ec21aa86f006fca2e0a32945999ba67
14+
- filename: Contentstack.Core/Models/Taxonomy.cs
15+
checksum: db8bcefdc7aafde4286e7fb6d67348bec49f1ac27b54d84fddca8124135bd779
16+
- filename: .github/workflows/nuget-publish.yml
17+
checksum: 53ba4ce874c4d2362ad00deb23f5a6ec219318860352f997b945e9161a580651

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### Version: 2.16.0
2+
#### Date: Sep-3-2024
3+
4+
##### New Feature:
5+
- Added Early Access Header Support
6+
7+
### Version: 2.15.0
8+
#### Date: Jul-30-2024
9+
10+
##### New Feature:
11+
- Taxonomy class added
12+
113
### Version: 2.14.0
214
#### Date: May-28-2024
315

Contentstack.Core.Tests/EntryTest.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,59 @@ public async Task FetchEntryByUIDPublishFallback()
7171
list.Add("ja-jp");
7272
ContentType contenttype = client.ContentType(source);
7373
string uid = await GetUID("source1");
74-
Entry sourceEntry = await contenttype.Entry(uid)
74+
Entry sourceEntry = contenttype.Entry(uid);
75+
await sourceEntry
7576
.SetLocale("ja-jp")
7677
.IncludeFallback()
7778
.Fetch<Entry>();
7879

7980
Assert.Contains((string)(sourceEntry.Get("publish_details") as JObject).GetValue("locale"), list);
8081
}
8182

83+
[Fact]
84+
public async Task FetchEntryByVariant()
85+
{
86+
ContentType contenttype = client.ContentType(source);
87+
string uid = await GetUID("source1");
88+
Entry sourceEntry = contenttype.Entry(uid);
89+
await sourceEntry
90+
.Variant("variant1")
91+
.Fetch<Entry>().ContinueWith((t) =>
92+
{
93+
Entry result = t.Result;
94+
if (result == null)
95+
{
96+
Assert.False(true, "Entry.Fetch is not match with expected result.");
97+
}
98+
else
99+
{
100+
Assert.True(result.Uid == sourceEntry.Uid);
101+
}
102+
});
103+
}
104+
105+
[Fact]
106+
public async Task FetchEntryByVariants()
107+
{
108+
ContentType contenttype = client.ContentType(source);
109+
string uid = await GetUID("source1");
110+
Entry sourceEntry = contenttype.Entry(uid);
111+
await sourceEntry
112+
.Variant(new List<string> { "variant1", "variant2" })
113+
.Fetch<Entry>().ContinueWith((t) =>
114+
{
115+
Entry result = t.Result;
116+
if (result == null)
117+
{
118+
Assert.False(true, "Entry.Fetch is not match with expected result.");
119+
}
120+
else
121+
{
122+
Assert.True(result.Uid == sourceEntry.Uid);
123+
}
124+
});
125+
}
126+
82127
[Fact]
83128
public async Task FetchEntryByUIDPublishWithoutFallback()
84129
{
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/Configuration/ContentstackOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ public ContentstackOptions()
7474
{
7575
Timeout = 30000; // Set default value
7676
}
77-
}
7877

78+
/// <summary>
79+
/// TheEarlyAccessHeader used to set service which the user has early access to.
80+
/// </summary>
81+
public string[] EarlyAccessHeader { get; set; }
82+
}
83+
7984
internal class ContentstackRegionConverter : TypeConverter
8085
{
8186
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)

Contentstack.Core/ContentstackClient.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public ContentstackClient(IOptions<ContentstackOptions> options)
8787
{
8888
this.SetHeader("access_token", _options.DeliveryToken);
8989
}
90+
if(_options.EarlyAccessHeader !=null)
91+
{
92+
this.SetHeader("x-header-ea", string.Join(",", _options.EarlyAccessHeader));
93+
}
9094
Config cnfig = new Config();
9195
cnfig.Environment = _options.Environment;
9296
if (_options.Host != null)
@@ -409,6 +413,22 @@ public AssetLibrary AssetLibrary()
409413
return asset;
410414
}
411415

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

Contentstack.Core/Internals/ContentstackRegion.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
namespace Contentstack.Core.Internals
1+
namespace Contentstack.Core.Internals
32
{
43
/// <summary>
54
/// Contentstack region.

Contentstack.Core/Models/Entry.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,56 @@ public void RemoveHeader(string key)
378378

379379
}
380380

381+
382+
383+
/// <summary>
384+
/// To set variants header using Entry instance.
385+
/// </summary>
386+
/// <param name="variant_header">Entry instance</param>
387+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
388+
/// <example>
389+
/// <code>
390+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
391+
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Entry(&quot;entry_uid&quot;);
392+
///
393+
/// csEntry.Variant("variant_entry_1");
394+
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
395+
/// //Your callback code.
396+
/// //var result = entryResult.Result.GetMetadata();
397+
/// });
398+
/// </code>
399+
/// </example>
400+
public Entry Variant(string variant_header)
401+
{
402+
this.SetHeader("x-cs-variant-uid", variant_header);
403+
return this;
404+
}
405+
406+
407+
408+
/// <summary>
409+
/// To set multiple variants headers using Entry instance.
410+
/// </summary>
411+
/// <param name="variant_headers">Entry instance</param>
412+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
413+
/// <example>
414+
/// <code>
415+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
416+
/// Entry csEntry = stack.ContentType(&quot;contentType_id&quot;).Query();
417+
///
418+
/// csEntry.Variant(new List<string> { "variant_entry_1", "variant_entry_2", "variant_entry_3" });
419+
/// csEntry.Fetch&lt;Product&gt;().ContinueWith((entryResult) =&gt; {
420+
/// //Your callback code.
421+
/// //var result = entryResult.Result.GetMetadata();
422+
/// });
423+
/// </code>
424+
/// </example>
425+
public Entry Variant(List<string> variant_headers)
426+
{
427+
this.SetHeader("x-cs-variant-uid", string.Join(",", variant_headers));
428+
return this;
429+
}
430+
381431
/// <summary>
382432
/// Get metadata of entry.
383433
/// </summary>

0 commit comments

Comments
 (0)