From 6d78a22c85a9a4036a1ce17b72268fbba9ed2501 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 23 Jul 2025 14:55:36 +0530 Subject: [PATCH 1/3] feat: Fetch Assets by tag value --- CHANGELOG.md | 7 + Contentstack.Core.Tests/AssetTagsBasicTest.cs | 91 ++++ Contentstack.Core.Tests/AssetTest.cs | 444 ++++++++++++++++++ .../Internals/HttpRequestHandler.cs | 2 +- Contentstack.Core/Models/AssetLibrary.cs | 29 ++ Directory.Build.props | 2 +- 6 files changed, 573 insertions(+), 2 deletions(-) create mode 100644 Contentstack.Core.Tests/AssetTagsBasicTest.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b0d61..d7438b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### Version: 2.23.0 +#### Date: Aug-05-2025 + +##### Feat: +- Fetch Assets using tags + + ### Version: 2.22.1 #### Date: June-13-2025 diff --git a/Contentstack.Core.Tests/AssetTagsBasicTest.cs b/Contentstack.Core.Tests/AssetTagsBasicTest.cs new file mode 100644 index 0000000..c1b2c20 --- /dev/null +++ b/Contentstack.Core.Tests/AssetTagsBasicTest.cs @@ -0,0 +1,91 @@ +using System; +using Xunit; +using Contentstack.Core.Models; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; + +namespace Contentstack.Core.Tests +{ + public class AssetTagsBasicTest + { + ContentstackClient client = StackConfig.GetStack(); + + [Fact] + public async Task AssetTags_BasicFunctionality_Test() + { + // Basic test to verify Tags method exists and works + AssetLibrary assetLibrary = client.AssetLibrary(); + + // This should not throw an exception + assetLibrary.Tags(new string[] { "test" }); + + // Verify the method returns AssetLibrary for chaining + Assert.NotNull(assetLibrary); + + // Test with multiple tags + assetLibrary.Tags(new string[] { "tag1", "tag2", "tag3" }); + Assert.NotNull(assetLibrary); + } + + [Fact] + public async Task AssetTags_ChainWithOtherMethods_Test() + { + // Test chaining Tags with other methods + AssetLibrary assetLibrary = client.AssetLibrary(); + + var chainedLibrary = assetLibrary + .Tags(new string[] { "test" }) + .Limit(1) + .Skip(0); + + Assert.NotNull(chainedLibrary); + } + + [Fact] + public async Task AssetTags_NullAndEmptyHandling_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + + // Should handle null gracefully + assetLibrary.Tags(null); + Assert.NotNull(assetLibrary); + + // Should handle empty array gracefully + assetLibrary.Tags(new string[] { }); + Assert.NotNull(assetLibrary); + } + + [Fact] + public void AssetTags_MethodExists_Test() + { + // Verify the Tags method exists with correct signature + AssetLibrary assetLibrary = client.AssetLibrary(); + + // This will compile only if the method exists with correct signature + var result = assetLibrary.Tags(new string[] { "test" }); + + // Should return AssetLibrary type for method chaining + Assert.IsType(result); + } + + [Fact] + public void AssetTags_MultipleCalls_ShouldNotThrowException_Test() + { + // Test multiple calls to Tags() method on same instance + AssetLibrary assetLibrary = client.AssetLibrary(); + + // First call + assetLibrary.Tags(new string[] { "tag1", "tag2" }); + + // Second call should not throw "An item with the same key has already been added" exception + assetLibrary.Tags(new string[] { "tag3", "tag4" }); + + // Third call with different tags + assetLibrary.Tags(new string[] { "newtag1", "newtag2", "newtag3" }); + + // Should return AssetLibrary type for method chaining + Assert.IsType(assetLibrary); + } + } +} \ No newline at end of file diff --git a/Contentstack.Core.Tests/AssetTest.cs b/Contentstack.Core.Tests/AssetTest.cs index c9e0eeb..9c45698 100644 --- a/Contentstack.Core.Tests/AssetTest.cs +++ b/Contentstack.Core.Tests/AssetTest.cs @@ -242,5 +242,449 @@ public async Task FetchAssetExcept() Assert.False(true, "Result doesn't mathced the count."); } } + [Fact] + public async Task AssetTags_FetchBySpecificTags_ShouldReturnValidAssets_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "assetdotnet" }); + ContentstackCollection assets = await assetLibrary.FetchAll(); + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + + if (assetCount > 0) + { + foreach (Asset asset in assets) + { + Assert.True(asset.FileName.Length > 0); + Assert.NotNull(asset.Uid); + Assert.NotNull(asset.Url); + Assert.True(asset.Tags != null || asset.Tags == null); // Either null or has value + } + } + } + + [Fact] + public async Task AssetTags_FetchWithExistingAssetTags_ShouldReturnMatchingAssets_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await assetLibrary.FetchAll(); + + int totalAssetsCount = allAssets.Count(); + Console.WriteLine($"Total assets in stack: {totalAssetsCount}"); + Assert.True(totalAssetsCount >= 0, "Total assets count should be non-negative"); + + if (totalAssetsCount > 0) + { + Asset assetWithTags = null; + foreach (Asset asset in allAssets) + { + if (asset.Tags != null && asset.Tags.Length > 0) + { + assetWithTags = asset; + break; + } + } + + if (assetWithTags != null && assetWithTags.Tags.Length > 0) + { + string firstTag = assetWithTags.Tags[0].ToString(); + AssetLibrary taggedAssetLibrary = client.AssetLibrary(); + taggedAssetLibrary.Tags(new string[] { firstTag }); + ContentstackCollection filteredAssets = await taggedAssetLibrary.FetchAll(); + + Assert.NotNull(filteredAssets); + + int filteredCount = filteredAssets.Count(); + + Assert.True(filteredCount >= 1, $"Should find at least 1 asset with existing tag '{firstTag}'"); + Assert.True(filteredCount <= totalAssetsCount, "Filtered count should not exceed total assets"); + + bool foundOriginalAsset = false; + foreach (Asset filteredAsset in filteredAssets) + { + if (filteredAsset.Uid == assetWithTags.Uid) + { + foundOriginalAsset = true; + break; + } + } + + Assert.True(foundOriginalAsset, $"Asset with UID {assetWithTags.Uid} should be found when filtering by tag '{firstTag}'"); + } + else + { + Console.WriteLine("No assets with tags found - skipping tag filtering test"); + } + } + } + + [Fact] + public async Task AssetTags_FetchBySingleTag_ShouldExecuteWithoutErrors_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset1" }); + ContentstackCollection assets = await assetLibrary.FetchAll(); + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + + if (assetCount > 0) + { + foreach (Asset asset in assets) + { + Assert.NotNull(asset.Uid); + Assert.True(asset.FileName.Length > 0); + } + } + } + + [Fact] + public async Task AssetTags_FetchByEmptyTagsArray_ShouldReturnAllAssets_Test() + { + AssetLibrary emptyTagsLibrary = client.AssetLibrary(); + emptyTagsLibrary.Tags(new string[] { }); + ContentstackCollection emptyTagsAssets = await emptyTagsLibrary.FetchAll(); + + Assert.NotNull(emptyTagsAssets); + + AssetLibrary allAssetsLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await allAssetsLibrary.FetchAll(); + + int emptyTagsCount = emptyTagsAssets.Count(); + int allAssetsCount = allAssets.Count(); + + + Assert.True(emptyTagsCount >= 0, "Empty tags asset count should be non-negative"); + Assert.True(emptyTagsCount == allAssetsCount || emptyTagsCount >= 0, + "Empty tags should return all assets or handle gracefully"); + } + + [Fact] + public async Task AssetTags_FetchByNullTags_ShouldReturnAllAssets_Test() + { + AssetLibrary nullTagsLibrary = client.AssetLibrary(); + nullTagsLibrary.Tags(null); + ContentstackCollection nullTagsAssets = await nullTagsLibrary.FetchAll(); + + Assert.NotNull(nullTagsAssets); + + AssetLibrary allAssetsLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await allAssetsLibrary.FetchAll(); + + int nullTagsCount = nullTagsAssets.Count(); + int allAssetsCount = allAssets.Count(); + + + Assert.True(nullTagsCount >= 0, "Null tags asset count should be non-negative"); + Assert.True(nullTagsCount == allAssetsCount || nullTagsCount >= 0, + "Null tags should return all assets or handle gracefully"); + } + + [Fact] + public async Task AssetTags_ChainWithOtherFilters_ShouldRespectAllFilters_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset2", "asset1" }) + .Limit(5) + .Skip(0) + .IncludeMetadata() + .IncludeFallback(); + + ContentstackCollection assets = await assetLibrary.FetchAll(); + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + + Assert.True(assetCount <= 5, "Limit of 5 should be respected"); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + + if (assetCount > 0) + { + foreach (Asset asset in assets) + { + Assert.NotNull(asset.Uid); + Assert.NotNull(asset.FileName); + Assert.True(asset.FileName.Length > 0); + } + } + } + + [Fact] + public async Task AssetTags_VerifyUrlQueriesParameter_ShouldContainTagsInQuery_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset1", "asset2" }); + + var urlQueriesField = typeof(AssetLibrary).GetField("UrlQueries", + System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + + if (urlQueriesField != null) + { + var urlQueries = (Dictionary)urlQueriesField.GetValue(assetLibrary); + Assert.True(urlQueries.ContainsKey("tags")); + + string[] tags = (string[])urlQueries["tags"]; + Assert.Equal(2, tags.Length); + Assert.Contains("asset1", tags); + Assert.Contains("asset2", tags); + + } + else + { + Console.WriteLine("Could not access UrlQueries field via reflection - test skipped"); + } + } + + [Fact] + public async Task AssetTags_FetchWithMultipleTags_ShouldReturnAssetsWithAnyTag_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset1", "asset2","assetdotnet" }); + ContentstackCollection assets = await assetLibrary.FetchAll(); + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + + if (assetCount > 0) + { + + foreach (Asset asset in assets) + { + Assert.NotNull(asset.Uid); + Assert.True(asset.FileName.Length > 0); + Assert.NotNull(asset.Url); + + if (asset.Tags != null && asset.Tags.Length > 0) + { + string[] searchTags = { "asset1", "asset2","assetdotnet" }; + bool hasMatchingTag = false; + + foreach (object assetTag in asset.Tags) + { + string tagString = assetTag.ToString().ToLower(); + foreach (string searchTag in searchTags) + { + if (tagString.Contains(searchTag.ToLower())) + { + hasMatchingTag = true; + break; + } + } + if (hasMatchingTag) break; + } + + if (!hasMatchingTag) + { + var assetTagsList = string.Join(", ", asset.Tags.Select(t => t.ToString())); + } + } + } + } + } + + [Fact] + public async Task AssetTags_CompareFilteredVsAllAssets_ShouldReturnFewerOrEqualAssets_Test() + { + + AssetLibrary allAssetsLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await allAssetsLibrary.FetchAll(); + + + AssetLibrary filteredAssetsLibrary = client.AssetLibrary(); + filteredAssetsLibrary.Tags(new string[] { "tag-does-not-exist" }); + ContentstackCollection filteredAssets = await filteredAssetsLibrary.FetchAll(); + + Assert.NotNull(allAssets); + Assert.NotNull(filteredAssets); + + // Get counts for comparison + int allAssetsCount = allAssets.Count(); + int filteredAssetsCount = filteredAssets.Count(); + + Assert.True(filteredAssetsCount <= allAssetsCount, + $"Filtered assets ({filteredAssetsCount}) should be <= all assets ({allAssetsCount})"); + + // Since we're using a tag that probably doesn't exist, count should be 0 + Assert.Equal(0, filteredAssetsCount); + + // All assets count should be greater than 0 (assuming there are assets in the stack) + Assert.True(allAssetsCount >= 0, "All assets count should be non-negative"); + + // Verify that filtering actually works by checking the difference + if (allAssetsCount > 0) + { + Assert.True(filteredAssetsCount < allAssetsCount, + "Filtered results should be less than total when using non-existent tag"); + } + } + + [Fact] + public async Task AssetTags_SortingAndPagination_ShouldRespectAllParameters_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset1" }) + .Limit(3) + .Skip(0) + .SortWithKeyAndOrderBy("created_at", Internals.OrderBy.OrderByDescending); + + ContentstackCollection assets = await assetLibrary.FetchAll(); + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + Assert.True(assetCount <= 3, "Should respect the limit of 3"); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + + if (assetCount > 1) + { + DateTime previousDate = DateTime.MaxValue; + foreach (Asset asset in assets) + { + DateTime currentDate = asset.GetCreateAt(); + Assert.True(currentDate <= previousDate, "Assets should be sorted by created_at in descending order"); + previousDate = currentDate; + } + } + } + + [Fact] + public async Task AssetTags_VerifyHttpRequestParameters_ShouldCompleteSuccessfully_Test() + { + + try + { + AssetLibrary assetLibrary = client.AssetLibrary(); + assetLibrary.Tags(new string[] { "asset1" }) + .Limit(1); + + ContentstackCollection assets = await assetLibrary.FetchAll(); + + + Assert.NotNull(assets); + + int assetCount = assets.Count(); + Assert.True(assetCount >= 0, "Asset count should be non-negative"); + Assert.True(assetCount <= 1, "Should respect limit of 1"); + + Assert.True(true, "HTTP request with tags parameter completed successfully"); + } + catch (Exception ex) + { + Assert.True(false, $"HTTP request failed, possibly due to malformed tags parameter: {ex.Message}"); + } + } + + [Fact] + public async Task AssetTags_EmptyAndNullHandling_ShouldNotBreakApiCalls_Test() + { + AssetLibrary emptyTagsLibrary = client.AssetLibrary(); + emptyTagsLibrary.Tags(new string[] { }); + ContentstackCollection emptyTagsAssets = await emptyTagsLibrary.FetchAll(); + Assert.NotNull(emptyTagsAssets); + + AssetLibrary nullTagsLibrary = client.AssetLibrary(); + nullTagsLibrary.Tags(null); + ContentstackCollection nullTagsAssets = await nullTagsLibrary.FetchAll(); + Assert.NotNull(nullTagsAssets); + + AssetLibrary allAssetsLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await allAssetsLibrary.FetchAll(); + + int emptyTagsCount = emptyTagsAssets.Count(); + int nullTagsCount = nullTagsAssets.Count(); + int allAssetsCount = allAssets.Count(); + + + Assert.True(emptyTagsCount == allAssetsCount || emptyTagsCount >= 0, + "Empty tags should return all assets or handle gracefully"); + Assert.True(nullTagsCount == allAssetsCount || nullTagsCount >= 0, + "Null tags should return all assets or handle gracefully"); + } + + [Fact] + public async Task AssetTags_CaseSensitivityVerification_ShouldTestCaseBehavior_Test() + { + AssetLibrary assetLibrary = client.AssetLibrary(); + ContentstackCollection allAssets = await assetLibrary.FetchAll(); + + int totalAssetsCount = allAssets.Count(); + Console.WriteLine($"Total assets available: {totalAssetsCount}"); + Assert.True(totalAssetsCount >= 0, "Total assets count should be non-negative"); + + Asset assetWithTags = null; + string originalTag = null; + + foreach (Asset asset in allAssets) + { + if (asset.Tags != null && asset.Tags.Length > 0) + { + assetWithTags = asset; + originalTag = asset.Tags[0].ToString(); + break; + } + } + + if (assetWithTags != null && !string.IsNullOrEmpty(originalTag)) + { + AssetLibrary originalCaseLibrary = client.AssetLibrary(); + originalCaseLibrary.Tags(new string[] { originalTag }); + ContentstackCollection originalCaseAssets = await originalCaseLibrary.FetchAll(); + + AssetLibrary upperCaseLibrary = client.AssetLibrary(); + upperCaseLibrary.Tags(new string[] { originalTag.ToUpper() }); + ContentstackCollection upperCaseAssets = await upperCaseLibrary.FetchAll(); + + AssetLibrary lowerCaseLibrary = client.AssetLibrary(); + lowerCaseLibrary.Tags(new string[] { originalTag.ToLower() }); + ContentstackCollection lowerCaseAssets = await lowerCaseLibrary.FetchAll(); + + Assert.NotNull(originalCaseAssets); + Assert.NotNull(upperCaseAssets); + Assert.NotNull(lowerCaseAssets); + + int originalCount = originalCaseAssets.Count(); + int upperCount = upperCaseAssets.Count(); + int lowerCount = lowerCaseAssets.Count(); + + + Assert.True(originalCount >= 1, $"Original case tag '{originalTag}' should return at least 1 asset"); + Assert.True(upperCount >= 0, "Uppercase tag search count should be non-negative"); + Assert.True(lowerCount >= 0, "Lowercase tag search count should be non-negative"); + Assert.True(originalCount <= totalAssetsCount, "Original count should not exceed total assets"); + Assert.True(upperCount <= totalAssetsCount, "Upper count should not exceed total assets"); + Assert.True(lowerCount <= totalAssetsCount, "Lower count should not exceed total assets"); + + bool foundOriginalAsset = originalCaseAssets.Any(a => a.Uid == assetWithTags.Uid); + Assert.True(foundOriginalAsset, $"Original asset {assetWithTags.Uid} should be found when searching with original tag '{originalTag}'"); + + if (originalTag.ToLower() != originalTag.ToUpper()) + { + bool appearsCaseInsensitive = (originalCount == upperCount && upperCount == lowerCount); + + if (appearsCaseInsensitive) + { + Assert.Equal(originalCount, upperCount); + Assert.Equal(originalCount, lowerCount); + Console.WriteLine("Verified: Tag search is case-insensitive"); + } + else + { + Console.WriteLine("Note: Tag search appears to be case-sensitive"); + } + } + } + else + { + Console.WriteLine("Skipping case sensitivity test - no assets with tags found"); + } + } } } \ No newline at end of file diff --git a/Contentstack.Core/Internals/HttpRequestHandler.cs b/Contentstack.Core/Internals/HttpRequestHandler.cs index 76416e8..9a1938a 100644 --- a/Contentstack.Core/Internals/HttpRequestHandler.cs +++ b/Contentstack.Core/Internals/HttpRequestHandler.cs @@ -48,7 +48,7 @@ public async Task ProcessRequest(string Url, Dictionary var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; - request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.22.1"; + request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.23.0"; request.Timeout = timeout; if (proxy != null) diff --git a/Contentstack.Core/Models/AssetLibrary.cs b/Contentstack.Core/Models/AssetLibrary.cs index adb01dd..8ec17e8 100644 --- a/Contentstack.Core/Models/AssetLibrary.cs +++ b/Contentstack.Core/Models/AssetLibrary.cs @@ -316,6 +316,35 @@ public AssetLibrary Limit(int number) return this; } + /// + /// Filter assets that have specific tags. + /// + /// Array of tags to filter assets by. + /// Current instance of AssetLibrary, this will be useful for a chaining calls. + /// + /// + /// ContentstackClient stack = new ContentstackClinet("api_key", "delivery_token", "environment"); + /// AssetLibrary assetLibrary = stack.AssetLibrary(); + /// assetLibrary.Tags(new string[] {"image", "banner"}); + /// ContentstackCollection contentstackCollection = await assetLibrary.FetchAll(); + /// + /// + public AssetLibrary Tags(string[] tags) + { + try + { + if (tags != null && tags.Length > 0) + { + UrlQueries["tags"] = tags; + } + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return this; + } + /// /// Specifies an array of 'only' keys in BASE object that would be 'included' in the response. /// diff --git a/Directory.Build.props b/Directory.Build.props index bec8fed..4f68ca3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.22.1 + 2.23.0 From d3cc605315869219647e366fd96e95275d005516 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 23 Jul 2025 15:22:00 +0530 Subject: [PATCH 2/3] Removed comments --- Contentstack.Core.Tests/AssetTagsBasicTest.cs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Contentstack.Core.Tests/AssetTagsBasicTest.cs b/Contentstack.Core.Tests/AssetTagsBasicTest.cs index c1b2c20..f82ef00 100644 --- a/Contentstack.Core.Tests/AssetTagsBasicTest.cs +++ b/Contentstack.Core.Tests/AssetTagsBasicTest.cs @@ -14,16 +14,12 @@ public class AssetTagsBasicTest [Fact] public async Task AssetTags_BasicFunctionality_Test() { - // Basic test to verify Tags method exists and works AssetLibrary assetLibrary = client.AssetLibrary(); - // This should not throw an exception assetLibrary.Tags(new string[] { "test" }); - // Verify the method returns AssetLibrary for chaining Assert.NotNull(assetLibrary); - // Test with multiple tags assetLibrary.Tags(new string[] { "tag1", "tag2", "tag3" }); Assert.NotNull(assetLibrary); } @@ -31,7 +27,6 @@ public async Task AssetTags_BasicFunctionality_Test() [Fact] public async Task AssetTags_ChainWithOtherMethods_Test() { - // Test chaining Tags with other methods AssetLibrary assetLibrary = client.AssetLibrary(); var chainedLibrary = assetLibrary @@ -47,11 +42,9 @@ public async Task AssetTags_NullAndEmptyHandling_Test() { AssetLibrary assetLibrary = client.AssetLibrary(); - // Should handle null gracefully assetLibrary.Tags(null); Assert.NotNull(assetLibrary); - // Should handle empty array gracefully assetLibrary.Tags(new string[] { }); Assert.NotNull(assetLibrary); } @@ -59,32 +52,22 @@ public async Task AssetTags_NullAndEmptyHandling_Test() [Fact] public void AssetTags_MethodExists_Test() { - // Verify the Tags method exists with correct signature AssetLibrary assetLibrary = client.AssetLibrary(); - // This will compile only if the method exists with correct signature var result = assetLibrary.Tags(new string[] { "test" }); - // Should return AssetLibrary type for method chaining Assert.IsType(result); } [Fact] public void AssetTags_MultipleCalls_ShouldNotThrowException_Test() { - // Test multiple calls to Tags() method on same instance AssetLibrary assetLibrary = client.AssetLibrary(); - // First call assetLibrary.Tags(new string[] { "tag1", "tag2" }); - - // Second call should not throw "An item with the same key has already been added" exception assetLibrary.Tags(new string[] { "tag3", "tag4" }); - - // Third call with different tags assetLibrary.Tags(new string[] { "newtag1", "newtag2", "newtag3" }); - // Should return AssetLibrary type for method chaining Assert.IsType(assetLibrary); } } From 5216619b808fe5f1719bfe4eb00493a9b068d3fe Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 23 Jul 2025 15:26:16 +0530 Subject: [PATCH 3/3] Removed Console --- Contentstack.Core.Tests/AssetTest.cs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/Contentstack.Core.Tests/AssetTest.cs b/Contentstack.Core.Tests/AssetTest.cs index 9c45698..25f4fd7 100644 --- a/Contentstack.Core.Tests/AssetTest.cs +++ b/Contentstack.Core.Tests/AssetTest.cs @@ -167,7 +167,6 @@ public async Task FetchAssetCountAsync() else if (jObject != null) { Assert.Equal(5, jObject.GetValue("assets")); - //Assert.True(true, "BuiltObject.Fetch is pass successfully."); } else { @@ -273,7 +272,6 @@ public async Task AssetTags_FetchWithExistingAssetTags_ShouldReturnMatchingAsset ContentstackCollection allAssets = await assetLibrary.FetchAll(); int totalAssetsCount = allAssets.Count(); - Console.WriteLine($"Total assets in stack: {totalAssetsCount}"); Assert.True(totalAssetsCount >= 0, "Total assets count should be non-negative"); if (totalAssetsCount > 0) @@ -314,10 +312,6 @@ public async Task AssetTags_FetchWithExistingAssetTags_ShouldReturnMatchingAsset Assert.True(foundOriginalAsset, $"Asset with UID {assetWithTags.Uid} should be found when filtering by tag '{firstTag}'"); } - else - { - Console.WriteLine("No assets with tags found - skipping tag filtering test"); - } } } @@ -435,10 +429,6 @@ public async Task AssetTags_VerifyUrlQueriesParameter_ShouldContainTagsInQuery_T Assert.Contains("asset2", tags); } - else - { - Console.WriteLine("Could not access UrlQueries field via reflection - test skipped"); - } } [Fact] @@ -505,20 +495,15 @@ public async Task AssetTags_CompareFilteredVsAllAssets_ShouldReturnFewerOrEqualA Assert.NotNull(allAssets); Assert.NotNull(filteredAssets); - // Get counts for comparison int allAssetsCount = allAssets.Count(); int filteredAssetsCount = filteredAssets.Count(); Assert.True(filteredAssetsCount <= allAssetsCount, $"Filtered assets ({filteredAssetsCount}) should be <= all assets ({allAssetsCount})"); - // Since we're using a tag that probably doesn't exist, count should be 0 Assert.Equal(0, filteredAssetsCount); - // All assets count should be greater than 0 (assuming there are assets in the stack) Assert.True(allAssetsCount >= 0, "All assets count should be non-negative"); - - // Verify that filtering actually works by checking the difference if (allAssetsCount > 0) { Assert.True(filteredAssetsCount < allAssetsCount, @@ -616,7 +601,6 @@ public async Task AssetTags_CaseSensitivityVerification_ShouldTestCaseBehavior_T ContentstackCollection allAssets = await assetLibrary.FetchAll(); int totalAssetsCount = allAssets.Count(); - Console.WriteLine($"Total assets available: {totalAssetsCount}"); Assert.True(totalAssetsCount >= 0, "Total assets count should be non-negative"); Asset assetWithTags = null; @@ -673,18 +657,9 @@ public async Task AssetTags_CaseSensitivityVerification_ShouldTestCaseBehavior_T { Assert.Equal(originalCount, upperCount); Assert.Equal(originalCount, lowerCount); - Console.WriteLine("Verified: Tag search is case-insensitive"); - } - else - { - Console.WriteLine("Note: Tag search appears to be case-sensitive"); } } } - else - { - Console.WriteLine("Skipping case sensitivity test - no assets with tags found"); - } } } } \ No newline at end of file