|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using Newtonsoft.Json.Linq; |
| 4 | +using NUnit.Framework; |
| 5 | + |
| 6 | +namespace CloudinaryDotNet.Tests |
| 7 | +{ |
| 8 | + public class SearchTest |
| 9 | + { |
| 10 | + private MockedCloudinary m_cloudinary = new MockedCloudinary(); |
| 11 | + |
| 12 | + [Test] |
| 13 | + public void TestShouldNotDuplicateValues() |
| 14 | + { |
| 15 | + m_cloudinary |
| 16 | + .Search() |
| 17 | + .SortBy("created_at", "asc") |
| 18 | + .SortBy("created_at", "desc") |
| 19 | + .SortBy("public_id", "asc") |
| 20 | + .Aggregate("format") |
| 21 | + .Aggregate("format") |
| 22 | + .Aggregate("resource_type") |
| 23 | + .WithField("context") |
| 24 | + .WithField("context") |
| 25 | + .WithField("tags") |
| 26 | + .Execute(); |
| 27 | + |
| 28 | + AssertCorrectRequest(m_cloudinary.HttpRequestContent); |
| 29 | + } |
| 30 | + |
| 31 | + private void AssertCorrectRequest(string request) |
| 32 | + { |
| 33 | + var requestJson = JToken.Parse(request); |
| 34 | + |
| 35 | + Assert.IsNotNull(requestJson["sort_by"]); |
| 36 | + Assert.AreEqual( |
| 37 | + new List<Dictionary<string, string>> |
| 38 | + { |
| 39 | + new Dictionary<string, string> { ["created_at"] = "desc" }, |
| 40 | + new Dictionary<string, string> { ["public_id"] = "asc" } |
| 41 | + }, |
| 42 | + requestJson["sort_by"] |
| 43 | + .Children<JObject>() |
| 44 | + .Select(item => |
| 45 | + new Dictionary<string, string> |
| 46 | + { |
| 47 | + [item.Properties().First().Name] = item.Properties().First().Value.ToString() |
| 48 | + }) |
| 49 | + ); |
| 50 | + |
| 51 | + Assert.IsNotNull(requestJson["aggregate"]); |
| 52 | + Assert.AreEqual(new[] { "format", "resource_type" }, requestJson["aggregate"].Values<string>()); |
| 53 | + |
| 54 | + Assert.IsNotNull(requestJson["with_field"]); |
| 55 | + Assert.AreEqual(new[] { "context", "tags" }, requestJson["with_field"].Values<string>()); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments