0

I am working on an asp.net mvc application.

I am using Repository pattern . I was unsure of how to test the controller methods that makes add/edit/delete operations.

How ever , i am mocking the database dependencies by using moq library.

Please suggest how to test the above operations.

Note : here , the delete operation is not actual delete , but it is soft delete , which means that , the status of the entity will be made be 0 from 1

1 Answer 1

1

It all depends on what you want to test:

  1. Pure unit tests for the controller: Then you will mock your repositories and verify that you made the expected calls.
  2. Testing the entire db logic from the controller downwards in one go: Then you will have to create a test database and point your data access code to it in your test project.

Your question suggests that the first proposal might be nearer to what you intend. However, it is not totally clear to me (e.g. whether a DELETE operation is hard or soft would be irrelevant if you're mocking the repository...).

Sign up to request clarification or add additional context in comments.

5 Comments

@Thomas..I agree with you..can you please give one example of how to test Db methods using test database. what does the test database exactly mean?
What do you agree with? I gave you two options: Do you want to mock the repository - then you'll need Moq and no db. Or do you want to test the entire thing - then you'll need a test db and no Moq.
@thomas..i am currently following first approach. is it possible to test Db methods apart from controller/
@Thomas..what i mean to say is testing repositories using test database
Huh? If you want to test repositories why then you need controllers? What's stopping you from writing tests against the repositories directly? E.g. using NDbUnit would be one possible option in that scenario along the lines that were outlined (here)[geekswithblogs.net/thomasweller/archive/2011/11/10/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.