@@ -24,6 +24,13 @@ public void Initialize()
2424 DbSettingMapper . Add < ClassHandlerForEntityWithAttributeConnection > ( new CustomDbSetting ( ) , true ) ;
2525 DbHelperMapper . Add < ClassHandlerForEntityWithAttributeConnection > ( new CustomDbHelper ( ) , true ) ;
2626 StatementBuilderMapper . Add < ClassHandlerForEntityWithAttributeConnection > ( new CustomStatementBuilder ( ) , true ) ;
27+
28+ #if NET7_0_OR_GREATER
29+ // For Generic Attributed Entity
30+ DbSettingMapper . Add < ClassHandlerForEntityWithGenericAttributeConnection > ( new CustomDbSetting ( ) , true ) ;
31+ DbHelperMapper . Add < ClassHandlerForEntityWithGenericAttributeConnection > ( new CustomDbHelper ( ) , true ) ;
32+ StatementBuilderMapper . Add < ClassHandlerForEntityWithGenericAttributeConnection > ( new CustomStatementBuilder ( ) , true ) ;
33+ #endif
2734 }
2835
2936 [ TestCleanup ]
@@ -73,7 +80,28 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
7380 return reader ;
7481 }
7582 }
83+
84+ #if NET7_0_OR_GREATER
85+ private class ClassHandlerForEntityWithGenericAttributeConnection : CustomDbConnection
86+ {
87+ protected override DbCommand CreateDbCommand ( )
88+ {
89+ return new ClassHandlerForEntityWithGenericAttributeDbCommand ( ) ;
90+ }
91+ }
7692
93+ private class ClassHandlerForEntityWithGenericAttributeDbCommand : CustomDbCommand
94+ {
95+ protected override DbDataReader ExecuteDbDataReader ( CommandBehavior behavior )
96+ {
97+ var reader = new DataEntityDataReader < ClassHandlerTestClassWithGenericAttribute > ( new [ ]
98+ {
99+ new ClassHandlerTestClassWithGenericAttribute { Id = 1 , Name = "James Doe" }
100+ } ) ;
101+ return reader ;
102+ }
103+ }
104+ #endif
77105 #endregion
78106
79107 #region ClassHandlers
@@ -103,6 +131,21 @@ public ClassHandlerTestClassWithAttribute Set(ClassHandlerTestClassWithAttribute
103131 return entity ;
104132 }
105133 }
134+
135+ #if NET7_0_OR_GREATER
136+ public class TestClassHandlerForEntityWithGenericAttribute : IClassHandler < ClassHandlerTestClassWithGenericAttribute >
137+ {
138+ public ClassHandlerTestClassWithGenericAttribute Get ( ClassHandlerTestClassWithGenericAttribute entity , ClassHandlerGetOptions options )
139+ {
140+ return entity ;
141+ }
142+
143+ public ClassHandlerTestClassWithGenericAttribute Set ( ClassHandlerTestClassWithGenericAttribute entity , ClassHandlerSetOptions options )
144+ {
145+ return entity ;
146+ }
147+ }
148+ #endif
106149
107150 #endregion
108151
@@ -120,7 +163,15 @@ public class ClassHandlerTestClassWithAttribute
120163 public int Id { get ; set ; }
121164 public string Name { get ; set ; }
122165 }
123-
166+
167+ #if NET7_0_OR_GREATER
168+ [ ClassHandler < TestClassHandlerForEntityWithGenericAttribute > ]
169+ public class ClassHandlerTestClassWithGenericAttribute
170+ {
171+ public int Id { get ; set ; }
172+ public string Name { get ; set ; }
173+ }
174+ #endif
124175 #endregion
125176
126177 #region Methods
@@ -162,7 +213,27 @@ public void TestClassHandlerPrecedenceWithAttribute()
162213 // Assert
163214 classHandler . Verify ( c => c . Get ( It . IsAny < ClassHandlerTestClassWithAttribute > ( ) , It . IsAny < ClassHandlerGetOptions > ( ) ) , Times . Never ) ;
164215 }
216+
217+ #if NET7_0_OR_GREATER
218+ [ TestMethod ]
219+ public void TestClassHandlerPrecedenceWithGenericAttribute ( )
220+ {
221+ // Prepare
222+ var classHandler = new Mock < IClassHandler < ClassHandlerTestClassWithGenericAttribute > > ( ) ;
223+ FluentMapper
224+ . Entity < ClassHandlerTestClassWithGenericAttribute > ( )
225+ . ClassHandler ( classHandler . Object ) ;
165226
227+ // Act
228+ using ( var connection = new ClassHandlerForEntityWithGenericAttributeConnection ( ) )
229+ {
230+ var result = connection . QueryAll < ClassHandlerTestClassWithGenericAttribute > ( ) ;
231+ }
232+
233+ // Assert
234+ classHandler . Verify ( c => c . Get ( It . IsAny < ClassHandlerTestClassWithGenericAttribute > ( ) , It . IsAny < ClassHandlerGetOptions > ( ) ) , Times . Never ) ;
235+ }
236+ #endif
166237 #endregion
167238 }
168239}
0 commit comments