Skip to content

Commit

Permalink
Merge pull request #9 from contentstack/publish_fallback
Browse files Browse the repository at this point in the history
Publish fallback
  • Loading branch information
uttamukkoji authored Dec 5, 2020
2 parents 393372b + 7d1d46e commit a17209e
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ packages/
*.nupkg
*.nuspec
*.trx
*/TestResults/
*/TestResults/
*/app.config
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
### Version: 2.5.0
#### Date: Dec-05-2020

##### Update API:
- AssetLibrary
- IncludeFallback function added
- SetLocale function added
- Asset
- IncludeFallback function added
- SetLocale function added
- Entry
- IncludeFallback function added
- Query
- IncludeFallback function added

### Version: 2.4.0
#### Date: Aug-12-2020

Expand Down
9 changes: 6 additions & 3 deletions Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
<Authors>Contentstack</Authors>
<Owners>Contentstack</Owners>
<ReleaseVersion>2.1.1</ReleaseVersion>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>2.5.0</PackageVersion>
<Description>Main release</Description>
<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.4.0</ReleaseVersion>
<PackageTags>v2.5.0</PackageTags>
<ReleaseVersion>2.5.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType></DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="Contentstack.Core">
<HintPath>..\Contentstack.Core\bin\Debug\Contentstack.Core.dll</HintPath>
Expand Down
38 changes: 36 additions & 2 deletions Contentstack.Core.Tests/AssetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,40 @@ await asset.Fetch().ContinueWith((t) =>
});
}

[Fact]
public async Task FetchAssetsPublishFallback()
{
List<string> list = new List<string>();
list.Add("en-us");
list.Add("ja-jp");
ContentstackCollection<Asset> assets = await client.AssetLibrary()
.SetLocale("ja-jp")
.IncludeFallback()
.FetchAll();
;
Assert.True(assets.Items.Count() > 0);
foreach (Asset asset in assets)
{
Assert.Contains((string)(asset.Get("publish_details") as JObject).GetValue("locale"), list);
}
}

[Fact]
public async Task FetchAssetsPublishWithoutFallback()
{
List<string> list = new List<string>();
list.Add("ja-jp");
ContentstackCollection<Asset> assets = await client.AssetLibrary()
.SetLocale("ja-jp")
.FetchAll();
;
Assert.True(assets.Items.Count() > 0);
foreach (Asset asset in assets)
{
Assert.Contains((string)(asset.Get("publish_details") as JObject).GetValue("locale"), list);
}
}

