Skip to content

Instantly share code, notes, and snippets.

@nth-commit
Created March 26, 2021 01:18
Show Gist options
  • Save nth-commit/549b389cfe0bfb6c03cd463f8e202ceb to your computer and use it in GitHub Desktop.
Save nth-commit/549b389cfe0bfb6c03cd463f8e202ceb to your computer and use it in GitHub Desktop.
public class MyTest : IClassFixture<MyTest.Fixture>
{
// Somehow this thing is in scope, as well as the values that come out of it. Also somehow, the generated values gets into the fixture.
public static readonly IGen<List<Person>> Users = Gen.Type<Person>();
private readonly Fixture _fixture;
public MyTest(Fixture fixture)
{
_fixture = fixture;
}
[Property]
public void SomethingAboutUsers()
{
// Can access _fixture.Users or whatever
}
[Property]
public IGen<Test> SomethingAboutUsers() =>
from nonExistentUserId in Gen.Guid()
select Property.ForThese(() =>
{
// Can access _fixture.Users or whatever, and they are the same users as the other test (one insert)
// Can also generate your own stuff local to the test which won't be shared.
});
private class Fixture : IAsyncLifetime
{
public Task InitializeAsync()
{
// Insert all the users
return Task.CompletedTask;
}
public Task DisposeAsync() => Task.CompletedTask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment