2016-05-01 7 views
4

Nach dem FakeItEasy Tutorial here die WithArgumentsForConstructor() Erweiterung Methode ist die Klasse Konstruktor nicht nennen:WithArgumentsForConstructor() Erweiterungsmethode ruft Konstruktor

// Specifying arguments for constructor using expression. This is refactoring friendly! 
// The constructor seen here is never actually invoked. It is an expression and it's purpose 
// is purely to communicate the constructor arguments which will be extracted from it 
var foo = A.Fake<FooClass>(x => x.WithArgumentsForConstructor(() => new FooClass("foo", "bar"))); 

jedoch der Haltepunkt in meiner Person Klasse Konstruktor wird unten in meinem Test ausgelöst. Wie das? Verwende ich WithArgumentsForConstructor() falsch?

[Test] 
public void Constructor_With_Arguments() 
{ 
    var driver = A.Fake<Person>(x => x.WithArgumentsForConstructor(() => new Person("Jane", 42))); 
    var age = driver.GetAge(); 
    Assert.AreEqual(42, age); 
} 

Stapelüberwachung:

MyStuff.Tests.Domain.dll!MyStuff.Tests.Domain.Driver.Person(string name, int age) Line 61 C# 
DynamicProxyGenAssembly2!Castle.Proxies.DriverProxy.DriverProxy(Castle.DynamicProxy.IInterceptor[] value, string value, int value) Unknown 
[Native to Managed Transition] 
[Managed to Native Transition] 
mscorlib.dll!System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, ref System.Threading.StackCrawlMark stackMark) Unknown 
mscorlib.dll!System.Activator.CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes) Unknown 
mscorlib.dll!System.Activator.CreateInstance(System.Type type, object[] args) Unknown 
FakeItEasy.dll!Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) Unknown 
FakeItEasy.dll!Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, Castle.DynamicProxy.IInterceptor[] interceptors) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.GenerateClassProxy(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, Castle.DynamicProxy.IInterceptor interceptor, System.Collections.Generic.IEnumerable<System.Type> allInterfacesToImplement) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.DoGenerateProxy(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<System.Type> additionalInterfacesToImplement, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, Castle.DynamicProxy.IInterceptor interceptor) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.CreateProxyGeneratorResult(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<System.Type> additionalInterfacesToImplement, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, FakeItEasy.Core.IFakeCallProcessorProvider fakeCallProcessorProvider) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.GenerateProxy(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<System.Type> additionalInterfacesToImplement, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, FakeItEasy.Core.IFakeCallProcessorProvider fakeCallProcessorProvider) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.GenerateProxy(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<System.Type> additionalInterfacesToImplement, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder> customAttributeBuilders, FakeItEasy.Core.IFakeCallProcessorProvider fakeCallProcessorProvider) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.ProxyGeneratorSelector.GenerateProxy(System.Type typeOfProxy, System.Collections.Generic.IEnumerable<System.Type> additionalInterfacesToImplement, System.Collections.Generic.IEnumerable<object> argumentsForConstructor, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder> customAttributeBuilders, FakeItEasy.Core.IFakeCallProcessorProvider fakeCallProcessorProvider) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.FakeObjectCreator.GenerateProxy(System.Type typeOfFake, FakeItEasy.Creation.FakeOptions fakeOptions, System.Collections.Generic.IEnumerable<object> argumentsForConstructor) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.FakeObjectCreator.CreateFake(System.Type typeOfFake, FakeItEasy.Creation.FakeOptions fakeOptions, FakeItEasy.Creation.IDummyValueCreationSession session, bool throwOnFailure) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake(System.Type typeOfFake, FakeItEasy.Creation.FakeOptions options) Unknown 
FakeItEasy.dll!FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake<SysSurge.DynMock.Tests.Domain.Driver>(System.Action<FakeItEasy.Creation.IFakeOptionsBuilder<SysSurge.DynMock.Tests.Domain.Driver>> options) Unknown 

...

Antwort

3

Sie es richtig verwenden.

Aber Sie verstehen es falsch.

// The constructor seen here is never actually invoked... 

Es bedeutet, dass es nicht den Konstruktor genau an dieser Stelle nennen. Es wird diesen Ausdruck analysieren und die Parameter verwenden, um den Konstruktor irgendwo im Inneren aufzurufen. Aber wird es den Konstruktor aufrufen.

Sie können dies überprüfen, um den Haltepunkt direkt in den Ausdruck einzufügen.