我有一个 XUnit 项目,它引用并测试另一个项目的 API 端点方法。但是,当我运行测试时,出现以下错误:
A test class may only define a single public constructor.
Run Code Online (Sandbox Code Playgroud)
还没有找到太多关于这个问题可能意味着什么的信息,但我将提供下面的代码示例。任何帮助是极大的赞赏。
APIControllerTest.cs
using System;
using System.Collections.Generic;
using AppointmentAPI.Controllers;
using AppointmentAPI.Appt_Models;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace AppointmentAPITests
{
public class APIControllerTests
{
#region Seeding
protected APIControllerTests(DbContextOptions<ApptSystemContext> contextOptions)
{
ContextOptions = contextOptions;
Seed();
}
protected DbContextOptions<ApptSystemContext> ContextOptions { get; }
private void Seed()
{
using (var context = new ApptSystemContext(ContextOptions))
{
// this ensures that a fresh in-memory db is used for each test
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var …
Run Code Online (Sandbox Code Playgroud)