Specify icon indicating copy to clipboard operation
Specify copied to clipboard

Failing test for resolving a class from the container

Open shaynevanasperen opened this issue 7 years ago • 1 comments

This is some code which demonstrates the problem described in https://github.com/mwhelan/Specify/issues/23

shaynevanasperen avatar Jul 06 '17 16:07 shaynevanasperen

I have now separated out the strategies for creating concrete classes in the TinyMockingContainer, which provides the behaviour required for your test to pass. The IoC container is configured to create concrete classes that aren't registered.

  1. If all the constructor parameters are reference types then I register mocks of them into the container using the mocking framework, as before
  2. If any of the parameters are value types I'm just creating the concrete class with the mocking framework. This means the result is consistent with what you would get if your did your example test natively with a mocking framework, like this:
[Test]
public void TestClass()
{
    string result;
    var sub = Substitute.For<Foo>();
    sub.Bar.Returns("Bar");
    var sut = new Subject();

    result = sut.DoSomethingWithClass(sub);
    result.Should().Be(sub.Bar);
}

I want to make sure this is consistent with what you've done around dependency chains, which I'm not totally clear on after being away from things for awhile.

If it is, we also have to make sure it is consistent in the Autofac Container

mwhelan avatar Jul 09 '17 05:07 mwhelan