[Collection("Integration Tests")]
Унаследуйте все четыре класса от BaseTest
, реализуйте интерфейс IClassFixture
и приведите операторы using
к показанному далее виду:
// CarTests.cs
using System.Collections.Generic;
using System.Linq;
using AutoLot.Dal.Exceptions;
using AutoLot.Dal.Repos;
using AutoLot.Dal.Tests.Base;
using AutoLot.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;
using Xunit;
namespace AutoLot.Dal.Tests.IntegrationTests
{
[Collection("Integation Tests")]
public class CarTests : BaseTest,
IClassFixture
{
}
}
// CustomerTests.cs
using System.Collections.Generic;
using System;
using System.Linq;
using System.Linq.Expressions;
using AutoLot.Dal.Tests.Base;
using AutoLot.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace AutoLot.Dal.Tests.IntegrationTests
{
[Collection("Integation Tests")]
public class CustomerTests : BaseTest,
IClassFixture
{
}
}
// MakeTests.cs
using System.Linq;
using AutoLot.Dal.Repos;
using AutoLot.Dal.Repos.Interfaces;
using AutoLot.Dal.Tests.Base;
using AutoLot.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Xunit;
namespace AutoLot.Dal.Tests.IntegrationTests
{
[Collection("Integation Tests")]
public class MakeTests : BaseTest,
IClassFixture
{
}
}
// OrderTests.cs
using System.Linq;
using AutoLot.Dal.Repos;
using AutoLot.Dal.Repos.Interfaces;
using AutoLot.Dal.Tests.Base;
using Microsoft.EntityFrameworkCore;
using Xunit;
namespace AutoLot.Dal.Tests.IntegrationTests
{
[Collection("Integation Tests")]
public class OrderTests : BaseTest,
IClassFixture
{
}
}
Добавьте в класс MakeTests
конструктор, который создает экземпляр MakeRepo
и присваивает его закрытой переменной readonly
уровня класса. Переопределите метод Dispose()
и освободите в нем экземпляр MakeRepo
:
[Collection("Integration Tests")]
public class MakeTests : BaseTest,
IClassFixture
{
private readonly IMakeRepo _repo;
public MakeTests()
{
_repo = new MakeRepo(Context);
}
public override void Dispose()
{
_repo.Dispose();
}
...
}
Повторите те же действия для класса OrderTests
, но с использованием OrderRepo
вместо MakeRepo
:
[Collection("Integration Tests")]
public class OrderTests : BaseTest,
IClassFixture
{
private readonly IOrderRepo _repo;
public OrderTests()
{
_repo = new OrderRepo(Context);
}
public override void Dispose()
{
_repo.Dispose();
}
...
}
Тестовые методы [Fact] и [Theory]