-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
156 lines (129 loc) · 6.42 KB
/
Copy pathProgram.cs
File metadata and controls
156 lines (129 loc) · 6.42 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
using System;
using System.Diagnostics;
using System.Threading;
namespace RevitTestAdapter.Logging.Demo
{
public static class Program
{
private const int BannerWidth = 80;
public static int Main(string[] args)
{
var sink = new ConsoleLogSink();
var stopwatch = Stopwatch.StartNew();
var info = new TestRunInfo
{
AdapterName = "RevitTestAdapter",
AdapterVersion = "1.4.0",
TargetFramework = ".NET Framework 4.8",
HostApplication = "Revit 2024",
AssemblyPath = @"C:\Projects\MyApp\bin\Debug\MyApp.Tests.dll",
Filter = "FullyQualifiedName~UserService|FullyQualifiedName~OrderRepository",
StartedUtc = new DateTime(2026, 4, 30, 14, 23, 0, DateTimeKind.Utc)
};
sink.WriteLine(new string('=', BannerWidth));
sink.WriteLine($" {info.AdapterName} v{info.AdapterVersion}");
if (!string.IsNullOrEmpty(info.TargetFramework) || !string.IsNullOrEmpty(info.HostApplication))
{
var parts = new System.Collections.Generic.List<string>();
if (!string.IsNullOrEmpty(info.TargetFramework)) parts.Add(info.TargetFramework);
if (!string.IsNullOrEmpty(info.HostApplication)) parts.Add(info.HostApplication);
sink.WriteLine(" " + string.Join(" | ", parts));
}
if (!string.IsNullOrEmpty(info.AssemblyPath))
sink.WriteLine($" Assembly: {info.AssemblyPath}");
sink.WriteLine($" Filter: {(string.IsNullOrEmpty(info.Filter) ? "(none)" : info.Filter)}");
sink.WriteLine($" Started: {info.StartedUtc:yyyy-MM-dd HH:mm:ss} UTC");
sink.WriteLine($" Machine: {info.MachineName} | PID: {info.ProcessId}");
sink.WriteLine(new string('=', BannerWidth));
sink.WriteLine(string.Empty);
sink.Flush();
RunDiscoveryDemo(sink, stopwatch);
Console.WriteLine();
RunPipeConnectionDemo(sink, stopwatch);
Console.WriteLine();
return RunExecutionDemo(sink, stopwatch);
}
private static void RunDiscoveryDemo(ILogSink sink, Stopwatch stopwatch)
{
var logger = new TestDiscoverLogger(sink, stopwatch);
logger.ClassDiscovered("MyApp.Tests.UserServiceTests",
[
"Should_CreateUser_WhenValidInput",
"Should_ThrowException_WhenNullEmail"
]);
logger.ClassDiscovered("MyApp.Tests.OrderRepositoryTests",
[
"Should_ReturnOrder_WhenIdExists",
"Should_ReturnNull_WhenIdMissing",
"Should_ThrowOnConnectionFailure"
]);
logger.ClassDiscovered("MyApp.Tests.PaymentServiceTests",
[
"Should_ChargeCard_WhenValid"
]);
logger.WriteSummary(new TestDiscoverySummary
{
TotalClasses = 3,
TotalMethods = 6,
Duration = TimeSpan.FromMilliseconds(12),
FinishedUtc = new DateTime(2026, 4, 30, 14, 23, 0, DateTimeKind.Utc)
});
}
private static void RunPipeConnectionDemo(ILogSink sink, Stopwatch stopwatch)
{
var logger = new PipeConnectionLogger(sink, stopwatch);
logger.Connecting(@"\\.\pipe\RevitTestAdapter", timeoutMs: 5000);
logger.Connected(@"\\.\pipe\RevitTestAdapter", TimeSpan.FromMilliseconds(44));
logger.Disconnecting();
}
private static int RunExecutionDemo(ILogSink sink, Stopwatch stopwatch)
{
var logger = new TestRunLogger(sink, stopwatch);
var summary = new TestRunSummary
{
TotalClasses = 2,
TotalTests = 5
};
logger.RunStarted(classCount: 2, methodCount: 5);
// ---- UserServiceTests ----
logger.ClassStarted("MyApp.Tests.UserServiceTests", testCount: 2);
logger.ClassInitialize("MyApp.Tests.UserServiceTests");
Thread.Sleep(40);
logger.MethodPassed("Should_CreateUser_WhenValidInput", TimeSpan.FromMilliseconds(44));
summary.Passed++;
Thread.Sleep(30);
logger.MethodFailed(
"Should_ThrowException_WhenNullEmail",
TimeSpan.FromMilliseconds(30),
expected: "ArgumentNullException",
actual: "<no exception thrown>",
stackLine: "at MyApp.Tests.UserServiceTests.Should_ThrowException_WhenNullEmail() in UserServiceTests.cs:line 42");
summary.Failed++;
summary.FailedTests.Add(new FailedTestInfo
{
FullyQualifiedName = "MyApp.Tests.UserServiceTests.Should_ThrowException_WhenNullEmail",
SourceLocation = "UserServiceTests.cs:42",
Reason = "Expected ArgumentNullException, got <no exception thrown>"
});
logger.ClassCleanup("MyApp.Tests.UserServiceTests");
logger.ClassFinished("UserServiceTests", passed: 1, failed: 1, elapsed: TimeSpan.FromMilliseconds(145));
// ---- OrderRepositoryTests ----
logger.ClassStarted("MyApp.Tests.OrderRepositoryTests", testCount: 3);
logger.ClassInitialize("MyApp.Tests.OrderRepositoryTests");
logger.MethodPassed("Should_ReturnOrder_WhenIdExists", TimeSpan.FromMilliseconds(32));
summary.Passed++;
logger.MethodPassed("Should_ReturnNull_WhenIdMissing", TimeSpan.FromMilliseconds(22));
summary.Passed++;
logger.MethodDiagnostic(LogLevel.Warn, "Retrying connection (attempt 2/3)");
logger.MethodPassed("Should_ThrowOnConnectionFailure", TimeSpan.FromMilliseconds(85));
summary.Passed++;
logger.ClassCleanup("MyApp.Tests.OrderRepositoryTests");
logger.ClassFinished("OrderRepositoryTests", passed: 3, failed: 0, elapsed: TimeSpan.FromMilliseconds(170));
summary.Duration = TimeSpan.FromMilliseconds(347);
summary.FinishedUtc = new DateTime(2026, 4, 30, 14, 23, 1, DateTimeKind.Utc);
logger.RunCompleted(summary.Passed, summary.Failed, summary.Skipped, summary.Duration);
logger.WriteSummary(summary);
return summary.Failed == 0 ? 0 : 1;
}
}
}