Skip to content

Classes can't be resolved from the container the same way that interfaces can #23

@shaynevanasperen

Description

@shaynevanasperen

Given code like this:

public interface IFoo
{
	string Bar { get; }
}

public class Foo
{
	public virtual string Bar { get; }
}

public class Subject
{
	public string DoSomethingWithInterface(IFoo foo)
	{
		return foo.Bar;
	}

	public string DoSomethingWithClass(Foo foo)
	{
		return foo.Bar;
	}
}

public class TestInterface : ScenarioFor<Subject>
{
	string _result;

	void GivenAFooWithBar() => The<IFoo>().Bar.Returns("Bar");
	void WhenDoingSomething() => _result = SUT.DoSomethingWithInterface(The<IFoo>());
	void ThenTheResultIsBar() => _result.Should().Be(The<IFoo>().Bar);
}

public class TestClass : ScenarioFor<Subject>
{
	string _result;

	void GivenAFooWithBar() => The<Foo>().Bar.Returns("Bar");
	void WhenDoingSomething() => _result = SUT.DoSomethingWithClass(The<Foo>());
	void ThenTheResultIsBar() => _result.Should().Be(The<Foo>().Bar);
}

The second test fails on the line GivenAFooWithBar(). It should work the same as with the interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions