Created
June 28, 2022 18:04
-
-
Save webartoli/62a03bcfbb84e76ddb8a8ee2614e5f92 to your computer and use it in GitHub Desktop.
Init Db with Xunit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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