Skip to content

Commit

Permalink
Merge pull request #4 from contentstack/develop
Browse files Browse the repository at this point in the history
Region support
  • Loading branch information
uttamukkoji authored Sep 3, 2019
2 parents 8d9c913 + 28517c9 commit 6812105
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 34 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### Version: 2.1.1
#### Date: Sept-03-2019

##### New Features:
- Config
- added property attribute 'region'
- Query
- added method 'ReferenceIn'
- added method 'ReferenceNotIn'

### Version: 2.1.0
#### Date: Jul-29-2019

Expand All @@ -7,7 +17,7 @@
- Entry
- added method 'includeReferenceContentTypeUid'

### Version: 2.0
### Version:
#### Date: Jun-28-2019

##### New Features:
Expand Down
4 changes: 2 additions & 2 deletions Contentstack.AspNetCore/Contentstack.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<PackageId>contentstack.aspnetcore</PackageId>
<Authors>Contentstack</Authors>
<Owners>Contentstack</Owners>
<ReleaseVersion>2.1.0</ReleaseVersion>
<PackageVersion>1.0.0</PackageVersion>
<Description>Main release</Description>
<Copyright>Copyright (c) 2012-2019 Contentstack (http://app.contentstack.com). All Rights Reserved
</Copyright>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageTags>v1.0.0</PackageTags>
<ReleaseVersion>2.0</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
<PackageReference Include="contentstack.csharp" Version="1.1.0" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.0" />
<PackageReference Include="contentstack.csharp" Version="1.1.0" />
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions Contentstack.Core.Tests/AssetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace Contentstack.Core.Tests
{
public class AssetTest
{
string uid = "blt14d101ddeddaeefb";
//string uid = "blt649cfadb08b577db";
ContentstackClient client = StackConfig.GetStack();

[Fact]
public async Task FetchAssetByUid()
{
Asset asset = client.Asset("blt649cfadb08b577db");
Asset asset = client.Asset(uid);
await asset.Fetch().ContinueWith((t) =>
{
Asset result = t.Result;
Expand Down Expand Up @@ -56,7 +58,7 @@ public async Task FetchAssetsOrderByAscending()
{
if (dateTime != null)
{
if (dateTime.CompareTo(asset.GetCreateAt()) != -1)
if (dateTime.CompareTo(asset.GetCreateAt()) != -1 && dateTime.CompareTo(asset.GetCreateAt()) != 0)
{
Assert.False(true);
}
Expand Down
13 changes: 10 additions & 3 deletions Contentstack.Core.Tests/EntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ public class EntryTest
{
ContentstackClient client = StackConfig.GetStack();


////PROD STAG
//String source = "source";
//String singelEntryFetchUID = "blt1f94e478501bba46";
//string htmlSource = "blt2f0dd6a81f7f40e7";
//String referenceFieldUID = "reference";
//EU
String source = "source";
String singelEntryFetchUID = "blt1f94e478501bba46";
String singelEntryFetchUID = "bltf4268538a14fc5e1";
string htmlSource = "blt7c4197d43c1156ba";
String referenceFieldUID = "reference";


[Fact]
public async Task FetchByUid() {
ContentType contenttype = client.ContentType(source);
Expand Down Expand Up @@ -209,7 +216,7 @@ public async Task GetTags()
public async Task GetHTMLText()
{
ContentType contenttype = client.ContentType(source);
Entry sourceEntry = contenttype.Entry("blt2f0dd6a81f7f40e7");
Entry sourceEntry = contenttype.Entry(htmlSource);
var result = await sourceEntry.Fetch<SourceModel>();


Expand Down
6 changes: 4 additions & 2 deletions Contentstack.Core.Tests/Models/SourceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class SourceModel
public Boolean Boolean;
public string Date;
public Asset file;
public List<string> Reference;
public List<string> Other_reference;
//public List<string> Reference;
//public List<string> Other_reference;
public List<Dictionary<string, object>> Reference;
public List<Dictionary<string, object>> Other_reference;
public Dictionary<string, object> Group;
public List<Dictionary<string, object>> Modular_blocks;
public object[] Tags;
Expand Down
3 changes: 2 additions & 1 deletion Contentstack.Core.Tests/Models/SourceModelIncludeRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class SourceModelIncludeRef
public Boolean Boolean;
public string Date;
public List<Entry> Reference;
public List<string> Other_reference;
//public List<string> Other_reference;
public List<Dictionary<string, object>> Other_reference;
public Dictionary<string, object> Group;
public List<Dictionary<string, object>> Modular_blocks;

Expand Down
65 changes: 64 additions & 1 deletion Contentstack.Core.Tests/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public async Task And()
}
}

// //Not working

[Fact]
public async Task Or()
Expand Down Expand Up @@ -1316,7 +1315,71 @@ public async Task WhereTags()
}
}

[Fact]
public async Task ReferenceIn()
{
ContentType contentTypeObj = client.ContentType(source);
Query query = contentTypeObj.Query();
query.IncludeReference("reference");
Query referencequery = contentTypeObj.Query();
referencequery.Where("title", "ref-1 test3");

query.ReferenceIn("reference", referencequery);

var result = await query.Find<SourceModelIncludeRef>();
if (result == null && result.Items.Count() == 0)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else
{
bool IsTrue = false;
foreach (var data in result.Items)
{
foreach (var entry in data.Reference)
{
IsTrue = (entry.Title == "ref-1 test3");
if (!IsTrue)
break;
}

}
Assert.True(IsTrue);
}
}

[Fact]
public async Task ReferenceNotIn()
{
ContentType contentTypeObj = client.ContentType(source);
Query query = contentTypeObj.Query();
query.IncludeReference("reference");
Query referencequery = contentTypeObj.Query();
referencequery.Where("title", "ref-1 test3");

query.ReferenceNotIn("reference", referencequery);

var result = await query.Find<SourceModelIncludeRef>();
if (result == null && result.Items.Count() == 0)
{
Assert.False(true, "Query.Exec is not match with expected result.");
}
else
{
bool IsTrue = false;
foreach (var data in result.Items)
{
foreach (var entry in data.Reference)
{
IsTrue = (entry.Title != "ref-1 test3");
if (!IsTrue)
break;
}

}
Assert.True(IsTrue);
}
}
}
}

2 changes: 1 addition & 1 deletion Contentstack.Core.Tests/StackConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static ContentstackClient GetStack()
ApiKey = apiKey,
AccessToken = accessToken,
Environment = environment,
Host = host
Host = host,
};

ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));
Expand Down
13 changes: 9 additions & 4 deletions Contentstack.Core.Tests/SyncStackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ public class SyncStackTest
{
ContentstackClient client = StackConfig.GetSyncStack();


//EU
//String PaginationToken = "***REMOVED***";
//String SyncToken = "***REMOVED***";

//STAG
String PaginationToken = "***REMOVED***";
String SyncToken = "***REMOVED***";
//String PaginationToken = "***REMOVED***";
//String SyncToken = "***REMOVED***";


// //PROD
// String PaginationToken = "***REMOVED***";
// String SyncToken = "***REMOVED***";
String PaginationToken = "***REMOVED***";
String SyncToken = "***REMOVED***";
[Fact]
public async Task SyncInit()
{
Expand Down
43 changes: 31 additions & 12 deletions Contentstack.Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Contentstack.Core.Internals;

namespace Contentstack.Core.Configuration
{
internal class Config
Expand All @@ -12,7 +13,6 @@ internal class Config
private string _Protocol;
private string _Host;
private string _Port;
private string _BaseURL;
private string _Version;
private string _Environment;
#endregion
Expand All @@ -35,10 +35,12 @@ public string Protocol {
}

public string Host {
get { return this._Host ?? "cdn.contentstack.io"; }
get { return _Host ?? HostURL; }
set { this._Host = value; }
}

public ContentstackRegion Region { get; set; } = ContentstackRegion.US;

public string Version
{
get { return this._Version ?? "v3"; }
Expand All @@ -55,18 +57,35 @@ public string BaseUrl
{
get
{
string port = (this.Port == "80") ? string.Empty : ":" + this.Port;
this._BaseURL = string.Format("{0}://{1}{2}/{3}",
this.Protocol.Trim('/').Trim('\\'),
this.Host.Trim('/').Trim('\\'), port.Trim('/').Trim('\\'), this.Version.Trim('/').Trim('\\'));
return this._BaseURL;
}
set
{
this._BaseURL = value;
string BaseURL = string.Format("{0}://{1}{2}/{3}",
this.Protocol.Trim('/').Trim('\\'),
regionCode(),
this.Host.Trim('/').Trim('\\'),
this.Version.Trim('/').Trim('\\'));
return BaseURL;
}
}

#endregion

#region Internal

internal string regionCode()
{
if (Region == ContentstackRegion.US) return "";
ContentstackRegionCode[] regionCodes = Enum.GetValues(typeof(ContentstackRegionCode)).Cast<ContentstackRegionCode>().ToArray();
return string.Format("{0}-", regionCodes[(int)Region].ToString());
}

internal string HostURL
{
get
{
if (Region == ContentstackRegion.EU)
return "cdn.contentstack.com";
return "cdn.contentstack.io";
}
}
#endregion
}
}
45 changes: 44 additions & 1 deletion Contentstack.Core/Configuration/ContentstackOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using Contentstack.Core.Internals;

namespace Contentstack.Core.Configuration
{
/// <summary>
Expand Down Expand Up @@ -26,9 +31,47 @@ public class ContentstackOptions
/// </summary>
public string Host { get; set; }

/// <summary>
/// The Region used to set region for the ContentStack API.
/// </summary>
[TypeConverter(typeof(ContentstackRegionConverter))]
public ContentstackRegion Region { get; set; } = ContentstackRegion.US;

/// <summary>
/// The Version number for the ContentStack API.
/// </summary>
public string Version { get; set; }
}

internal class ContentstackRegionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string stringValue;
object result;

result = null;
stringValue = value as string;

if (!string.IsNullOrEmpty(stringValue))
{
int nonDigitIndex;

nonDigitIndex = stringValue.IndexOf(stringValue.FirstOrDefault(char.IsLetter));

if (nonDigitIndex > 0)
{
result = (ContentstackRegion)Enum.Parse(typeof(ContentstackRegion), stringValue.Substring(nonDigitIndex), true);
}
}

return result ?? base.ConvertFrom(context, culture, value);
}
}
}

6 changes: 3 additions & 3 deletions Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<PackageId>contentstack.csharp</PackageId>
<Authors>Contentstack</Authors>
<Description>.NET SDK for the Contentstack Content Delivery API.</Description>
<PackageVersion>2.0</PackageVersion>
<PackageVersion>2.1.1</PackageVersion>
<Owners>Contentstack</Owners>
<PackageReleaseNotes>Query Find method, Entry Fetch method returns ContentstackCollection of Model.</PackageReleaseNotes>
<ReleaseVersion>2.1.0</ReleaseVersion>
<Copyright>Copyright © 2012-2019 Contentstack. All Rights Reserved
</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageTags>v2.1.0</PackageTags>
<PackageTags>v2.1.1</PackageTags>
<PackageProjectUrl>https://github.com/contentstack/contentstack-dotnet</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/contentstack/contentstack-dotnet/blob/master/LICENSE</PackageLicenseUrl>
<ReleaseVersion>2.0</ReleaseVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
Loading

0 comments on commit 6812105

Please sign in to comment.