Skip to content

Staging #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: Contentstack.Core/Internals/HttpRequestHandler.cs
checksum: 93c1659f3bc7527956f0fd12db46441297fac3a4366d273bcbb3425d2351300e
checksum: 94288e483056f41ff3a4c2ab652c3ce9ecb53dc0b9d4029456b34baed4f34891
- filename: Contentstack.Core/Models/Entry.cs
checksum: a6226f755dde69be62c21737ca75569ba6ea7cb4b7a125dc460c047dbe741b9e
checksum: 78a09b03b9fd6aefd0251353b2d8c70962bdfced16a6e1e28d10dc9af43da244
- filename: Contentstack.Core/ContentstackClient.cs
checksum: 761a5d65bfa12d16641aa66e5431b2eb52b0909eff904dca5c2f607ee439cba0
checksum: 687dc0a5f20037509731cfe540dcec9c3cc2b6cf50373cd183ece4f3249dc88e
- filename: Contentstack.Core/Models/AssetLibrary.cs
checksum: 92ff3feaf730b57c50bb8429f08dd4cddedb42cd89f2507e9746f8237b65fb11
- filename: Contentstack.Core/Models/Asset.cs
Expand All @@ -18,11 +18,5 @@ fileignoreconfig:
checksum: 751a725d94eff7d845bb22a5ce80a5529bb62971373de39288149fff3d024930
- filename: .github/workflows/nuget-publish.yml
checksum: 53ba4ce874c4d2362ad00deb23f5a6ec219318860352f997b945e9161a580651
- filename: Contentstack.Core/Models/ContentType.cs
checksum: 53e3b8330183445d100b32c545073f281b869ee238514c7ab8c9a4500a140166
- filename: Contentstack.Core.Tests/ContentTypeTest.cs
checksum: a2549638af21492d5a299dce35a2994ec4721b211af6956b955602d7065c47dc
- filename: Contentstack.Core/Models/GlobalFieldQuery.cs
checksum: 16fb3c5fb4de2b686f338b0666c7c86c3d37f2a276f85698a59a1ac1a02d359d
- filename: Contentstack.Core/Models/GlobalField.cs
checksum: 49cc6ec8b55408a3e71ba19551dbe01709ec70bc673fae21c280a1f74968e395
- filename: Contentstack.Core.Tests/ContentstackClientTest.cs
checksum: b63897181a8cb5993d1305248cfc3e711c4039b5677b6c1e4e2a639e4ecb391b
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version: 2.22.1
#### Date: June-13-2025

##### Fix:
- Fixed Timeline issue of Entry not getting updated

### Version: 2.22.0
#### Date: March-03-2025

Expand Down
242 changes: 242 additions & 0 deletions Contentstack.Core.Tests/ContentstackClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
// Contentstack.Core/ContentstackClientTest.cs
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
using Contentstack.Core.Configuration;

