55using System . Text ;
66using System . Threading . Tasks ;
77using FluentAssertions ;
8+ using SharedTestFramework ;
89using Xunit ;
910using Xunit . Abstractions ;
1011
@@ -19,67 +20,119 @@ public ConfirmMatchingTests(ITestOutputHelper output)
1920 _output = output ;
2021 }
2122
23+ private class ConfirmMatchingTestHelper
24+ {
25+ public ConfirmMatchingTestHelper ( )
26+ {
27+ PostgreAssembly = typeof ( ivaldez . Sql . IntegrationPostgreSqlTests . BulkLoading . BulkLoaderForBatchSizeTests )
28+ . Assembly ;
29+ SqlServerAssembly = typeof ( ivaldez . Sql . IntegrationSqlServerTests . BulkLoading . BulkLoaderForBatchSizeTests )
30+ . Assembly ;
31+
32+ var postgreAssemblyName = PostgreAssembly . GetName ( ) . Name ;
33+ var sqlServerAssemblyName = SqlServerAssembly . GetName ( ) . Name ;
34+
35+ PostgreClasses = PostgreAssembly . GetTypes ( ) . Where ( x => x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . ToArray ( ) ;
36+ SqlServerClasses = SqlServerAssembly . GetTypes ( ) . Where ( x => x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . ToArray ( ) ;
37+
38+ PostgreClassInfo = PostgreClasses . Select ( x => new ClassInfo
39+ {
40+ Class = x ,
41+ Assembly = x . Assembly ,
42+ ReferenceName = x . FullName . Replace ( postgreAssemblyName , "" ) ,
43+ Ignore = ShouldIgnore ( x )
44+ } )
45+ . Where ( x => x . Ignore == false ) . ToArray ( ) ;
46+ SqlServerClassInfo = SqlServerClasses . Select ( x => new ClassInfo
47+ {
48+ Class = x ,
49+ Assembly = x . Assembly ,
50+ ReferenceName = x . FullName . Replace ( sqlServerAssemblyName , "" ) ,
51+ Ignore = ShouldIgnore ( x )
52+ } )
53+ . Where ( x => x . Ignore == false ) . ToArray ( ) ;
54+ }
55+
56+ private bool ShouldIgnore ( Type type )
57+ {
58+ Attribute [ ] attrs = System . Attribute . GetCustomAttributes ( type ) ;
59+
60+ return attrs . Any ( x => x . GetType ( ) . FullName == typeof ( ImplementationSpecificTestAttribute ) . FullName ) ;
61+ }
62+
63+ public class ClassInfo
64+ {
65+ public string ReferenceName { get ; set ; }
66+ public Assembly Assembly { get ; set ; }
67+ public bool Ignore { get ; set ; }
68+ public Type Class { get ; set ; }
69+ }
70+
71+ public Type [ ] PostgreClasses { get ; set ; }
72+
73+ public Type [ ] SqlServerClasses { get ; set ; }
74+
75+ public ClassInfo [ ] SqlServerClassInfo { get ; set ; }
76+
77+ public ClassInfo [ ] PostgreClassInfo { get ; set ; }
78+
79+ public Assembly SqlServerAssembly { get ; set ; }
80+
81+ public Assembly PostgreAssembly { get ; set ; }
82+ }
83+
2284 [ Fact ( DisplayName = "Should find matching tests for all shared features between implementations" ) ]
2385 public void TestClassesMatchingTests ( )
2486 {
25- var sourceClass1 = typeof ( ivaldez . Sql . IntegrationPostgreSqlTests . BulkLoading . BulkLoaderForBatchSizeTests )
26- . Assembly ;
27- var sourceClass2 = typeof ( ivaldez . Sql . IntegrationSqlServerTests . BulkLoading . BulkLoaderForBatchSizeTests )
28- . Assembly ;
87+ var helper = new ConfirmMatchingTestHelper ( ) ;
2988
30- var allTestMethods1 = sourceClass1 . GetTypes ( ) . Where ( x => x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . Select ( x => x . Name ) . ToArray ( ) ;
31- var allTestMethods2 = sourceClass2 . GetTypes ( ) . Where ( x => x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . Select ( x => x . Name ) . ToArray ( ) ;
89+ var postgreClasses = helper . PostgreClassInfo . Select ( x => x . ReferenceName ) . ToArray ( ) ;
90+ var sqlServerClasses = helper . SqlServerClassInfo . Select ( x => x . ReferenceName ) . ToArray ( ) ;
3291
33- var testsMIssingIn1 = allTestMethods1 . Except ( allTestMethods2 ) . ToArray ( ) ;
34- var testsMIssingIn2 = allTestMethods2 . Except ( allTestMethods1 ) . ToArray ( ) ;
92+ var postgreMissingClasses = postgreClasses . Except ( sqlServerClasses ) . ToArray ( ) ;
93+ var sqlServerMissingClasses = sqlServerClasses . Except ( postgreClasses ) . ToArray ( ) ;
3594
36- _output . WriteLine ( $ "Test classes missing in: { sourceClass1 } ") ;
37- foreach ( var missing in testsMIssingIn1 )
95+ _output . WriteLine ( $ "Test classes missing in: { helper . PostgreAssembly } ") ;
96+ foreach ( var missing in postgreMissingClasses )
3897 {
3998 _output . WriteLine ( $ "Test classes missing: { missing } ") ;
4099 }
41100
42- _output . WriteLine ( $ "Test classes missing in: { sourceClass2 } ") ;
43- foreach ( var missing in testsMIssingIn2 )
101+ _output . WriteLine ( $ "Test classes missing in: { helper . SqlServerAssembly } ") ;
102+ foreach ( var missing in sqlServerMissingClasses )
44103 {
45104 _output . WriteLine ( $ "Test classes missing: { missing } ") ;
46105 }
47106
48- testsMIssingIn1 . Length . Should ( ) . Be ( 0 ) ;
49- testsMIssingIn2 . Length . Should ( ) . Be ( 0 ) ;
107+ postgreMissingClasses . Length . Should ( ) . Be ( 0 ) ;
108+ sqlServerMissingClasses . Length . Should ( ) . Be ( 0 ) ;
50109 }
51110
52111 [ Fact ( DisplayName = "Should find matching test methods for all shared features between implementations" ) ]
53112 public void TestMethodMatchingTests ( )
54113 {
55- var sourceClass1 = typeof ( ivaldez . Sql . IntegrationPostgreSqlTests . BulkLoading . BulkLoaderForBatchSizeTests )
56- . Assembly ;
57- var sourceClass2 = typeof ( ivaldez . Sql . IntegrationSqlServerTests . BulkLoading . BulkLoaderForBatchSizeTests )
58- . Assembly ;
59-
60- var allTestClasses1 = sourceClass1 . GetTypes ( ) . Where ( x => x . IsClass && x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . ToArray ( ) ;
61- var allTestClasses2 = sourceClass2 . GetTypes ( ) . Where ( x => x . IsClass && x . Name . ToLower ( ) . EndsWith ( "tests" ) ) . ToArray ( ) ;
62-
114+ var helper = new ConfirmMatchingTestHelper ( ) ;
115+
63116 var errorCount = 0 ;
64- foreach ( var classDefinition in allTestClasses1 )
117+ foreach ( var postgreClassInfo in helper . PostgreClassInfo )
65118 {
66- var matchingType = allTestClasses2 . First ( x => x . Name == classDefinition . Name ) ;
119+ var matchingSqlServerClassInfo = helper . SqlServerClassInfo . First ( x => x . ReferenceName == postgreClassInfo . ReferenceName ) ;
67120
68- var allTestMethods1 = classDefinition . GetMethods ( ) . Select ( x => x . Name ) . ToArray ( ) ;
69- var allTestMethods2 = matchingType . GetMethods ( ) . Select ( x => x . Name ) . ToArray ( ) ;
121+ var postgreMethods = postgreClassInfo . Class . GetMethods ( ) . Select ( x => x . Name ) . ToArray ( ) ;
122+ var sqlServerMethods = matchingSqlServerClassInfo . Class . GetMethods ( ) . Select ( x => x . Name ) . ToArray ( ) ;
70123
71- var testsMIssingIn1 = allTestMethods1 . Except ( allTestMethods2 ) . ToArray ( ) ;
72- var testsMIssingIn2 = allTestMethods2 . Except ( allTestMethods1 ) . ToArray ( ) ;
124+ var postgreMissingSqlServer = postgreMethods . Except ( sqlServerMethods ) . ToArray ( ) ;
125+ var sqlServerMissingPostgre = sqlServerMethods . Except ( postgreMethods ) . ToArray ( ) ;
73126
74- _output . WriteLine ( $ "Test class: { classDefinition } ") ;
75- foreach ( var missing in testsMIssingIn1 )
127+ _output . WriteLine ( $ "Test class: { postgreClassInfo } ") ;
128+ foreach ( var missing in postgreMissingSqlServer )
76129 {
77130 errorCount ++ ;
78131 _output . WriteLine ( $ "***missing method: { missing } ") ;
79132 }
80133
81- _output . WriteLine ( $ "Test class: { matchingType } ") ;
82- foreach ( var missing in testsMIssingIn2 )
134+ _output . WriteLine ( $ "Test class: { matchingSqlServerClassInfo } ") ;
135+ foreach ( var missing in sqlServerMissingPostgre )
83136 {
84137 errorCount ++ ;
85138 _output . WriteLine ( $ "***missing method: { missing } ") ;
0 commit comments