|
10 | 10 | using Contentstack.Management.Core.Tests.Helpers; |
11 | 11 | using Contentstack.Management.Core.Tests.Model; |
12 | 12 | using Contentstack.Management.Core.Exceptions; |
| 13 | +using Contentstack.Management.Core.Queryable; |
13 | 14 | using Microsoft.AspNetCore.Http.Internal; |
14 | 15 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
15 | 16 |
|
@@ -939,5 +940,216 @@ public void Test030_Should_Handle_Empty_Query_Results() |
939 | 940 | } |
940 | 941 | } |
941 | 942 |
|
| 943 | + [TestMethod] |
| 944 | + [DoNotParallelize] |
| 945 | + public void Test031_Should_Fetch_Asset_With_Locale_Parameter() |
| 946 | + { |
| 947 | + TestOutputLogger.LogContext("TestScenario", "FetchAssetWithLocaleParameter"); |
| 948 | + try |
| 949 | + { |
| 950 | + if (string.IsNullOrEmpty(_testAssetUid)) |
| 951 | + { |
| 952 | + Test005_Should_Create_Asset_Async(); |
| 953 | + } |
| 954 | + |
| 955 | + if (!string.IsNullOrEmpty(_testAssetUid)) |
| 956 | + { |
| 957 | + TestOutputLogger.LogContext("AssetUID", _testAssetUid); |
| 958 | + var coll = new ParameterCollection(); |
| 959 | + coll.Add("locale", "en-us"); |
| 960 | + ContentstackResponse response = _stack.Asset(_testAssetUid).Fetch(coll); |
| 961 | + |
| 962 | + if (response.IsSuccessStatusCode) |
| 963 | + { |
| 964 | + AssertLogger.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode, "FetchAssetWithLocale_StatusCode"); |
| 965 | + var responseObject = response.OpenJObjectResponse(); |
| 966 | + AssertLogger.IsNotNull(responseObject["asset"], "FetchAssetWithLocale_ResponseContainsAsset"); |
| 967 | + } |
| 968 | + else |
| 969 | + { |
| 970 | + AssertLogger.Fail("Fetch asset with locale parameter failed"); |
| 971 | + } |
| 972 | + } |
| 973 | + } |
| 974 | + catch (Exception e) |
| 975 | + { |
| 976 | + AssertLogger.Fail("Asset Fetch with locale parameter failed ", e.Message); |
| 977 | + } |
| 978 | + } |
| 979 | + |
| 980 | + [TestMethod] |
| 981 | + [DoNotParallelize] |
| 982 | + public void Test032_Should_Fetch_Asset_Async_With_Locale_Parameter() |
| 983 | + { |
| 984 | + TestOutputLogger.LogContext("TestScenario", "FetchAssetAsyncWithLocaleParameter"); |
| 985 | + try |
| 986 | + { |
| 987 | + if (string.IsNullOrEmpty(_testAssetUid)) |
| 988 | + { |
| 989 | + Test005_Should_Create_Asset_Async(); |
| 990 | + } |
| 991 | + |
| 992 | + if (!string.IsNullOrEmpty(_testAssetUid)) |
| 993 | + { |
| 994 | + TestOutputLogger.LogContext("AssetUID", _testAssetUid); |
| 995 | + var coll = new ParameterCollection(); |
| 996 | + coll.Add("locale", "en-us"); |
| 997 | + ContentstackResponse response = _stack.Asset(_testAssetUid).FetchAsync(coll).Result; |
| 998 | + |
| 999 | + if (response.IsSuccessStatusCode) |
| 1000 | + { |
| 1001 | + AssertLogger.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode, "FetchAssetAsyncWithLocale_StatusCode"); |
| 1002 | + var responseObject = response.OpenJObjectResponse(); |
| 1003 | + AssertLogger.IsNotNull(responseObject["asset"], "FetchAssetAsyncWithLocale_ResponseContainsAsset"); |
| 1004 | + } |
| 1005 | + else |
| 1006 | + { |
| 1007 | + AssertLogger.Fail("Fetch asset async with locale parameter failed"); |
| 1008 | + } |
| 1009 | + } |
| 1010 | + } |
| 1011 | + catch (Exception e) |
| 1012 | + { |
| 1013 | + AssertLogger.Fail("Asset Fetch async with locale parameter failed ", e.Message); |
| 1014 | + } |
| 1015 | + } |
| 1016 | + |
| 1017 | + [TestMethod] |
| 1018 | + [DoNotParallelize] |
| 1019 | + public void Test033_Should_Query_Assets_With_Locale_Parameter() |
| 1020 | + { |
| 1021 | + TestOutputLogger.LogContext("TestScenario", "QueryAssetsWithLocaleParameter"); |
| 1022 | + try |
| 1023 | + { |
| 1024 | + TestOutputLogger.LogContext("StackAPIKey", _stack?.APIKey ?? "null"); |
| 1025 | + var coll = new ParameterCollection(); |
| 1026 | + coll.Add("locale", "en-us"); |
| 1027 | + var query = _stack.Asset().Query(); |
| 1028 | + query.Limit(5); |
| 1029 | + query.Skip(0); |
| 1030 | + |
| 1031 | + ContentstackResponse response = query.Find(coll); |
| 1032 | + |
| 1033 | + if (response.IsSuccessStatusCode) |
| 1034 | + { |
| 1035 | + AssertLogger.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode, "QueryAssetsWithLocale_StatusCode"); |
| 1036 | + var responseObject = response.OpenJObjectResponse(); |
| 1037 | + AssertLogger.IsNotNull(responseObject["assets"], "QueryAssetsWithLocale_ResponseContainsAssets"); |
| 1038 | + } |
| 1039 | + else |
| 1040 | + { |
| 1041 | + AssertLogger.Fail("Querying assets with locale parameter failed"); |
| 1042 | + } |
| 1043 | + } |
| 1044 | + catch (Exception e) |
| 1045 | + { |
| 1046 | + AssertLogger.Fail("Querying assets with locale parameter failed ", e.Message); |
| 1047 | + } |
| 1048 | + } |
| 1049 | + |
| 1050 | + [TestMethod] |
| 1051 | + [DoNotParallelize] |
| 1052 | + public void Test034_Should_Handle_Fetch_With_Invalid_Locale_Parameter() |
| 1053 | + { |
| 1054 | + TestOutputLogger.LogContext("TestScenario", "FetchAssetWithInvalidLocaleParameter"); |
| 1055 | + try |
| 1056 | + { |
| 1057 | + if (string.IsNullOrEmpty(_testAssetUid)) |
| 1058 | + { |
| 1059 | + Test005_Should_Create_Asset_Async(); |
| 1060 | + } |
| 1061 | + |
| 1062 | + if (string.IsNullOrEmpty(_testAssetUid)) |
| 1063 | + { |
| 1064 | + AssertLogger.Fail("No asset UID for invalid locale fetch test"); |
| 1065 | + return; |
| 1066 | + } |
| 1067 | + |
| 1068 | + TestOutputLogger.LogContext("AssetUID", _testAssetUid); |
| 1069 | + var coll = new ParameterCollection(); |
| 1070 | + coll.Add("locale", "invalid_locale_code_xyz"); |
| 1071 | + |
| 1072 | + try |
| 1073 | + { |
| 1074 | + ContentstackResponse response = _stack.Asset(_testAssetUid).Fetch(coll); |
| 1075 | + if (response.IsSuccessStatusCode) |
| 1076 | + { |
| 1077 | + var responseObject = response.OpenJObjectResponse(); |
| 1078 | + AssertLogger.IsNotNull(responseObject["asset"], "FetchInvalidLocale_ResponseContainsAssetWhenApiIgnoresParam"); |
| 1079 | + } |
| 1080 | + } |
| 1081 | + catch (ContentstackErrorException ex) |
| 1082 | + { |
| 1083 | + AssertLogger.IsTrue( |
| 1084 | + ex.Message.Contains("locale", StringComparison.OrdinalIgnoreCase) |
| 1085 | + || ex.Message.Contains("invalid", StringComparison.OrdinalIgnoreCase) |
| 1086 | + || ex.Message.Contains("not found", StringComparison.OrdinalIgnoreCase) |
| 1087 | + || ex.Message.Contains("error", StringComparison.OrdinalIgnoreCase), |
| 1088 | + $"Expected error indication in exception, got: {ex.Message}", |
| 1089 | + "FetchInvalidLocale_ExceptionMessage"); |
| 1090 | + } |
| 1091 | + } |
| 1092 | + catch (Exception e) |
| 1093 | + { |
| 1094 | + AssertLogger.Fail("Fetch with invalid locale parameter failed unexpectedly ", e.Message); |
| 1095 | + } |
| 1096 | + } |
| 1097 | + |
| 1098 | + [TestMethod] |
| 1099 | + [DoNotParallelize] |
| 1100 | + public void Test035_Should_Handle_Fetch_Invalid_Asset_With_Locale_Parameter() |
| 1101 | + { |
| 1102 | + TestOutputLogger.LogContext("TestScenario", "FetchInvalidAssetWithLocaleParameter"); |
| 1103 | + string invalidAssetUid = "invalid_asset_uid_12345"; |
| 1104 | + TestOutputLogger.LogContext("InvalidAssetUID", invalidAssetUid); |
| 1105 | + var coll = new ParameterCollection(); |
| 1106 | + coll.Add("locale", "en-us"); |
| 1107 | + |
| 1108 | + try |
| 1109 | + { |
| 1110 | + _stack.Asset(invalidAssetUid).Fetch(coll); |
| 1111 | + AssertLogger.Fail("Expected exception for invalid asset fetch with locale, but operation succeeded"); |
| 1112 | + } |
| 1113 | + catch (ContentstackErrorException ex) |
| 1114 | + { |
| 1115 | + AssertLogger.IsTrue(ex.Message.Contains("not found") || ex.Message.Contains("invalid"), |
| 1116 | + $"Expected 'not found' or 'invalid' in exception message, got: {ex.Message}", |
| 1117 | + "InvalidAssetFetchWithLocale_ExceptionMessage"); |
| 1118 | + } |
| 1119 | + } |
| 1120 | + |
| 1121 | + [TestMethod] |
| 1122 | + [DoNotParallelize] |
| 1123 | + public void Test036_Should_Handle_Query_With_Invalid_Locale_Parameter() |
| 1124 | + { |
| 1125 | + TestOutputLogger.LogContext("TestScenario", "QueryAssetsWithInvalidLocaleParameter"); |
| 1126 | + TestOutputLogger.LogContext("StackAPIKey", _stack?.APIKey ?? "null"); |
| 1127 | + var coll = new ParameterCollection(); |
| 1128 | + coll.Add("locale", "invalid_locale_code_xyz"); |
| 1129 | + var query = _stack.Asset().Query(); |
| 1130 | + query.Limit(1); |
| 1131 | + query.Skip(0); |
| 1132 | + |
| 1133 | + try |
| 1134 | + { |
| 1135 | + ContentstackResponse response = query.Find(coll); |
| 1136 | + if (response.IsSuccessStatusCode) |
| 1137 | + { |
| 1138 | + AssertLogger.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode, "QueryInvalidLocale_StatusCode"); |
| 1139 | + var responseObject = response.OpenJObjectResponse(); |
| 1140 | + AssertLogger.IsNotNull(responseObject["assets"], "QueryInvalidLocale_ResponseContainsAssetsWhenApiIgnoresParam"); |
| 1141 | + } |
| 1142 | + } |
| 1143 | + catch (ContentstackErrorException ex) |
| 1144 | + { |
| 1145 | + AssertLogger.IsTrue( |
| 1146 | + ex.Message.Contains("locale", StringComparison.OrdinalIgnoreCase) |
| 1147 | + || ex.Message.Contains("invalid", StringComparison.OrdinalIgnoreCase) |
| 1148 | + || ex.Message.Contains("error", StringComparison.OrdinalIgnoreCase), |
| 1149 | + $"Expected error indication in exception, got: {ex.Message}", |
| 1150 | + "QueryInvalidLocale_ExceptionMessage"); |
| 1151 | + } |
| 1152 | + } |
| 1153 | + |
942 | 1154 | } |
943 | 1155 | } |
0 commit comments