Skip to content

Commit 239d31d

Browse files
authored
Merge pull request #8 from contentstack/2.4.0
Autoload converter support Delivery Token Support added JsonConverter autoload implemented
2 parents b2a0892 + bfa23c7 commit 239d31d

20 files changed

Lines changed: 536 additions & 117 deletions

CHANGELOG.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
### Version: 2.4.0
2+
#### Date: Aug-12-2020
3+
4+
##### Update API:
5+
- AssetLibrary
6+
- Count function added
7+
- Limit, Skip functionality added
8+
- Only, Except function added
9+
- Query
10+
- Count function added
11+
- CSJsonConverter
12+
- Added class CSJsonConverter to allow autoloading of converters
13+
##### Enhancement
14+
- Stack
15+
- Sync function to allow multiple SyncType
16+
##### Bug Fixes
17+
- Entry
18+
- GetContentType exception resolved
19+
##### Deprecation
20+
- Stack
21+
- AccessToken deprecated with support to add DeliveryToken
22+
123
### Version: 2.3.0
224
#### Date: Jun-22-2020
325

426
##### Update API:
527
- GetEnvironment issue resolved
6-
- GetDeleted at Method added
28+
- GetDeleted at Method addedAssetLibrary
729
- SyncType issue resolved
830

931
### Version: 2.2.1

Contentstack.AspNetCore/Contentstack.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Copyright>Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
1313
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
1414
<PackageTags>v1.0.0</PackageTags>
15-
<ReleaseVersion>2.3.0</ReleaseVersion>
15+
<ReleaseVersion>2.4.0</ReleaseVersion>
1616
</PropertyGroup>
1717

1818
<ItemGroup>

Contentstack.Core.Tests/AssetTest.cs

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Text.RegularExpressions;
99
using System.Collections;
10+
using Newtonsoft.Json.Linq;
1011

1112
namespace Contentstack.Core.Tests
1213
{
@@ -40,7 +41,7 @@ await asset.Fetch().ContinueWith((t) =>
4041
Assert.True(result.FileName.Length > 0);
4142
}
4243
});
43-
}
44+
}
4445

4546
[Fact]
4647
public async Task FetchAssets()
@@ -89,5 +90,93 @@ public async Task FetchAssetsIncludeRelativeURL()
8990
Assert.True(asset.FileName.Length > 0);
9091
}
9192
}
93+
94+
[Fact]
95+
public async Task FetchAssetCountAsync()
96+
{
97+
AssetLibrary assetLibrary = client.AssetLibrary();
98+
JObject jObject = await assetLibrary.Count();
99+
if (jObject == null)
100+
{
101+
Assert.False(true, "Query.Exec is not match with expected result.");
102+
}
103+
else if (jObject != null)
104+
{
105+
Assert.Equal(5, jObject.GetValue("assets"));
106+
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
107+
}
108+
else
109+
{
110+
Assert.False(true, "Result doesn't mathced the count.");
111+
}
112+
}
113+
114+
[Fact]
115+
public async Task FetchAssetSkipLimit()
116+
{
117+
AssetLibrary assetLibrary = client.AssetLibrary().Skip(2).Limit(5);
118+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
119+
if (assets == null)
120+
{
121+
Assert.False(true, "Query.Exec is not match with expected result.");
122+
}
123+
else if (assets != null)
124+
{
125+
Assert.Equal(3, assets.Items.Count());
126+
}
127+
else
128+
{
129+
Assert.False(true, "Result doesn't mathced the count.");
130+
}
131+
}
132+
133+
[Fact]
134+
public async Task FetchAssetOnly()
135+
{
136+
AssetLibrary assetLibrary = client.AssetLibrary().Only(new string[] { "url"});
137+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
138+
if (assets == null)
139+
{
140+
Assert.False(true, "Query.Exec is not match with expected result.");
141+
}
142+
else if (assets != null)
143+
{
144+
foreach (Asset asset in assets)
145+
{
146+
Assert.DoesNotContain(asset.Url, "http");
147+
Assert.Null(asset.Description);
148+
Assert.Null(asset.FileSize);
149+
Assert.Null(asset.Tags);
150+
Assert.Null(asset.Description);
151+
}
152+
}
153+
else
154+
{
155+
Assert.False(true, "Result doesn't mathced the count.");
156+
}
157+
}
158+
159+
[Fact]
160+
public async Task FetchAssetExcept()
161+
{
162+
AssetLibrary assetLibrary = client.AssetLibrary().Except(new string[] { "description" });
163+
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
164+
if (assets == null)
165+
{
166+
Assert.False(true, "Query.Exec is not match with expected result.");
167+
}
168+
else if (assets != null)
169+
{
170+
foreach (Asset asset in assets)
171+
{
172+
Assert.DoesNotContain(asset.Url, "http");
173+
Assert.Null(asset.Description);
174+
}
175+
}
176+
else
177+
{
178+
Assert.False(true, "Result doesn't mathced the count.");
179+
}
180+
}
92181
}
93-
}
182+
}

Contentstack.Core.Tests/Contentstack.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7-
<ReleaseVersion>2.3.0</ReleaseVersion>
7+
<ReleaseVersion>2.4.0</ReleaseVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>

Contentstack.Core.Tests/QueryTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,29 @@ public async Task FetchAllGetContentType()
5252
}
5353
}
5454

