44// Created : 10-22-2023
55//
66// Last Modified By : David McCarter
7- // Last Modified On : 04-24 -2025
7+ // Last Modified On : 04-28 -2025
88// ***********************************************************************
99// <copyright file="UnitTester.cs" company="David McCarter - dotNetTips.com">
1010// McCarter Consulting (David McCarter)
1616// </summary>
1717// ***********************************************************************
1818using System . Diagnostics ;
19+ using System . Diagnostics . CodeAnalysis ;
1920using System . Reflection ;
2021using System . Runtime . CompilerServices ;
2122using DotNetTips . Spargine . Core ;
@@ -32,8 +33,9 @@ namespace DotNetTips.Spargine.Tester;
3233/// Initializes a new instance of the <see cref="UnitTester"/> class.
3334/// </remarks>
3435/// <param name="outputDirectory">The directory where output files will be saved. Defaults to the current directory if not specified.</param>
36+ [ ExcludeFromCodeCoverage ]
37+ [ DebuggerStepThrough ]
3538[ Information ( Status = Status . NeedsDocumentation , Documentation = "ADD URL" ) ]
36- [ method: Information ( nameof ( UnitTester ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . NotRequired , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
3739public abstract class UnitTester ( string outputDirectory = null )
3840{
3941 /// <summary>
@@ -55,10 +57,7 @@ public abstract class UnitTester(string outputDirectory = null)
5557 [ Information ( nameof ( PropertiesToString ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Completed , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
5658 protected virtual string PropertiesToString < T > ( T input , Func < PropertyInfo , bool > propertySelector )
5759 {
58- input = input . ArgumentNotNull ( ) ;
59- propertySelector = propertySelector . ArgumentNotNull ( ) ;
60-
61- return string . Join ( ", " , input . GetType ( )
60+ return string . Join ( ControlChars . CommaSpace , input . GetType ( )
6261 . GetProperties ( BindingFlags . Public | BindingFlags . Instance )
6362 . Where ( propertySelector )
6463 . Select ( prop =>
@@ -78,8 +77,9 @@ protected virtual string PropertiesToString<T>(T input, Func<PropertyInfo, bool>
7877 /// The name of the calling method. This is automatically populated by the compiler unless explicitly provided.
7978 /// </param>
8079 /// <exception cref="ArgumentNullException">Thrown when <paramref name="collection"/> or <paramref name="propertySelector"/> is null.</exception>
80+ [ DebuggerStepThrough ]
8181 [ Information ( nameof ( PrintToDebug ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Completed , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
82- public void PrintToDebug < T > ( IEnumerable < T > collection , Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
82+ public void PrintToDebug < T > ( [ NotNull ] IEnumerable < T > collection , [ NotNull ] Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
8383 {
8484 collection = collection . ArgumentNotNull ( ) ;
8585 propertySelector = propertySelector . ArgumentNotNull ( ) ;
@@ -108,8 +108,9 @@ public void PrintToDebug<T>(IEnumerable<T> collection, Func<PropertyInfo, bool>
108108 /// <exception cref="ArgumentNullException">
109109 /// Thrown when <paramref name="input"/> or <paramref name="propertySelector"/> is null.
110110 /// </exception>
111+ [ DebuggerStepThrough ]
111112 [ Information ( nameof ( PrintToDebug ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Completed , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
112- public void PrintToDebug < T > ( T input , Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
113+ public void PrintToDebug < T > ( [ NotNull ] T input , [ NotNull ] Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
113114 {
114115 input = input . ArgumentNotNull ( ) ;
115116 propertySelector = propertySelector . ArgumentNotNull ( ) ;
@@ -128,14 +129,15 @@ public void PrintToDebug<T>(T input, Func<PropertyInfo, bool> propertySelector,
128129 /// The name of the calling method. This is automatically populated by the compiler unless explicitly provided.
129130 /// </param>
130131 /// <exception cref="ArgumentNullException">Thrown when <paramref name="collection"/> or <paramref name="propertySelector"/> is null.</exception>
132+ [ DebuggerStepThrough ]
131133 [ Information ( nameof ( SaveToFile ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Completed , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
132- public void SaveToFile < T > ( IEnumerable < T > collection , Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
134+ public void SaveToFile < T > ( [ NotNull ] IEnumerable < T > collection , [ NotNull ] Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
133135 {
134136 collection = collection . ArgumentNotNull ( ) ;
135137 propertySelector = propertySelector . ArgumentNotNull ( ) ;
136138 methodName = methodName . ArgumentNotNullOrEmpty ( ) ;
137139
138- var filePath = Path . Combine ( this . _outputDirectory , $ "{ methodName } .txt") ;
140+ var filePath = Path . Combine ( this . OutputDirectory , $ "{ methodName } .txt") ;
139141
140142 var content = collection
141143 . Select ( item => this . PropertiesToString ( item , propertySelector ) )
@@ -156,14 +158,15 @@ public void SaveToFile<T>(IEnumerable<T> collection, Func<PropertyInfo, bool> pr
156158 /// <exception cref="ArgumentNullException">
157159 /// Thrown when <paramref name="input"/> or <paramref name="propertySelector"/> is null.
158160 /// </exception>
161+ [ DebuggerStepThrough ]
159162 [ Information ( nameof ( SaveToFile ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Completed , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
160- public void SaveToFile < T > ( T input , Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
163+ public void SaveToFile < T > ( [ NotNull ] T input , [ NotNull ] Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
161164 {
162165 input = input . ArgumentNotNull ( ) ;
163166 propertySelector = propertySelector . ArgumentNotNull ( ) ;
164167 methodName = methodName . ArgumentNotNullOrEmpty ( ) ;
165168
166- var filePath = Path . Combine ( this . _outputDirectory , $ "{ methodName } .txt") ;
169+ var filePath = Path . Combine ( this . OutputDirectory , $ "{ methodName } .txt") ;
167170
168171 var content = this . PropertiesToString ( input , propertySelector ) ;
169172 File . WriteAllText ( filePath , content ) ;
@@ -185,19 +188,29 @@ public void SaveToFile<T>(T input, Func<PropertyInfo, bool> propertySelector, [C
185188 /// <exception cref="ArgumentException">
186189 /// Thrown when <paramref name="methodName"/> is null or empty.
187190 /// </exception>
191+ [ AsyncStateMachine ( typeof ( Task ) ) ]
192+ [ DebuggerStepThrough ]
188193 [ Information ( nameof ( SaveToFileAsync ) , UnitTestStatus = UnitTestStatus . None , OptimizationStatus = OptimizationStatus . Optimize , BenchmarkStatus = BenchmarkStatus . NotRequired , Status = Status . New ) ]
189- public async Task SaveToFileAsync < T > ( IEnumerable < T > collection , Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
194+ public async Task SaveToFileAsync < T > ( [ NotNull ] IEnumerable < T > collection , [ NotNull ] Func < PropertyInfo , bool > propertySelector , [ CallerMemberName ] string methodName = ControlChars . EmptyString )
190195 {
191196 collection = collection . ArgumentNotNull ( ) ;
192197 propertySelector = propertySelector . ArgumentNotNull ( ) ;
193198 methodName = methodName . ArgumentNotNullOrEmpty ( ) ;
194199
195- var filePath = Path . Combine ( Directory . GetCurrentDirectory ( ) , $ "{ methodName } .txt") ;
200+ var filePath = Path . Combine ( this . OutputDirectory , $ "{ methodName } .txt") ;
196201
197202 var content = collection
198203 . Select ( item => this . PropertiesToString ( item , propertySelector ) )
199204 . ToArray ( ) ;
200205
201206 await File . WriteAllLinesAsync ( filePath , content , CancellationToken . None ) . ConfigureAwait ( false ) ;
202207 }
208+
209+ /// <summary>
210+ /// Gets the output directory where files will be saved.
211+ /// </summary>
212+ /// <value>
213+ /// A string representing the directory path where output files will be saved.
214+ /// </value>
215+ public string OutputDirectory => this . _outputDirectory ;
203216}
0 commit comments