Skip to content

Commit

Permalink
Merge pull request #8 from contentstack/2.4.0
Browse files Browse the repository at this point in the history
Autoload converter support 
Delivery Token Support added
JsonConverter autoload implemented
  • Loading branch information
uttamukkoji authored Aug 12, 2020
2 parents 809ba87 + 668dee8 commit 5103b58
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 17 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
### Version: 2.4.0
#### Date: Aug-12-2020

##### Update API:
- AssetLibrary
- Count function added
- Limit, Skip functionality added
- Only, Except function added
- Query
- Count function added
- CSJsonConverter
- Added class CSJsonConverter to allow autoloading of converters
##### Enhancement
- Stack
- Sync function to allow multiple SyncType
##### Bug Fixes
- Entry
- GetContentType exception resolved
##### Deprecation
- Stack
- AccessToken deprecated with support to add DeliveryToken

### Version: 2.3.0
#### Date: Jun-22-2020

##### Update API:
- GetEnvironment issue resolved
- GetDeleted at Method added
- GetDeleted at Method addedAssetLibrary
- SyncType issue resolved

### Version: 2.2.1
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Copyright>Copyright (c) 2012-2020 Contentstack (http://app.contentstack.com). All Rights Reserved</Copyright>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageTags>v1.0.0</PackageTags>
<ReleaseVersion>2.3.0</ReleaseVersion>
<ReleaseVersion>2.4.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
93 changes: 91 additions & 2 deletions Contentstack.Core.Tests/AssetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections;
using Newtonsoft.Json.Linq;

namespace Contentstack.Core.Tests
{
Expand Down Expand Up @@ -40,7 +41,7 @@ await asset.Fetch().ContinueWith((t) =>
Assert.True(result.FileName.Length > 0);
}
});
}
}

[Fact]
public async Task FetchAssets()
Expand Down Expand Up @@ -89,5 +90,93 @@ public async Task FetchAssetsIncludeRelativeURL()
Assert.True(asset.FileName.Length > 0);
}
}

[Fact]
public async Task FetchAssetCountAsync()
{
AssetLibrary assetLibrary = client.AssetLibrary();
JObject jObject = await assetLibrary.Count();
if (jObject == null)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else if (jObject != null)
{
Assert.Equal(5, jObject.GetValue("assets"));
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
}
else
{
Assert.False(true, "Result doesn't mathced the count.");
}
}

[Fact]
public async Task FetchAssetSkipLimit()
{
AssetLibrary assetLibrary = client.AssetLibrary().Skip(2).Limit(5);
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
if (assets == null)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else if (assets != null)
{
Assert.Equal(3, assets.Items.Count());
}
else
{
Assert.False(true, "Result doesn't mathced the count.");
}
}

[Fact]
public async Task FetchAssetOnly()
{
AssetLibrary assetLibrary = client.AssetLibrary().Only(new string[] { "url"});
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
if (assets == null)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else if (assets != null)
{
foreach (Asset asset in assets)
{
Assert.DoesNotContain(asset.Url, "http");
Assert.Null(asset.Description);
Assert.Null(asset.FileSize);
Assert.Null(asset.Tags);
Assert.Null(asset.Description);
}
}
else
{
Assert.False(true, "Result doesn't mathced the count.");
}
}

[Fact]
public async Task FetchAssetExcept()
{
AssetLibrary assetLibrary = client.AssetLibrary().Except(new string[] { "description" });
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
if (assets == null)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else if (assets != null)
{
foreach (Asset asset in assets)
{
Assert.DoesNotContain(asset.Url, "http");
Assert.Null(asset.Description);
}
}
else
{
Assert.False(true, "Result doesn't mathced the count.");
}
}
}
}
}
2 changes: 1 addition & 1 deletion Contentstack.Core.Tests/Contentstack.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
<ReleaseVersion>2.3.0</ReleaseVersion>
<ReleaseVersion>2.4.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions Contentstack.Core.Tests/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ public async Task FetchAllGetContentType()
}
}

[Fact]
public async Task FetchAllCount()
{
Query query = client.ContentType(source).Query();
query.SetLocale("en-us");
var result = await query.Count();
if (result == null)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else if (result != null)
{

Assert.Equal(7, result.GetValue("entries"));
//Assert.True(true, "BuiltObject.Fetch is pass successfully.");
}
else
{
Assert.False(true, "Result doesn't mathced the count.");

}
}

