Я пытаюсь запустить тест на репозитории Controller 'PeoppleRepositoryController.cs.Я получаю приведенную ниже ошибку и не могу понять, на что именно она жалуется.Может кто-нибудь объяснить, что мне нужно сделать, чтобы решить эту проблему?
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService (IServiceProvider sp, тип Type, тип requiredBy, bool isDefaultParameterRequired)
Полный след стека можно увидеть на изображении ниже:
Контроллер:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Personkartotek.DAL;
using Personkartotek.Models;
using Personkartotek.Persistence;
namespace Personkartotek.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PeopleRepositoryController : ControllerBase
{
private readonly IUnitOfWork _uoWork;
public PeopleRepositoryController(IUnitOfWork uoWork)
{
_uoWork = uoWork;
}
// GET: api/PeopleRepository
[HttpGet]
public IEnumerable<Person> GetPersons()
{
return _uoWork._People.GetAll();
}
// GET: api/PeopleRepository/5
[HttpGet("{id}")]
public async Task<IActionResult> GetPerson([FromRoute] int id)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var person = _uoWork._People.Get(id);
if (person == null)
{
return NotFound();
}
return Ok(person);
}
//GET: api/PeopleRepository/
[HttpGet("AtAdr/{id}")]
public IActionResult GetPersonsResidingAtAddress([FromRoute] int AddressId)
{
var ResidingPersons = _uoWork._People.GetAllPersonsById(AddressId);
return Ok(ResidingPersons);
}
// PUT: api/PeopleRepository/5
[HttpPut("{id}")]
public async Task<IActionResult> PutPerson([FromRoute] int id, [FromBody] Person person)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != person.PersonId)
{
return BadRequest();
}
if (!PersonExists(id))
{
return NotFound();
}
_uoWork._People.Put(person);
return NoContent();
}
// POST: api/PeopleRepository
[HttpPost]
public async Task<IActionResult> PostPerson([FromBody] Person person)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_uoWork._People.Add(person);
_uoWork.Complete();
return CreatedAtAction("GetPerson", new { id = person.PersonId }, person);
}
// DELETE: api/PeopleRepository/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeletePerson([FromRoute] int id)
{
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}
var person = _uoWork._People.Get(id);
if (person == null) {
return NotFound();
}
_uoWork._People.Remove(person);
_uoWork.Complete();
return Ok(person);
}
private bool PersonExists(int id)
{
return _uoWork.Exist(id);
}
}
}
Файл IUnitOfWork:
using Personkartotek.DAL.IRepositories;
namespace Personkartotek.DAL
{
public interface IUnitOfWork : IDisposable
{
IPeopleRepository _People { get; }
int Complete();
bool Exist(int id);
}
}
Мой запуск.Настройки файла CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Personkartotek.DAL;
using Personkartotek.Models.Context;
using Personkartotek.Persistence;
using Swashbuckle.AspNetCore.Swagger;
namespace Personkartotek
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ModelsContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("PersonkartotekDB")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}