[Fact]
public async Task FetchAssets()
{
Expand Down Expand Up @@ -94,7 +128,7 @@ public async Task FetchAssetsIncludeRelativeURL()
[Fact]
public async Task FetchAssetCountAsync()
{
AssetLibrary assetLibrary = client.AssetLibrary();
AssetLibrary assetLibrary = client.AssetLibrary().SetLocale("en-us");
JObject jObject = await assetLibrary.Count();
if (jObject == null)
{
Expand All @@ -114,7 +148,7 @@ public async Task FetchAssetCountAsync()
[Fact]
public async Task FetchAssetSkipLimit()
{
AssetLibrary assetLibrary = client.AssetLibrary().Skip(2).Limit(5);
AssetLibrary assetLibrary = client.AssetLibrary().SetLocale("en-us").Skip(2).Limit(5);
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();
if (assets == null)
{
Expand Down
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.4.0</ReleaseVersion>
<ReleaseVersion>2.5.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions Contentstack.Core.Tests/EntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
using System.Text.RegularExpressions;
using Contentstack.Core.Tests.Models;
using Newtonsoft.Json.Linq;

namespace Contentstack.Core.Tests
{

Expand Down Expand Up @@ -61,6 +63,36 @@ await sourceEntry.Fetch<Entry>().ContinueWith((t) =>
});
}

[Fact]
public async Task FetchEntryByUIDPublishFallback()
{
List<string> list = new List<string>();
list.Add("en-us");
list.Add("ja-jp");
ContentType contenttype = client.ContentType(source);
string uid = await GetUID("source1");
Entry sourceEntry = await contenttype.Entry(uid)
.SetLocale("ja-jp")
.IncludeFallback()
.Fetch<Entry>();

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

[Fact]
public async Task FetchEntryByUIDPublishWithoutFallback()
{
List<string> list = new List<string>();
list.Add("ja-jp");
ContentType contenttype = client.ContentType(source);
string uid = await GetUID("source1");
Entry sourceEntry = await contenttype.Entry(uid)
.SetLocale("ja-jp")
.Fetch<Entry>();

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

[Fact]
public async Task IncludeReference() {
ContentType contenttype = client.ContentType(source);
Expand Down
34 changes: 34 additions & 0 deletions Contentstack.Core.Tests/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,40 @@ public async Task FetchAllGetContentType()
}
}

[Fact]
public async Task FetchEntriesPublishFallback()
{
List<string> list = new List<string>();
list.Add("en-us");
list.Add("ja-jp");
ContentstackCollection<Entry> entries = await client.ContentType(source).Query()
.SetLocale("ja-jp")
.IncludeFallback()
.Find<Entry>();
;
Assert.True(entries.Items.Count() > 0);
foreach (Entry entry in entries)
{
Assert.Contains((string)(entry.Get("publish_details") as JObject).GetValue("locale"), list);
}
}

[Fact]
public async Task FetchEntriesPublishWithoutFallback()
{
List<string> list = new List<string>();
list.Add("ja-jp");
ContentstackCollection<Entry> entries = await client.ContentType(source).Query()
.SetLocale("ja-jp")
.Find<Entry>();
;
Assert.True(entries.Items.Count() > 0);
foreach (Entry entry in entries)
{
Assert.Contains((string)(entry.Get("publish_details") as JObject).GetValue("locale"), list);
}
}

[Fact]
public async Task FetchAllCount()
{
Expand Down
28 changes: 6 additions & 22 deletions Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net47;net472;</TargetFrameworks>
<PackageId>contentstack.csharp</PackageId>
<Authors>Contentstack</Authors>
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
<PackageVersion>2.4.0</PackageVersion>
<PackageVersion>2.5.0</PackageVersion>
<Owners>Contentstack</Owners>
<PackageReleaseNotes>Entry model, JsonConverter added
Bug fixes Environment, Entry content types resolved</PackageReleaseNotes>
<PackageReleaseNotes>Publish content fallback </PackageReleaseNotes>
<Copyright>Copyright © 2012-2020 Contentstack. All Rights Reserved</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v2.4.0</PackageTags>
<PackageTags>v2.5.0</PackageTags>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE</PackageLicenseUrl>
<ReleaseVersion>2.4.0</ReleaseVersion>
<ReleaseVersion>2.5.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -28,29 +27,14 @@ Bug fixes Environment, Entry content types resolved</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Markdig" Version="0.20.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.5" />
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2"><PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Markdig" Version="0.22.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Internals\" />
<Folder Include="Models\" />
<Folder Include="Attributes\" />
</ItemGroup>
<ItemGroup>
<None Remove=".DS_Store" />
<None Remove="Contentstack.Core.nuspec" />
<None Remove="contentstack.csharp.1.0.0-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.1-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.2-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.3-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.4-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.5-alpha.nupkg" />
<None Remove="contentstack.csharp.1.0.6.nupkg" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Contentstack.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Net;
using System.IO;
using System.Collections;
using System.Reflection;

namespace Contentstack.Core
{
Expand Down
41 changes: 41 additions & 0 deletions Contentstack.Core/Models/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ public void SetHeader(string key, string value)
}

}

/// <summary>
/// Include fallback locale publish content, if specified locale content is not publish.
/// </summary>
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
/// <example>
/// <code>
/// //&quot;blt5d4sample2633b&quot; is a dummy Stack API key
/// //&quot;blt6d0240b5sample254090d&quot; is dummy access token.
/// ContentstackClient stack = new ContentstackClinet(&quot;blt5d4sample2633b&quot;, &quot;blt6d0240b5sample254090d&quot;, &quot;stag&quot;);
/// Asset asset = stack.Asset(&quot;asset_uid&quot;);
/// asset.IncludeFallback();
/// asset.Fetch&lt;Product&gt;().ContinueWith((assetResult) =&gt; {
/// //Your callback code.
/// });
/// </code>
/// </example>
public Asset includeFallback()
{
this.UrlQueries.Add("include_fallback", true);
return this;
}

public void RemoveHeader(string key)
{
Expand Down Expand Up @@ -176,6 +198,25 @@ public DateTime GetCreateAt()
return DateTime.MinValue;
}

public Object Get(String key)
{
try
{
if (_ObjectAttributes.ContainsKey(key))
{
var value = _ObjectAttributes[key];
return value;
}
else
return null;
}
catch
{
//CSAppUtils.showLog(TAG, "-----------------getUpdateAtDate|" + e);
}
return null;
}

public String GetCreatedBy()
{

Expand Down
Loading

0 comments on commit a17209e

Please sign in to comment.