Skip to content

Instantly share code, notes, and snippets.

@webartoli
Created June 28, 2022 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webartoli/62a03bcfbb84e76ddb8a8ee2614e5f92 to your computer and use it in GitHub Desktop.
Save webartoli/62a03bcfbb84e76ddb8a8ee2614e5f92 to your computer and use it in GitHub Desktop.
Init Db with Xunit
public class InMemoryDbInstance
{
public InMemoryDbInstance()
{
Data = "";
}
public string Data { get; set; }
}
public class InitializedDb
{
private readonly InMemoryDbInstance _db;
public string Data => _db.Data;
public InitializedDb()
{
_db = new InMemoryDbInstance
{
Data = "Claudio"
};
}
}
[CollectionDefinition("InitializedDb")]
public class DatabaseCollection : ICollectionFixture<InitializedDb>
{
}
[Collection("InitializedDb")]
public class TestClass1
{
private readonly InitializedDb _db;
public TestClass1(InitializedDb db)
{
_db = db;
}
[Fact]
public void Test()
{
Assert.Equal("Claudio", _db.Data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment