Как выполнить модульное тестирование модели в .net core 2.0? Я не понимаю, что передать классу Homecontroller в классе модульного тестирования. Это мой класс модульного тестирования, где мне нужна помощь
using BasicUnitTesting.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BasicUnitTesting.Controllers;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace BasicUnitTestProj
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void GetEmployeeTest()
{
HomeController home = new HomeController(null); //What should i pass to HomeController
var vr = home.GetEmployee() as ViewResult;
List<Employee> expectedemps = new List<Employee>()
{
new Employee() {EmpID=101,EmpName="Abhilash",Salary=50000},
new Employee() {EmpID=102,EmpName="Abhishek",Salary=60000},
new Employee() {EmpID=103,EmpName="Nagraj",Salary=30000},
new Employee() {EmpID=104,EmpName="Sunil",Salary=50000},
new Employee() {EmpID=105,EmpName="Vinay",Salary=40000}
};
Assert.IsTrue(expectedemps.SequenceEqual(vr.Model as List<Employee>));
}
}
}
Ниже мой HomeController
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BasicUnitTesting.Models;
namespace BasicUnitTesting.Controllers
{
public class HomeController : Controller
{
private readonly CompanyDbContext _context
public HomeController(CompanyDbContext context)
{
_context = context;
}
public IActionResult Index()
{
return View("Index");
}
public IActionResult GetEmployee()
{
//CompanyDbContext Db = new CompanyDbContext();
//List<Employee> emps = Db.Employees.ToList();
List<Employee> emps = _context.Employees.ToList();
return View(emps);
}
}
}
Моя модель и класс Context следующие:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace BasicUnitTesting.Models
{
public class Employee
{
[Key]
public int EmpID { get; set; }
public string EmpName { get; set; }
public decimal Salary { get; set; }
}
public class CompanyDbContext:DbContext
{
public CompanyDbContext()
{
}
public CompanyDbContext(DbContextOptions<CompanyDbContext> options) : base(options)
{
}
public DbSet<Employee> Employees { get; set; }
}
}