Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Inconsistent semantics around Create in Autofac.Extras.FakeItEasy #431

Closed
alexmg opened this Issue Jan 22, 2014 · 5 comments

Comments

Projects
None yet
1 participant
Contributor

alexmg commented Jan 22, 2014

From adam.ra...@gmail.com on May 13, 2013 21:38:29

[Fact]
public void Autofake_self_test_OK()
{
using (var fake = new AutoFake())
{
Assert.Same(fake.Create(), fake.Create());
}
}

[Fact]
public void Autofake_self_test_Fails()
{
    using (var fake = new AutoFake())
    {                        
        Assert.Same(fake.Create<Calculator>(), fake.Create<Calculator>());
    }
}

If Calculator is non-abstract, the second test fails. This is because the call to Create() for a interface or abstract class returns a fake, but the call to Create() for a concrete type returns a concrete instance. The container is configured to return the same instance each time for a fake but a new instance each time for a concrete.

The API should change and these two behaviours should exist on separate methods with names which communicate the correct semantics

Original issue: http://code.google.com/p/autofac/issues/detail?id=431

Contributor

alexmg commented Jan 22, 2014

From JSzumi...@gmail.com on May 13, 2013 05:11:34

I expected that fake.Create<> always creates new instance, but fake.Container.Resolve<> always returns the same instance (because of my other assumption: all fakes inside using statement are in the same lifetime scope of the Container).

I suggest use fake.Create<> for new instances and fake.Resolve<> for the same (for a shorter writing).

Contributor

alexmg commented Jan 22, 2014

From travis.illig on May 13, 2013 17:48:29

Labels: Module-Extras-FakeItEasy

Contributor

alexmg commented Jan 22, 2014

From a...@adamralph.com on November 09, 2013 03:45:58

I've pushed a change for this to my fork on the 'fie' branch - https://code.google.com/r/adam-autofac/source/browse/?name=fie The changes are:

  • The Create() method is obsolete and replaced with Resolve().
  • The default behaviour is instance-per-lifetime-scope for all types. I.e. within the using block, any resolution to a given type yields the same instance
  • The AutoFake constructor has a the container builder as an optional parameter which allows the consumer to fully customise the registration before creating the AutoFake, e.g. resolution for a given type can be changed to instance per dependency, etc.
Contributor

alexmg commented Jan 22, 2014

From travis.illig on November 11, 2013 13:41:47

I'll take a look at this and see about pulling those changes in.

Summary: Inconsistent semantics around Create in Autofac.Extras.FakeItEasy (was: inconsistent semantics around Create in Autofac.Extras.FakeItEasy)
Owner: travis.illig

Contributor

alexmg commented Jan 22, 2014

From alex.meyergleaves on November 12, 2013 04:24:06

This issue was closed by revision 1fea0f29c7e7 .

Status: Fixed

@alexmg alexmg closed this Jan 22, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment