@@ -11,66 +11,64 @@ public class NotImplementedAttribute : TestCategoryBaseAttribute
1111{
1212 public string Reason { get ; set ; }
1313
14- public override IList < string > TestCategories => new [ ] { "NotImplemented" } ;
14+ public override IList < string > TestCategories { get ; } = [ "NotImplemented" ] ;
1515}
1616
1717[ AttributeUsage ( AttributeTargets . Method ) ]
1818public class ImplementedAttribute : TestCategoryBaseAttribute
1919{
2020 public string Reason { get ; set ; }
2121
22- public override IList < string > TestCategories => new [ ] { "Completed" } ;
22+ public override IList < string > TestCategories { get ; } = [ "Completed" ] ;
2323}
2424
2525[ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
26- public class AssertionDiagnosticAttribute : Attribute , ITestDataSource
26+ public abstract class AssertionDiagnosticBaseAttribute ( string assertion , params string [ ] additionalParameters ) : Attribute , ITestDataSource
2727{
28- public string Assertion { get ; }
28+ public string Assertion { get ; } = assertion ;
2929
30- public string [ ] AdditionalParameters { get ; }
30+ public string [ ] AdditionalParameters { get ; } = additionalParameters ?? [ ] ;
3131
32- public AssertionDiagnosticAttribute ( string assertion , params string [ ] additionalParameters )
33- {
34- Assertion = assertion ;
35- AdditionalParameters = additionalParameters ?? Array . Empty < string > ( ) ;
36- }
32+ private protected abstract IEnumerable < string > GetTestCases ( ) ;
3733
3834 public IEnumerable < object [ ] > GetData ( MethodInfo methodInfo )
3935 {
40- foreach ( var assertion in TestCasesInputUtils . GetTestCases ( Assertion ) )
36+ foreach ( var assertion in GetTestCases ( ) )
4137 {
4238 yield return new object [ ] { assertion } . Concat ( AdditionalParameters ) . ToArray ( ) ;
4339 }
4440 }
4541
46- public string GetDisplayName ( MethodInfo methodInfo , object [ ] data ) => $ "{ methodInfo . Name } (\" { string . Join ( "\" , \" " , data ) } \" )";
42+ public string GetDisplayName ( MethodInfo methodInfo , object [ ] data )
43+ => $ "{ methodInfo . Name } (\" { string . Join ( "\" , \" " , data ) } \" )";
4744}
4845
49- [ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
50- public class IgnoreAssertionDiagnosticAttribute : Attribute
46+ public sealed class AssertionDiagnosticAttribute ( string assertion , params string [ ] additionalParameters )
47+ : AssertionDiagnosticBaseAttribute ( assertion , additionalParameters )
5148{
52- public string Assertion { get ; }
49+ private protected override IEnumerable < string > GetTestCases ( )
50+ => TestCasesInputUtils . GetTestCases ( Assertion , MessageFormat . Simple | MessageFormat . Because | MessageFormat . FormattedBecause ) ;
51+ }
5352
54- public IgnoreAssertionDiagnosticAttribute ( string assertion ) => Assertion = assertion ;
53+ [ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
54+ public class IgnoreAssertionDiagnosticAttribute ( string assertion ) : Attribute
55+ {
56+ public string Assertion { get ; } = assertion ;
5557}
5658
5759[ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
58- public class AssertionCodeFixAttribute : Attribute , ITestDataSource
60+ public abstract class AssertionCodeFixBaseAttribute ( string oldAssertion , string newAssertion , params string [ ] additionalParameters )
61+ : Attribute , ITestDataSource
5962{
60- public string OldAssertion { get ; }
61- public string NewAssertion { get ; }
62- public string [ ] AdditionalParameters { get ; }
63+ public string OldAssertion { get ; } = oldAssertion ;
64+ public string NewAssertion { get ; } = newAssertion ;
65+ public string [ ] AdditionalParameters { get ; } = additionalParameters ?? [ ] ;
6366
64- public AssertionCodeFixAttribute ( string oldAssertion , string newAssertion , params string [ ] additionalParameters )
65- {
66- OldAssertion = oldAssertion ;
67- NewAssertion = newAssertion ;
68- AdditionalParameters = additionalParameters ?? Array . Empty < string > ( ) ;
69- }
67+ private protected abstract IEnumerable < ( string oldAssertion , string newAssertion ) > GetTestCases ( ) ;
7068
7169 public IEnumerable < object [ ] > GetData ( MethodInfo methodInfo )
7270 {
73- foreach ( var ( oldAssertion , newAssertion ) in TestCasesInputUtils . GetTestCases ( OldAssertion , NewAssertion ) )
71+ foreach ( var ( oldAssertion , newAssertion ) in GetTestCases ( ) )
7472 {
7573 yield return new object [ ] { oldAssertion , newAssertion } . Concat ( AdditionalParameters ) . ToArray ( ) ;
7674 }
@@ -87,6 +85,13 @@ public string GetDisplayName(MethodInfo methodInfo, object[] data)
8785 }
8886}
8987
88+ public class AssertionCodeFixAttribute ( string oldAssertion , string newAssertion , params string [ ] additionalParameters )
89+ : AssertionCodeFixBaseAttribute ( oldAssertion , newAssertion , additionalParameters )
90+ {
91+ private protected override IEnumerable < ( string oldAssertion , string newAssertion ) > GetTestCases ( )
92+ => TestCasesInputUtils . GetTestCases ( OldAssertion , NewAssertion ) ;
93+ }
94+
9095[ AttributeUsage ( AttributeTargets . Method , AllowMultiple = true ) ]
9196public class IgnoreAssertionCodeFixAttribute : Attribute
9297{
@@ -128,34 +133,63 @@ public IgnoreAssertionMethodCodeFixAttribute(string methodArguments, string oldA
128133 => ( MethodArguments , OldAssertion , NewAssertion ) = ( methodArguments , oldAssertion , newAssertion ) ;
129134}
130135
131- public static class TestCasesInputUtils
136+ [ Flags ]
137+ internal enum MessageFormat
132138{
133- private static readonly string Empty = string . Empty ;
134- private static readonly string Because = "\" because it's possible\" " ;
135- private static readonly string FormattedBecause = "\" because message with {0} placeholders {1} at {2}\" , 3, \" is awesome\" , DateTime.Now.Add(2.Seconds())" ;
136- public static IEnumerable < string > GetTestCases ( string assertion )
139+ Simple = 1 ,
140+ Because = 2 ,
141+ FormattedBecause = 4 ,
142+ InterpolatedBecause = 8 ,
143+ Default = Simple | Because | FormattedBecause ,
144+ }
145+
146+ internal static class TestCasesInputUtils
147+ {
148+ private const string Empty = "" ;
149+ private const string Because = "\" because it's possible\" " ;
150+ private const string FormattedBecause = "\" because message with {0} placeholders {1} at {2}\" , 3, \" is awesome\" , DateTime.Now.Add(2.Seconds())" ;
151+ private const string InterpolatedBecause = "$\" because message with {3} placeholders {DateTime.Now}\" " ;
152+
153+ public static IEnumerable < string > GetTestCases ( string assertion , MessageFormat messageFormat = MessageFormat . Default )
137154 {
138155 if ( ! assertion . Contains ( "{0}" ) )
139156 {
140157 yield return assertion ;
141158 yield break ;
142159 }
143160
144- yield return SafeFormat ( assertion , Empty ) ;
145- yield return SafeFormat ( assertion , Because ) ;
146- yield return SafeFormat ( assertion , FormattedBecause ) ;
161+ if ( messageFormat . HasFlag ( MessageFormat . Simple ) )
162+ yield return SafeFormat ( assertion , Empty ) ;
163+
164+ if ( messageFormat . HasFlag ( MessageFormat . Because ) )
165+ yield return SafeFormat ( assertion , Because ) ;
166+
167+ if ( messageFormat . HasFlag ( MessageFormat . FormattedBecause ) )
168+ yield return SafeFormat ( assertion , FormattedBecause ) ;
169+
170+ if ( messageFormat . HasFlag ( MessageFormat . InterpolatedBecause ) )
171+ yield return SafeFormat ( assertion , InterpolatedBecause ) ;
147172 }
148- public static IEnumerable < ( string oldAssertion , string newAssertion ) > GetTestCases ( string oldAssertion , string newAssertion )
173+
174+ public static IEnumerable < ( string oldAssertion , string newAssertion ) > GetTestCases ( string oldAssertion , string newAssertion , MessageFormat messageFormat = MessageFormat . Default )
149175 {
150176 if ( ! oldAssertion . Contains ( "{0}" ) && ! newAssertion . Contains ( "{0}" ) )
151177 {
152178 yield return ( oldAssertion , newAssertion ) ;
153179 yield break ;
154180 }
155181
156- yield return ( SafeFormat ( oldAssertion , Empty ) , SafeFormat ( newAssertion , Empty ) ) ;
157- yield return ( SafeFormat ( oldAssertion , Because ) , SafeFormat ( newAssertion , Because ) ) ;
158- yield return ( SafeFormat ( oldAssertion , FormattedBecause ) , SafeFormat ( newAssertion , FormattedBecause ) ) ;
182+ if ( messageFormat . HasFlag ( MessageFormat . Simple ) )
183+ yield return ( SafeFormat ( oldAssertion , Empty ) , SafeFormat ( newAssertion , Empty ) ) ;
184+
185+ if ( messageFormat . HasFlag ( MessageFormat . Because ) )
186+ yield return ( SafeFormat ( oldAssertion , Because ) , SafeFormat ( newAssertion , Because ) ) ;
187+
188+ if ( messageFormat . HasFlag ( MessageFormat . FormattedBecause ) )
189+ yield return ( SafeFormat ( oldAssertion , FormattedBecause ) , SafeFormat ( newAssertion , FormattedBecause ) ) ;
190+
191+ if ( messageFormat . HasFlag ( MessageFormat . InterpolatedBecause ) )
192+ yield return ( SafeFormat ( oldAssertion , InterpolatedBecause ) , SafeFormat ( newAssertion , InterpolatedBecause ) ) ;
159193 }
160194
161195 /// <summary>
0 commit comments