-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
173 lines (159 loc) · 5.49 KB
/
Copy pathProgram.cs
File metadata and controls
173 lines (159 loc) · 5.49 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
#nullable enable
using System;
using System.Text.Json;
using SqliteMultiTenant.Models;
using SqliteMultiTenant.Constants;
Console.WriteLine("Testing MigrationJsonExtensions...\n");
// Create a test migration
var migration = new Migration
{
MigrationId = "test-migration-001",
DatabaseId = "db-001",
Version = "1.0.0",
Name = "InitialSetup",
Description = "Initial database setup migration",
UpScript = "CREATE TABLE TestTable (Id INTEGER PRIMARY KEY, Name TEXT);",
DownScript = "DROP TABLE TestTable;",
Status = MigrationStatus.Completed,
CreatedAt = DateTime.UtcNow,
ExecutedAt = DateTime.UtcNow.AddMinutes(-5),
CompletedAt = DateTime.UtcNow.AddMinutes(-3),
ExecutedBy = "test-user",
ExecutionTimeMs = 150,
ExecutionOrder = 1,
IsRollbackable = true
};
Console.WriteLine("1. Testing ToJson with compact format...");
try
{
string jsonCompact = migration.ToJson();
Console.WriteLine("✓ ToJson() succeeded");
Console.WriteLine($"JSON length: {jsonCompact.Length} characters");
Console.WriteLine("First 100 chars:");
Console.WriteLine(jsonCompact[..Math.Min(100, jsonCompact.Length)]);
}
catch (Exception ex)
{
Console.WriteLine($"✗ ToJson() failed: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n2. Testing ToJson with indented format...");
try
{
string jsonIndented = migration.ToJson(indented: true);
Console.WriteLine("✓ ToJson(indented: true) succeeded");
Console.WriteLine("First 150 chars:");
Console.WriteLine(jsonIndented[..Math.Min(150, jsonIndented.Length)]);
}
catch (Exception ex)
{
Console.WriteLine($"✗ ToJson(indented: true) failed: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n3. Testing FromJson...");
try
{
string json = migration.ToJson();
Migration? deserialized = MigrationJsonExtensions.FromJson(json);
if (deserialized == null)
{
Console.WriteLine("✗ FromJson returned null");
Environment.Exit(1);
}
Console.WriteLine("✓ FromJson succeeded");
Console.WriteLine($"Deserialized MigrationId: {deserialized.MigrationId}");
Console.WriteLine($"Deserialized Version: {deserialized.Version}");
Console.WriteLine($"Deserialized Status: {deserialized.Status}");
}
catch (Exception ex)
{
Console.WriteLine($"✗ FromJson failed: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n4. Testing TryFromJson with valid JSON...");
try
{
string json = migration.ToJson();
bool success = MigrationJsonExtensions.TryFromJson(json, out var result);
if (!success || result == null)
{
Console.WriteLine("✗ TryFromJson returned false or null");
Environment.Exit(1);
}
Console.WriteLine("✓ TryFromJson succeeded with valid JSON");
}
catch (Exception ex)
{
Console.WriteLine($"✗ TryFromJson failed: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n5. Testing TryFromJson with invalid JSON...");
try
{
bool success = MigrationJsonExtensions.TryFromJson("invalid json {{{", out var result);
if (success)
{
Console.WriteLine("✗ TryFromJson should have returned false for invalid JSON");
Environment.Exit(1);
}
Console.WriteLine("✓ TryFromJson correctly returned false for invalid JSON");
}
catch (Exception ex)
{
Console.WriteLine($"✗ TryFromJson threw exception on invalid JSON: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n6. Testing TryFromJson with empty/whitespace JSON...");
try
{
bool success1 = MigrationJsonExtensions.TryFromJson("", out var result1);
bool success2 = MigrationJsonExtensions.TryFromJson(" ", out var result2);
bool success3 = MigrationJsonExtensions.TryFromJson(null, out var result3);
if (success1 || success2 || success3)
{
Console.WriteLine("✗ TryFromJson should have returned false for empty/whitespace/null JSON");
Environment.Exit(1);
}
Console.WriteLine("✓ TryFromJson correctly returned false for empty/whitespace/null JSON");
}
catch (Exception ex)
{
Console.WriteLine($"✗ TryFromJson threw exception on empty JSON: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n7. Testing FromJson with empty/whitespace JSON...");
try
{
Migration? result1 = MigrationJsonExtensions.FromJson("");
Migration? result2 = MigrationJsonExtensions.FromJson(" ");
Migration? result3 = MigrationJsonExtensions.FromJson(null);
if (result1 != null || result2 != null || result3 != null)
{
Console.WriteLine("✗ FromJson should have returned null for empty/whitespace/null JSON");
Environment.Exit(1);
}
Console.WriteLine("✓ FromJson correctly returned null for empty/whitespace/null JSON");
}
catch (Exception ex)
{
Console.WriteLine($"✗ FromJson threw exception on empty JSON: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n8. Testing camelCase property naming...");
try
{
string json = migration.ToJson();
if (!json.Contains("migrationId") || !json.Contains("databaseId") || !json.Contains("upScript"))
{
Console.WriteLine("✗ JSON does not contain expected camelCase properties");
Console.WriteLine("Expected properties: migrationId, databaseId, upScript");
Environment.Exit(1);
}
Console.WriteLine("✓ JSON correctly uses camelCase property naming");
}
catch (Exception ex)
{
Console.WriteLine($"✗ camelCase test failed: {ex.Message}");
Environment.Exit(1);
}
Console.WriteLine("\n✅ All tests passed! MigrationJsonExtensions is working correctly.");