I have tried your step by step guide, i'm struck with implementing repository which not resolving on my test? Kindly help...
Please help as soon as you can.. so my team start our work as planned...
8 Answer(s)
-
0
Hi,
Which version do you use ? Is it angular2 template ? Do you have an error message ? If so, please share the error message or a screenshot.
Thanks.
-
0
I'm using MVC and Jquery version. I'm not getting any error message, but my test fails due to the fact the repository is not pulling the data from the table that I mentioned. When I used DbContext to pull records from that table it works fine. Not sure what I'm missing. Your immediate help is highly appreciated.
Thanks, Rajesh
-
0
Update:
I'm able to get the data from Controller -> App Service -> Repository with no issues.
I'm unable to get the data from Test -> App Service -> Repository.
_customerAppService = Resolve<ICustomerAppService>();
The above is what I think causing the problem. Let me know how can I resolve this.
-
0
Hi,
What is the value of _customerAppService when you debu it ? Do you have an exception or does it have a value ?
By the way, do you have any seed data for customer ? If not, in unit tests you might not get any data.
-
0
I noticed that all the DbSet inside context that came with the solutions and the one's i created doesn't pull data using the repository. This happens when I run the tests. I can able to render the data in the UI when run the website on the browser.
I'm not sure what I missing to make my test work. This is blocking my test driven development at this time.
Any help is highly appreciated.
Thanks
-
0
Hi @raajeshb,
Maybe I understand you wrong. Currently, in unit tests your real database is not used. Do you want to get data from your real database in unit tests ?
-
0
Yes
-
0
Hi,
In AspNet Zero, we use an in-memory database using this great library <a class="postlink" href="https://github.com/tamasflamich/effort">https://github.com/tamasflamich/effort</a>. We suggest you to move on this way.
It means, in each unit test,
- ARRANGE: create the data you need, insert using repository or directly to dbContext. This will not be saved to your real database.
- ACT: make the action for your test. (For example delete a record).
- ASSERT: Check the result of your action and see if it passes or fails.
I suggest you to read this short article about unit testing which is also valid for AspNet Zero <a class="postlink" href="https://www.codeproject.com/articles/871786/unit-testing-in-csharp-using-xunit-entity-framewor">https://www.codeproject.com/articles/87 ... y-framewor</a>.
At the end, if you want to use your real database, we can take a look at it.
Thanks.