0

I currently use using (TransactionScope scope = new TransactionScope()) for c# testing database insertion so that it doesn't actually save into database for unit testing. But for system testing which I am currently testing on different server to test the status code for different scenarios. Each time I run the test, it is actually saving data into database and next time I ran the test it is failing as it is duplicate record. I tried to use transaction scope , but doesn't seem to work. Please help.

sandy
  • 307
  • 2
  • 3
  • 7
  • Don't use the database for testing. It is a singleton, instead, try abstracting away the database, possibly using Entity Framework, and then using a testing Fake, for example, EF In Memory database, or SQLite. – Aron Nov 27 '18 at 10:37
  • The best way is to make a copy of the database. So first take current database and de-attach, otherwise, you cannot make copy. Then locate mdf file and copy. Then attach the original database. Rename the copy for testing and attach the copy. Then for testing all you have to do is add a USE statement to indicate if you are using the original or the copy of the database. Or you can change the connection string to use a different default database. – jdweng Nov 27 '18 at 10:41
  • Thanks @jdweng and Aron. But I am connecting to the endpoint using certificate and bearer token using the client.postAsync. can I still Fake / make a copy of database ? sorry I am doing system testing for the first time.Bit confused on how it works. – sandy Nov 27 '18 at 11:05
  • What type database are you using? With SQL Server you have a connection to the Server. The server can have multiple databases. So the certificate is for the connection to the server. – jdweng Nov 27 '18 at 11:09
  • we are using oracle – sandy Nov 27 '18 at 11:28

0 Answers0