public CommandAPIControllerTests() { optionsBuilder = new DbContextOptionsBuilder <CommandAPIContext>(); optionsBuilder.UseInMemoryDatabase("UnitTestInMemDB"); dbContext = new CommandAPIContext(optionsBuilder.Options); //create an instance of controller passing the dbContext created controller = new CommandAPIController(dbContext); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CommandAPIContext context) { context.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers();//for our endpoints specified //within configure services method // endpoints.MapGet("/", async context => // { // await context.Response.WriteAsync("Hello World!"); // }); }); }
//dependency injected value // public CommandAPIController(ICommandAPIRepo repo) // { // _repo = repo; // } public CommandAPIController(CommandAPIContext ctx) { _context = ctx; }
public DbCommandAPIRepo(CommandAPIContext ctx) { _context = ctx; }