Sai Avinash
Sai Avinash

Reputation: 4753

how to test controllers that add/update/delete database in asp.net mvc using Moq

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

Upvotes: 0

Views: 893

Answers (1)

Thomas Weller
Thomas Weller

Reputation: 11717

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...).

Upvotes: 1

Related Questions