namespace Contentstack.Core.Tests
{
public class ContentstackClientTest
{
private ContentstackClient CreateClient()
{
var options = new ContentstackOptions()
{
ApiKey = "api_key",
DeliveryToken = "delivery_token",
Environment = "environment",
Version = "1.2.3",
LivePreview = new LivePreviewConfig()
{
Enable = true,
Host = "https://preview.contentstack.com",
ReleaseId = "rid",
PreviewTimestamp = "ts",
PreviewToken = "pt"

}
};
return new ContentstackClient(options);
}

private string GetPrivateField(ContentstackClient client, string fieldName)
{
var field = typeof(ContentstackClient).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
return (string)field.GetValue(client);
}

[Fact]
public void SetEntryUid_SetsValue_WhenNonEmpty()
{
var client = CreateClient();
client.SetEntryUid("entry123");
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
}

[Fact]
public void SetEntryUid_DoesNotSet_WhenEmpty()
{
var client = CreateClient();
client.SetEntryUid("entry123");
client.SetEntryUid("");
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
}

[Fact]
public void SetEntryUid_DoesNotSet_WhenNull()
{
var client = CreateClient();
client.SetEntryUid("entry123");
client.SetEntryUid(null);
Assert.Equal("entry123", GetPrivateField(client, "currentEntryUid"));
}

[Fact]
public void ContentType_SetscurrentContenttypeUid_WhenNonEmpty()
{
var client = CreateClient();
client.ContentType("blog");
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
}

[Fact]
public void ContentType_DoesNotSet_WhenEmpty()
{
var client = CreateClient();
client.ContentType("blog");
client.ContentType("");
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
}

[Fact]
public void ContentType_DoesNotSet_WhenNull()
{
var client = CreateClient();
client.ContentType("blog");
client.ContentType(null);
Assert.Equal("blog", GetPrivateField(client, "currentContenttypeUid"));
}

[Fact]
public void ContentType_ReturnsContentTypeInstance()
{
var client = CreateClient();
var contentType = client.ContentType("blog");
Assert.NotNull(contentType);
Assert.Equal("blog", contentType.ContentTypeId);
}

[Fact]
public void GlobalField_ReturnsGlobalFieldInstance()
{
var client = CreateClient();
var globalField = client.GlobalField("author");
Assert.NotNull(globalField);
Assert.Equal("author", globalField.GlobalFieldId);
}

[Fact]
public void Asset_ReturnsAssetInstance()
{
var client = CreateClient();
var asset = client.Asset("asset_uid");
Assert.NotNull(asset);
Assert.Equal("asset_uid", asset.Uid);
}

[Fact]
public void AssetLibrary_ReturnsAssetLibraryInstance()
{
var client = CreateClient();
var assetLibrary = client.AssetLibrary();
Assert.NotNull(assetLibrary);
}

[Fact]
public void Taxonomies_ReturnsTaxonomyInstance()
{
var client = CreateClient();
var taxonomy = client.Taxonomies();
Assert.NotNull(taxonomy);
}

[Fact]
public void GetVersion_ReturnsVersion()
{
var client = CreateClient();
var t = client.GetVersion();
Assert.Equal("1.2.3", client.GetVersion());
}

[Fact]
public void GetApplicationKey_ReturnsApiKey()
{
var client = CreateClient();
Assert.Equal("api_key", client.GetApplicationKey());
}

[Fact]
public void GetAccessToken_ReturnsDeliveryToken()
{
var client = CreateClient();
Assert.Equal("delivery_token", client.GetAccessToken());
}

[Fact]
public void GetLivePreviewConfig_ReturnsConfig()
{
var client = CreateClient();
Assert.NotNull(client.GetLivePreviewConfig());
}

[Fact]
public void RemoveHeader_RemovesHeader()
{
var client = CreateClient();
client.SetHeader("custom", "value");
client.RemoveHeader("custom");
var localHeaders = typeof(ContentstackClient)
.GetField("_LocalHeaders", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(client) as Dictionary<string, object>;
Assert.False(localHeaders.ContainsKey("custom"));
}

[Fact]
public void SetHeader_AddsHeader()
{
var client = CreateClient();
client.SetHeader("custom", "value");
var localHeaders = typeof(ContentstackClient)
.GetField("_LocalHeaders", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(client) as Dictionary<string, object>;
Assert.True(localHeaders.ContainsKey("custom"));
Assert.Equal("value", localHeaders["custom"]);
}

[Fact]
public async Task LivePreviewQueryAsync_SetsLivePreviewConfigFields()
{
var client = CreateClient();
client.ContentType("ctuid");
client.ContentType("ctuid").Entry("euid");
// Mock GetLivePreviewData to avoid actual HTTP call
var method = typeof(ContentstackClient).GetMethod("GetLivePreviewData", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(client, null); // Just to ensure method exists

var query = new Dictionary<string, string>
{
{ "live_preview", "hash" },
{ "release_id", "rid" },
{ "preview_timestamp", "ts" }
};

// Patch GetLivePreviewData to return a dummy JObject

// Since GetLivePreviewData is private and does a real HTTP call,
// we only test the config fields are set correctly before the call
await client.LivePreviewQueryAsync(query);
var v = client.GetLivePreviewConfig();
Assert.Equal("ctuid", GetPrivateField(client, "currentContenttypeUid"));
Assert.Equal("euid", GetPrivateField(client, "currentEntryUid"));
Assert.Equal(true, v.Enable );
Assert.Equal("rid", v.ReleaseId);
Assert.Equal("ts", v.PreviewTimestamp);
Assert.Equal("pt", v.PreviewToken);
}

// For SyncRecursive, SyncPaginationToken, SyncToken, you should mock HTTP calls.
// Here we just check that the methods exist and can be called (will throw if not configured).
[Fact]
public async Task SyncRecursive_ThrowsOrReturns()
{
var client = CreateClient();
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncRecursive());
}

[Fact]
public async Task SyncPaginationToken_ThrowsOrReturns()
{
var client = CreateClient();
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncPaginationToken("pagetoken"));
}

[Fact]
public async Task SyncToken_ThrowsOrReturns()
{
var client = CreateClient();
await Assert.ThrowsAnyAsync<Exception>(() => client.SyncToken("synctoken"));
}
}
}
2 changes: 1 addition & 1 deletion Contentstack.Core/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal string getBaseUrl (LivePreviewConfig livePreviewConfig, string contentT
{
if (livePreviewConfig != null
&& livePreviewConfig.Enable
&& livePreviewConfig.LivePreview != "init"
&& livePreviewConfig.LivePreview != "init" && !string.IsNullOrEmpty(livePreviewConfig.LivePreview)
&& livePreviewConfig.ContentTypeUID == contentTypeUID)
{
return getLivePreviewUrl(livePreviewConfig);
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/Contentstack.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Markdig" Version="0.36.2" />
<PackageReference Include="contentstack.utils" Version="1.0.5" />
<PackageReference Include="contentstack.utils" Version="1.0.6" />
</ItemGroup>
<ItemGroup>
<None Remove="Interfaces\" />
Expand Down
Loading
Loading