-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathColumnDiffHelperTests.cs
More file actions
185 lines (158 loc) · 5.64 KB
/
ColumnDiffHelperTests.cs
File metadata and controls
185 lines (158 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using KustoSchemaTools.Changes;
namespace KustoSchemaTools.Tests.Changes
{
public class ColumnDiffHelperTests
{
[Fact]
public void BuildColumnDiff_WithAddedColumns_ShowsAdditions()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" },
{ "new_col", "long" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.NotNull(result);
Assert.Contains("+ new_col: long", result);
Assert.DoesNotContain("id", result);
Assert.DoesNotContain("timestamp", result);
}
[Fact]
public void BuildColumnDiff_WithTypeChange_ShowsTypeChange()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "count", "int" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "count", "long" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.NotNull(result);
Assert.Contains("! count: int → long", result);
Assert.DoesNotContain("id", result);
}
[Fact]
public void BuildColumnDiff_WithRemovedColumns_ShowsInformationalNote()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "old_col", "string" },
{ "timestamp", "datetime" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.NotNull(result);
Assert.Contains("old_col: string (live only)", result);
Assert.Contains(".create-merge", result);
Assert.DoesNotContain("+ ", result);
}
[Fact]
public void BuildColumnDiff_WithNoChanges_ReturnsNull()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.Null(result);
}
[Fact]
public void BuildColumnDiff_WithNullOldColumns_TreatsAsNewTable()
{
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" }
};
var result = ColumnDiffHelper.BuildColumnDiff(null, newColumns);
Assert.NotNull(result);
Assert.Contains("+ id: string", result);
Assert.Contains("+ timestamp: datetime", result);
}
[Fact]
public void BuildColumnDiff_WithNullNewColumns_ReturnsNull()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, null);
Assert.Null(result);
}
[Fact]
public void BuildColumnDiff_WithMixedChanges_ShowsAllCategories()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "count", "int" },
{ "removed_col", "string" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "count", "long" },
{ "new_col", "datetime" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.NotNull(result);
Assert.Contains("+ new_col: datetime", result);
Assert.Contains("! count: int → long", result);
Assert.Contains("removed_col: string (live only)", result);
}
[Fact]
public void BuildColumnDiff_CaseInsensitiveTypeComparison_IgnoresCaseDifference()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "String" }
};
var newColumns = new Dictionary<string, string>
{
{ "id", "string" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.Null(result);
}
[Fact]
public void BuildColumnDiff_ReorderOnly_ReturnsNull()
{
var oldColumns = new Dictionary<string, string>
{
{ "id", "string" },
{ "timestamp", "datetime" },
{ "count", "long" }
};
// Same columns, different insertion order in the dictionary
var newColumns = new Dictionary<string, string>
{
{ "count", "long" },
{ "id", "string" },
{ "timestamp", "datetime" }
};
var result = ColumnDiffHelper.BuildColumnDiff(oldColumns, newColumns);
Assert.Null(result);
}
}
}