[Fact]
public async Task FetchAll()
{
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core.Tests/StackConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static ContentstackClient GetStack()
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
{
ApiKey = apiKey,
AccessToken = delivery_token,
DeliveryToken = delivery_token,
Environment = environment,
Host = host,
};
Expand Down
82 changes: 82 additions & 0 deletions Contentstack.Core/Attributes/CSJsonConverterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;

namespace Contentstack.Core
{
[AttributeUsage(AttributeTargets.Class)]
public class CSJsonConverterAttribute : Attribute
{
private readonly string name;
private readonly bool isAutoloadEnable;
private static ConcurrentDictionary<Type, List<Type>> _types = new ConcurrentDictionary<Type, List<Type>>();

/// <summary>
/// Name for the JsonConverter
/// </summary>
public string Name
{
get
{
return this.name;
}
}

/// <summary>
/// To enable autoload in ContentstackClient. Default is Enable.
/// </summary>
public bool IsAutoloadEnable
{
get
{
return this.isAutoloadEnable;
}
}

/// <summary>
/// CSJsonConverterAttribute constructor
/// </summary>
/// <param name="name">Name for the JsonConverter</param>
/// <param name="isAutoloadEnable"> To enable autoload in ContentstackClient. Default is Enable.</param>
public CSJsonConverterAttribute(string name, bool isAutoloadEnable = true)
{
this.name = name;
this.isAutoloadEnable = isAutoloadEnable;
}

internal static IEnumerable<Type> GetCustomAttribute(Type attribute)
{
if (!_types.ContainsKey(attribute))
{
List<Type> result = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
foreach (Type type in assembly.GetTypes())
{
var objectType = type.GetCustomAttributes(attribute, true);
foreach (var attr in type.GetCustomAttributes(typeof(CSJsonConverterAttribute)))
{
CSJsonConverterAttribute ctdAttr = attr as CSJsonConverterAttribute;
Trace.Assert(ctdAttr != null, "cast is null");
if (ctdAttr.isAutoloadEnable)
{
result.Add(type);
}
}
}
}
catch (Exception ex)
{

}
}
_types[attribute] = result;
}
return _types[attribute].ToArray();
}
}
}
7 changes: 7 additions & 0 deletions Contentstack.Core/Configuration/ContentstackOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ public class ContentstackOptions
/// <summary>
/// The access token used when communicating with the Contentstack API.
/// </summary>
[Obsolete("We have deprecated AccessToken and we will stop supporting it in the near future. " +
"We strongly recommend using DeliveryToken.")]
public string AccessToken { get; set; }

/// <summary>
/// The delivery token used when communicating with the Contentstack API.
/// </summary>
public string DeliveryToken { get; set; }

/// <summary>
/// The environment used when communicating with the Contentstack API.
/// </summary>
Expand Down
10 changes: 6 additions & 4 deletions Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<PackageId>contentstack.csharp</PackageId>
<Authors>Contentstack</Authors>
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
<PackageVersion>2.3.0</PackageVersion>
<PackageVersion>2.4.0</PackageVersion>
<Owners>Contentstack</Owners>
<PackageReleaseNotes>Get Global fields added.</PackageReleaseNotes>
<PackageReleaseNotes>Entry model, JsonConverter added
Bug fixes Environment, Entry content types resolved</PackageReleaseNotes>
<Copyright>Copyright © 2012-2020 Contentstack. All Rights Reserved</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v2.3.0</PackageTags>
<PackageTags>v2.4.0</PackageTags>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE</PackageLicenseUrl>
<ReleaseVersion>2.3.0</ReleaseVersion>
<ReleaseVersion>2.4.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -37,6 +38,7 @@
<ItemGroup>
<Folder Include="Internals\" />
<Folder Include="Models\" />
<Folder Include="Attributes\" />
</ItemGroup>
<ItemGroup>
<None Remove=".DS_Store" />
Expand Down
2 changes: 2 additions & 0 deletions Contentstack.Core/Internals/AssetJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using Contentstack.Core;
using Contentstack.Core.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Contentstack.Core.Internals
{
[CSJsonConverter("AssetJsonConverter")]
public class AssetJsonConverter : JsonConverter<Asset>
{
public override Asset ReadJson(JsonReader reader, Type objectType, Asset existingValue, bool hasExistingValue, JsonSerializer serializer)
Expand Down
8 changes: 4 additions & 4 deletions Contentstack.Core/Internals/ContentStackError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Contentstack.Core.Internals
/// <summary>
/// The ContentstackError class is abstraction of general exception class.
/// </summary>
public class ContentstackError : Exception
public class ContentstackException : Exception
{
#region Private Variables
private string _ErrorMessage = string.Empty;
Expand Down Expand Up @@ -65,15 +65,15 @@ public string ErrorMessage
/// <summary>
/// The ContentstackError class is abstraction of general exception class.
/// </summary>
public ContentstackError()
public ContentstackException()
{
}

/// <summary>
/// The ContentstackError class is abstraction of general exception class.
/// </summary>
/// <param name="errorMessage"> Error Message</param>
public ContentstackError(string errorMessage)
public ContentstackException(string errorMessage)
: base(errorMessage)
{
this.ErrorMessage = errorMessage;
Expand All @@ -83,7 +83,7 @@ public ContentstackError(string errorMessage)
/// The ContentstackError class is abstraction of general exception class.
/// </summary>
/// <param name="exception"> Exception</param>
public ContentstackError(Exception exception)
public ContentstackException(Exception exception)
: base(exception.Message, exception.InnerException)
{
this.ErrorMessage = exception.Message;
Expand Down
1 change: 1 addition & 0 deletions Contentstack.Core/Internals/EntryJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Contentstack.Core.Internals
{
[CSJsonConverter("EntryJsonConverter")]
public class EntryJsonConverter : JsonConverter<Entry>
{
public override Entry ReadJson(JsonReader reader, Type objectType, Entry existingValue, bool hasExistingValue, JsonSerializer serializer)
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ Global
$0.XmlFormattingPolicy = $9
$9.scope = application/xml
$0.StandardHeader = $10
version = 2.3.0
version = 2.4.0
EndGlobalSection
EndGlobal
Loading

0 comments on commit 5103b58

Please sign in to comment.