Question: ** IF you do not know how to answer this question to not spam answer me like the last chegg expert . Let a chegg
** IF you do not know how to answer this question to not spam answer me like the last chegg "expert" . Let a chegg expert answer it who actually knows how to answer it
I need to learn how to write a Unit Test for a .NET CORE MVC . I'm using microsoft visual studios and using Xunit. I need to write a unit test to test a CONTROLLER in the mvc project.
CONTROLLER TO TEST IS CALLED "VendorAddControler.cs"
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using CS4790FinalProject3.Data; using CS4790FinalProject3.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore;
namespace CS4790FinalProject3.Controllers { public class VendorAddProductController : Controller { // get the database object private readonly ApplicationDbContext _db; //now add a constructor public VendorAddProductController(ApplicationDbContext db) { _db = db; } public IActionResult Index() { //NEEDS TO RETURN WHERE EQUAL TO SESSION return View(_db.Products.ToList()); }
public IActionResult Create() { return View(); } //post action for create [HttpPost] [ValidateAntiForgeryToken] public async Task
//Details : VendorAddProducts/Details/3 public async Task
//Edit : VendorAddProducts/Details/3 public async Task
//This will be for the post of Edit [HttpPost] [ValidateAntiForgeryToken] public async Task
//Details : VendorAddProducts/Details/3 //this is actually a get method public async Task
//POST : delete the book ->the action name os refering to the public asyn method of Delete at the bottom. it can be used if you want to call it something else [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public async Task
}
protected override void Dispose(bool disposing) { if (disposing) { _db.Dispose(); } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
