twsl / xunit.MySql

Easy unit testing integration for MySql with support for real queries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xunit.MySql

CI Version Downloads license

Easy unit testing integration for MySql with support for real queries using the Entity Framework Core provider for MySql. It is not the fastest nor the prettiest solution, but it integrates stumpdk's MySql.Server adequately into xunit. While testing, the library spins up a local MySql instance and cleans up afterwards.

Disclaimer

This is no official package, I just used the Xunit.* namespace to hightlight, that this is an extension highly depending on that project. Even though this package targets .NET Standard, it currently only works on Windows due to the supplied MySql binaries.

The usage of MySql is covered by The Universal FOSS Exception.

License

License

Prepare unit tests

Install the latest version of the ef tool with:

dotnet tool install --global dotnet-ef --version 3.1.6

Or update an existing version with:

dotnet tool update --global dotnet-ef

Then execute the following command from the xunit.MySql.Tests directory:

dotnet ef migrations add Init -v --context TestDbContext

Example

public class SimpleFixture : DatabaseFixture<DbContext, MySqlServiceV8<Version_8_0_12>>
{
    public SimpleFixture()
    {
        // Context.ModelName.Add...
        Context.SaveChanges();
    }
}
public class SimpleQueryTest : IClassFixture<SimpleFixture>
{
    private readonly SimpleFixture _fixture;

    public SimpleQueryTest(SimpleFixture fixture)
    {
        _fixture = fixture;
    }

    [Fact]
    public void TestAllElements()
    {
        var list = _fixture.Context.ModelName.ToList();
        Assert.NotNull(list);
    }
}

About

Easy unit testing integration for MySql with support for real queries

License:MIT License


Languages

Language:C# 100.0%