@@ -112,11 +112,12 @@ public async Task ProcessRecord_DatabaseInsertThrows_ReturnsFalse()
112112 }
113113
114114 [ TestMethod ]
115- public async Task ProcessRecord_PrimaryKeyViolation_ReturnsTrue ( )
115+ public async Task ProcessRecord_PrimaryKeyViolation_ReturnsFalse ( )
116116 {
117117 // Arrange
118118 var data = CreatePayload ( new { LanguageCodeId = "EN" , LanguageDescription = "English" } ) ;
119- var dbUpdateException = new DbUpdateException ( "An error occurred" , new Exception ( "Violation of PRIMARY KEY constraint" ) ) ;
119+ var sqlException = new SqlExceptionWithNumber ( 2627 ) ;
120+ var dbUpdateException = new DbUpdateException ( "An error occurred" , sqlException ) ;
120121
121122 var accessorMock = new Mock < IDataServiceAccessor < LanguageCode > > ( ) ;
122123 accessorMock . Setup ( a => a . InsertSingle ( It . IsAny < LanguageCode > ( ) ) ) . ThrowsAsync ( dbUpdateException ) ;
@@ -128,15 +129,16 @@ public async Task ProcessRecord_PrimaryKeyViolation_ReturnsTrue()
128129 var result = await _handler . ProcessRecord ( "LanguageCode" , data ) ;
129130
130131 // Assert
131- Assert . IsTrue ( result ) ;
132+ Assert . IsFalse ( result ) ;
132133 }
133134
134135 [ TestMethod ]
135- public async Task ProcessRecord_UniqueConstraintViolation_ReturnsTrue ( )
136+ public async Task ProcessRecord_UniqueConstraintViolation_ReturnsFalse ( )
136137 {
137138 // Arrange
138139 var data = CreatePayload ( new { GenderCode = "M" } ) ;
139- var dbUpdateException = new DbUpdateException ( "An error occurred" , new Exception ( "unique constraint violation on table" ) ) ;
140+ var sqlException = new SqlExceptionWithNumber ( 2601 ) ;
141+ var dbUpdateException = new DbUpdateException ( "An error occurred" , sqlException ) ;
140142
141143 var accessorMock = new Mock < IDataServiceAccessor < GenderMaster > > ( ) ;
142144 accessorMock . Setup ( a => a . InsertSingle ( It . IsAny < GenderMaster > ( ) ) ) . ThrowsAsync ( dbUpdateException ) ;
@@ -148,7 +150,7 @@ public async Task ProcessRecord_UniqueConstraintViolation_ReturnsTrue()
148150 var result = await _handler . ProcessRecord ( "GenderMaster" , data ) ;
149151
150152 // Assert
151- Assert . IsTrue ( result ) ;
153+ Assert . IsFalse ( result ) ;
152154 }
153155
154156 [ TestMethod ]
@@ -259,7 +261,7 @@ public async Task ProcessRecord_CaseInsensitiveDataType_ReturnsTrue()
259261 }
260262
261263 [ TestMethod ]
262- public async Task ProcessRecord_InsertSingleReturnsFalse_ReturnsTrue ( )
264+ public async Task ProcessRecord_InsertSingleReturnsFalse_ReturnsFalse ( )
263265 {
264266 // Arrange
265267 var data = CreatePayload ( new { GpPracticeCode = "Y99999" } ) ;
@@ -270,6 +272,11 @@ public async Task ProcessRecord_InsertSingleReturnsFalse_ReturnsTrue()
270272 var result = await _handler . ProcessRecord ( "BsSelectGpPractice" , data ) ;
271273
272274 // Assert
273- Assert . IsTrue ( result ) ;
275+ Assert . IsFalse ( result ) ;
274276 }
275277}
278+
279+ internal class SqlExceptionWithNumber ( int number ) : Exception ( $ "SQL error { number } ")
280+ {
281+ public int Number { get ; } = number ;
282+ }
0 commit comments