|
| 1 | +//------------------------------------------------------------ |
| 2 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +//------------------------------------------------------------ |
| 4 | + |
| 5 | +namespace Microsoft.Azure.Cosmos.Linq |
| 6 | +{ |
| 7 | + using System; |
| 8 | + using System.Collections.Generic; |
| 9 | + using System.Linq; |
| 10 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// Tests for GitHub Issue #5547: |
| 14 | + /// LINQ queries using .Any() on Dictionary<string, object> properties should generate SQL using OBJECTTOARRAY. |
| 15 | + /// </summary> |
| 16 | + [TestClass] |
| 17 | + public class LinqDictionaryQueryTests |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// Test that IsDictionary correctly identifies Dictionary types. |
| 21 | + /// </summary> |
| 22 | + [TestMethod] |
| 23 | + public void IsDictionary_ShouldReturnTrueForDictionaryTypes() |
| 24 | + { |
| 25 | + // Test Dictionary<,> |
| 26 | + Assert.IsTrue(typeof(Dictionary<string, object>).IsDictionary()); |
| 27 | + Assert.IsTrue(typeof(Dictionary<int, string>).IsDictionary()); |
| 28 | + |
| 29 | + // Test IDictionary<,> |
| 30 | + Assert.IsTrue(typeof(IDictionary<string, object>).IsDictionary()); |
| 31 | + Assert.IsTrue(typeof(IDictionary<int, string>).IsDictionary()); |
| 32 | + |
| 33 | + // Test types that implement IDictionary<,> |
| 34 | + Assert.IsTrue(typeof(SortedDictionary<string, object>).IsDictionary()); |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Test that IsDictionary correctly rejects non-Dictionary types. |
| 39 | + /// </summary> |
| 40 | + [TestMethod] |
| 41 | + public void IsDictionary_ShouldReturnFalseForNonDictionaryTypes() |
| 42 | + { |
| 43 | + // Test arrays |
| 44 | + Assert.IsFalse(typeof(string[]).IsDictionary()); |
| 45 | + Assert.IsFalse(typeof(int[]).IsDictionary()); |
| 46 | + |
| 47 | + // Test lists |
| 48 | + Assert.IsFalse(typeof(List<string>).IsDictionary()); |
| 49 | + Assert.IsFalse(typeof(List<object>).IsDictionary()); |
| 50 | + |
| 51 | + // Test IEnumerable |
| 52 | + Assert.IsFalse(typeof(IEnumerable<string>).IsDictionary()); |
| 53 | + |
| 54 | + // Test primitives |
| 55 | + Assert.IsFalse(typeof(string).IsDictionary()); |
| 56 | + Assert.IsFalse(typeof(int).IsDictionary()); |
| 57 | + |
| 58 | + // Test other collections |
| 59 | + Assert.IsFalse(typeof(HashSet<string>).IsDictionary()); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments