Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to do Unit Test with Dependency Injection .net Core 2

$
0
0

Hi

I start to develop a new web application, I create a Domain Object, Inteface, DAL and BLL...

I would like to test all before use that.

If I use the developed function in web application in .net core 2 I put in Startup.cs some code like this :

public void ConfigureServices(IServiceCollection services)

        {

            services.AddTransient<ITableOfTableRepository, DBTableOfTableRepository>();

            services.AddMvc();

            services.AddSingleton<IConfiguration>(Configuration);

        }

And in my Controller add this code 

 public class TablesController : Controller

    {

        private readonly ITableOfTableRepository _repository;

        public TablesController(ITableOfTableRepository repository)

        {

            this._repository = repository;

        }

How to do a UnitTest project for testing all before of the use in web application?

How to use dependency Injection in unit test?

BR


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>