0

I've got following integration test for a repository:

public class RepositoryTests
{
    [Fact]
    public async Task GetAllAdressen_ReturnsEntities_OK_Test()
    {
        await GetAll_ReturnsEntities_OK_Test<AdresseEntity>();
    }

    [Fact]
    public async Task GetAllApplikationsarten_ReturnsEntities_OK_Test()
    {
        await GetAll_ReturnsEntities_OK_Test<ApplikationsartEntity>();
    }

    private static async Task GetAll_ReturnsEntities_OK_Test<TEntity>()
        where TEntity : BaseEntity
    {
        // Arrange
        var dbContext = new SaiTestContext();
        var repository = new Repository<TEntity>(dbContext);

        // Act
        var entities = await repository.GetAllAsync();

        // Assert
        Assert.NotEmpty(entities);
    }
}

Is there a way to remove both [Fact] and convert the private static async Task GetAll_ReturnsEntities_OK_Test<TEntity>() into a [Theory] while specifying TEntity somehow with InlineData?

Philippe
  • 1,949
  • 4
  • 31
  • 57
  • `Theory` passes parameters to test at runtime, generic types are resolved at compile time, how do you want to achieve it? Passing `Type` instance seems to be an ugly workaround – Pavel Anikhouski May 29 '20 at 07:58
  • 1
    @PavelAnikhouski Thanks, it probably would but the additional effort is not worth the gain. I'll keep it as it is. – Philippe May 29 '20 at 08:06

0 Answers0