55+
[Fact]
56+
public async Task FetchAllCount()
57+
{
58+
Query query = client.ContentType(source).Query();
59+
query.SetLocale("en-us");
60+
var result = await query.Count();
61+
if (result == null)
62+
{
63+
Assert.False(true, "Query.Exec is not match with expected result.");
64+
}
65+
else if (result != null)
66+
{
67+
68+
Assert.Equal(7, result.GetValue("entries"));
69+
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
70+
}
71+
else
72+
{
73+
Assert.False(true, "Result doesn't mathced the count.");
74+
75+
}
76+
}
77+
5578
[Fact]
5679
public async Task FetchAll()
5780
{

Contentstack.Core.Tests/StackConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static ContentstackClient GetStack()
3434
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
3535
{
3636
ApiKey = apiKey,
37-
AccessToken = delivery_token,
37+
DeliveryToken = delivery_token,
3838
Environment = environment,
3939
Host = host,
4040
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Reflection;
6+
7+
namespace Contentstack.Core
8+
{
9+
[AttributeUsage(AttributeTargets.Class)]
10+
public class CSJsonConverterAttribute : Attribute
11+
{
12+
private readonly string name;
13+
private readonly bool isAutoloadEnable;
14+
private static ConcurrentDictionary<Type, List<Type>> _types = new ConcurrentDictionary<Type, List<Type>>();
15+
16+
/// <summary>
17+
/// Name for the JsonConverter
18+
/// </summary>
19+
public string Name
20+
{
21+
get
22+
{
23+
return this.name;
24+
}
25+
}
26+
27+
/// <summary>
28+
/// To enable autoload in ContentstackClient. Default is Enable.
29+
/// </summary>
30+
public bool IsAutoloadEnable
31+
{
32+
get
33+
{
34+
return this.isAutoloadEnable;
35+
}
36+
}
37+
38+
/// <summary>
39+
/// CSJsonConverterAttribute constructor
40+
/// </summary>
41+
/// <param name="name">Name for the JsonConverter</param>
42+
/// <param name="isAutoloadEnable"> To enable autoload in ContentstackClient. Default is Enable.</param>
43+
public CSJsonConverterAttribute(string name, bool isAutoloadEnable = true)
44+
{
45+
this.name = name;
46+
this.isAutoloadEnable = isAutoloadEnable;
47+
}
48+
49+
internal static IEnumerable<Type> GetCustomAttribute(Type attribute)
50+
{
51+
if (!_types.ContainsKey(attribute))
52+
{
53+
List<Type> result = new List<Type>();
54+
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
55+
{
56+
try
57+
{
58+
foreach (Type type in assembly.GetTypes())
59+
{
60+
var objectType = type.GetCustomAttributes(attribute, true);
61+
foreach (var attr in type.GetCustomAttributes(typeof(CSJsonConverterAttribute)))
62+
{
63+
CSJsonConverterAttribute ctdAttr = attr as CSJsonConverterAttribute;
64+
Trace.Assert(ctdAttr != null, "cast is null");
65+
if (ctdAttr.isAutoloadEnable)
66+
{
67+
result.Add(type);
68+
}
69+
}
70+
}
71+
}
72+
catch (Exception ex)
73+
{
74+
75+
}
76+
}
77+
_types[attribute] = result;
78+
}
79+
return _types[attribute].ToArray();
80+
}
81+
}
82+
}

Contentstack.Core/Configuration/ContentstackOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ public class ContentstackOptions
1919
/// <summary>
2020
/// The access token used when communicating with the Contentstack API.
2121
/// </summary>
22+
[Obsolete("We have deprecated AccessToken and we will stop supporting it in the near future. " +
23+
"We strongly recommend using DeliveryToken.")]
2224
public string AccessToken { get; set; }
2325

26+
/// <summary>
27+
/// The delivery token used when communicating with the Contentstack API.
28+
/// </summary>
29+
public string DeliveryToken { get; set; }
30+
2431
/// <summary>
2532
/// The environment used when communicating with the Contentstack API.
2633
/// </summary>

Contentstack.Core/Contentstack.Core.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
<PackageId>contentstack.csharp</PackageId>
66
<Authors>Contentstack</Authors>
77
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
8-
<PackageVersion>2.3.0</PackageVersion>
8+
<PackageVersion>2.4.0</PackageVersion>
99
<Owners>Contentstack</Owners>
10-
<PackageReleaseNotes>Get Global fields added.</PackageReleaseNotes>
10+
<PackageReleaseNotes>Entry model, JsonConverter added
11+
Bug fixes Environment, Entry content types resolved</PackageReleaseNotes>
1112
<Copyright>Copyright © 2012-2020 Contentstack. All Rights Reserved</Copyright>
1213
<PackOnBuild>true</PackOnBuild>
13-
<PackageTags>v2.3.0</PackageTags>
14+
<PackageTags>v2.4.0</PackageTags>
1415
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
1516
<PackageLicenseUrl>https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE</PackageLicenseUrl>
16-
<ReleaseVersion>2.3.0</ReleaseVersion>
17+
<ReleaseVersion>2.4.0</ReleaseVersion>
1718
</PropertyGroup>
1819

1920
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -37,6 +38,7 @@
3738
<ItemGroup>
3839
<Folder Include="Internals\" />
3940
<Folder Include="Models\" />
41+
<Folder Include="Attributes\" />
4042
</ItemGroup>
4143
<ItemGroup>
4244
<None Remove=".DS_Store" />

0 commit comments

Comments
 (0)