Skip to content

Acumatica/xunit.autofac

Repository files navigation

Build Status Nuget Package

About the project

This project contains an integration between xUnit and Autofac. It adds the support for the dependency injection (DI) into all xUnit entities such as test classes, fixtures, etc.

How to use

Install the NuGet package.

Install-Package xunit.autofac

In your testing project, add the following attribute to the AssemblyInfo.cs file.

[assembly: Xunit.Autofac.UseAutofacTestFramework]

Register your dependencies by adding Autofac modules to your testing project.

public class ServiceRegistration : Module
{
	protected override void Load(ContainerBuilder builder)
	{
		builder.Register(context => new MyService())
			.As<IMyService>()
			.InstancePerLifetimeScope();
	}
}

After that, you can use dependency injection in the test entities in your code.

public class TestClass
{
	private readonly IMyService _myService;

	public TestClass(IMyService myService)
	{
		_myService = myService; // this dependency will be injected automatically by Autofac
	}

	[Fact]
	public void Test()
	{
	}
}

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages