|
1 | 1 | using Cosmos.DataTransfer.Interfaces;
|
2 | 2 | using System.Dynamic;
|
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
3 | 4 |
|
4 | 5 | namespace Cosmos.DataTransfer.CosmosExtension.UnitTests
|
5 | 6 | {
|
@@ -56,6 +57,83 @@ public void BuildDynamicObjectTree_WithNestedArrays_WorksCorrectly()
|
56 | 57 | Assert.AreEqual("sub2-1", secondSubArray[0].id);
|
57 | 58 | }
|
58 | 59 |
|
| 60 | + [TestMethod] |
| 61 | + public void BuildDynamicObjectTree_WithAnyCaseIds_UsesSourceIdValue() |
| 62 | + { |
| 63 | + var numeric = Random.Shared.Next(); |
| 64 | + var lower = Guid.NewGuid().ToString(); |
| 65 | + var upper = Guid.NewGuid().ToString(); |
| 66 | + var mixed = Guid.NewGuid().ToString(); |
| 67 | + var reversed = Guid.NewGuid().ToString(); |
| 68 | + var item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 69 | + { |
| 70 | + { "id", numeric }, |
| 71 | + }); |
| 72 | + |
| 73 | + dynamic obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: false)!; |
| 74 | + Assert.AreEqual(numeric.ToString(), obj.id); |
| 75 | + |
| 76 | + item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 77 | + { |
| 78 | + { "id", lower }, |
| 79 | + }); |
| 80 | + |
| 81 | + obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: false)!; |
| 82 | + Assert.AreEqual(lower, obj.id); |
| 83 | + |
| 84 | + item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 85 | + { |
| 86 | + { "ID", upper }, |
| 87 | + }); |
| 88 | + obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: false)!; |
| 89 | + Assert.AreEqual(upper, obj.id); |
| 90 | + |
| 91 | + item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 92 | + { |
| 93 | + { "Id", mixed }, |
| 94 | + }); |
| 95 | + obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: false)!; |
| 96 | + Assert.AreEqual(mixed, obj.id); |
| 97 | + |
| 98 | + item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 99 | + { |
| 100 | + { "iD", reversed }, |
| 101 | + }); |
| 102 | + obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: false)!; |
| 103 | + Assert.AreEqual(reversed, obj.id); |
| 104 | + } |
| 105 | + |
| 106 | + [TestMethod] |
| 107 | + public void BuildDynamicObjectTree_WithPreservedMixedCaseIds_PassesThroughSourceValues() |
| 108 | + { |
| 109 | + var id = Random.Shared.Next(); |
| 110 | + var upper = Guid.NewGuid().ToString(); |
| 111 | + var mixed = Guid.NewGuid().ToString(); |
| 112 | + var item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 113 | + { |
| 114 | + { "id", id }, |
| 115 | + { "ID", upper }, |
| 116 | + { "Id", mixed } |
| 117 | + }); |
| 118 | + |
| 119 | + dynamic obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: true)!; |
| 120 | + Assert.AreEqual(id.ToString(), obj.id); |
| 121 | + Assert.AreEqual(upper, obj.ID); |
| 122 | + Assert.AreEqual(mixed, obj.Id); |
| 123 | + |
| 124 | + item = new CosmosDictionaryDataItem(new Dictionary<string, object?>() |
| 125 | + { |
| 126 | + { "ID", upper }, |
| 127 | + { "Id", mixed } |
| 128 | + }); |
| 129 | + obj = item.BuildDynamicObjectTree(requireStringId: true, preserveMixedCaseIds: true)!; |
| 130 | + Assert.AreEqual(upper, obj.ID); |
| 131 | + Assert.AreEqual(mixed, obj.Id); |
| 132 | + string? cosmosId = obj.id; |
| 133 | + Assert.IsNotNull(cosmosId); |
| 134 | + Assert.IsFalse(string.IsNullOrWhiteSpace(cosmosId)); |
| 135 | + } |
| 136 | + |
59 | 137 | [TestMethod]
|
60 | 138 | public void BuildDynamicObjectTree_WithIgnoredNulls_ExcludesNullFields()
|
61 | 139 | {
|
|
0 commit comments