Skip to content

Testing library for autofac modules

License

Notifications You must be signed in to change notification settings

Romfos/Testing.Autofac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing.Autofac

Small testing library for autofac modules

.github/workflows/verify.yml

Testing.Autofac.NSubstitute
Testing.Autofac.Moq

Nuget

NSubstitute: https://www.nuget.org/packages/Testing.Autofac.NSubstitute/

Moq: https://www.nuget.org/packages/Testing.Autofac.Moq/

Usage

  1. Create TestContainerBuilder
  2. Register autofac modules
  3. Register mocks (NSubstitute or Moq)
  4. Resolve test services

Usage example (NSubstitute)

[TestMethod]
public void ExampleTest()
{
    // arrange
    new TestContainerBuilder()
        .Module<TestModule>()
        .Mock(out IBar bar)
        .Resolve(out IFoo underTest);

    bar.Value().Returns(2);

    // act
    var actual = underTest.Add(1);

    // assert
    Assert.AreEqual(3, actual);
}