Skip to content

Instantly share code, notes, and snippets.

@chsami
Created November 14, 2019 15:32
Show Gist options
  • Select an option

  • Save chsami/7a35f9dc2d02e48e0f5e357421495f64 to your computer and use it in GitHub Desktop.

Select an option

Save chsami/7a35f9dc2d02e48e0f5e357421495f64 to your computer and use it in GitHub Desktop.
[TestClass]
public abstract class BaseTest
{
public static ServiceProvider serviceProvider;
public IMyService _myService;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
IServiceCollection services = new ServiceCollection();
services.AddTransient<IMyService, MyService>();
//build services
serviceProvider = services.BuildServiceProvider();
}
[TestInitialize]
public void InitializeTest()
{
//resolve services
_myService = serviceProvider.GetService<IMyService>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment