asp.net mvc - How to prevent database effect in C# MVC Unit testing? -


when applying unit testing on insert, update , delete operation. @ time record inserted, updated , deleted in database well.

how possible? can give solution prevent database effect?

thanks,

ideally should using mocking scenarios db interaction there. make sure have separate out db interaction logic , interface driven. can create mock objects, wherein define expectation of db interaction interfaces. example, if example insertsomething() method called, should returned method? , on. sharing links on details unit testing , mocking.

https://msdn.microsoft.com/en-us/library/ff650441.aspx

https://github.com/moq/moq4

http://www.developerhandbook.com/unit-testing/writing-unit-tests-with-nunit-and-moq/

testing mvc controller fails null reference exception

as option, can go separate real database testing purpose, if essential execute tests against database. can also, execute sql script @ start , after running test seed , clean data respectively keep database pristine


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -