public static void ConfigureFakeOverridesCallsBaseMethods( MakesVirtualCallInConstructor fake) { "When specifying that a fake calls base methods followed by explicit configuration" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .CallsBaseMethods() .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)).Returns("a value from ConfigureFake")))); "Then it should behave as defined by the explicit configuration" .x(() => fake.VirtualMethod(null).Should().Be("a value from ConfigureFake")); }
public static void CallsBaseMethodsOverridesStrict( MakesVirtualCallInConstructor fake) { "When specifying a strict fake followed by specifying that the fake calls base methods" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Strict() .CallsBaseMethods())); "Then it should call the base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public void CallsBaseMethodsOverridesConfigureFake( MakesVirtualCallInConstructor fake) { "when ConfigureFake followed by CallsBaseMethods are used to configure a fake" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)).Returns("a value from ConfigureFake")) .CallsBaseMethods())); "it should call base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public static void CallsBaseMethodsOverridesConfigureFake( MakesVirtualCallInConstructor fake) { "When explicit configuration is followed by specifying that the fake calls base methods" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)).Returns("a value from ConfigureFake")) .CallsBaseMethods())); "Then it should call the base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public static void CallsBaseMethodsOverridesWrapping( MakesVirtualCallInConstructor fake) { "When a fake is configured to wrap an object followed by specifying that the fake calls base methods" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")) .CallsBaseMethods())); "Then it should call the base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public void CallsBaseMethodsOverridesWrapping( MakesVirtualCallInConstructor fake) { "when Wrapping followed by CallsBaseMethods are used to configure a fake" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")) .CallsBaseMethods())); "it should call base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public void CallsBaseMethodsOverridesStrict( MakesVirtualCallInConstructor fake) { "when Strict followed by CallsBaseMethods are used to configure a fake" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Strict() .CallsBaseMethods())); "it should call base method" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public static void CallsBaseMethodsDuringConstruction( MakesVirtualCallInConstructor fake) { "When specifying that a fake calls base methods" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options.CallsBaseMethods())); "Then it should call the base method during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("implementation value")); "And it should call base method after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public void CallsBaseMethodsDuringConstruction( MakesVirtualCallInConstructor fake) { "when CallsBaseMethods is used to configure a fake" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options.CallsBaseMethods())); "it should call base method during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("implementation value")); "it should call base method after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public static void MultipleConfigureFakeConfigurations( MakesVirtualCallInConstructor fake) { "When configuring a fake multiple times" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)).Returns("second value")) .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)).Returns("first value").Once()))); "Then it should apply each configuration in turn" .x(() => new[] { fake.VirtualMethodValueDuringConstructorCall, fake.VirtualMethod(null) } .Should().Equal("first value", "second value")); }
public static void ConfigureFakeDuringConstruction( MakesVirtualCallInConstructor fake) { "When configuring a fake during construction" .x(() => { fake = A.Fake<MakesVirtualCallInConstructor>( options => options.ConfigureFake( f => A.CallTo(() => f.VirtualMethod(A<string>._)) .Returns("configured value in fake options"))); }); "Then it should return the configured value during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake options")); "And it should return the configured value after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("configured value in fake options")); }
public void VirtualMethod( MakesVirtualCallInConstructor fake) { "when faking a class with a virtual method" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>()); "it should return a default value when the method is called during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be(string.Empty)); "it should return a default value when the method is called after the constructor" .x(() => fake.VirtualMethod("call after constructor").Should().Be(string.Empty)); "it should record the method call during the constructor" .x(() => A.CallTo(() => fake.VirtualMethod("call in constructor")).MustHaveHappened()); "it should record the method call after the constructor" .x(() => A.CallTo(() => fake.VirtualMethod("call after constructor")).MustHaveHappened()); }
public void WrappingOverridesStrict( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, string result) { "Given an explicit options builder that makes a fake strict and then wrap an object" .x(() => optionsBuilder = options => options .Strict() .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value"))); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => result = fake.VirtualMethod(null)); "Then it delegates to the wrapped instance" .x(() => result.Should().Be("wrapped value")); }
public void MultipleWrappingConfigurations( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, string result) { "Given an explicit options builder that makes a fake wrap two objects in turn" .x(() => optionsBuilder = options => options .Wrapping(new DerivedMakesVirtualCallInConstructor("first wrapped value")) .Wrapping(new DerivedMakesVirtualCallInConstructor("second wrapped value"))); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => result = fake.VirtualMethod(null)); "Then it delegates to the last wrapped instance" .x(() => result.Should().Be("second wrapped value")); }
public void ConfigureFakeAfterConstruction( MakesVirtualCallInConstructor fake, Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, string result) { "Given an explicit options builder that overrides a method" .x(() => optionsBuilder = options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A <string> ._)) .Returns("configured value in fake options"))); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => result = fake.VirtualMethod(null)); "Then it uses the configured behavior" .x(() => result.Should().Be("configured value in fake options")); }
public void CallsBaseMethodsOverridesWrapping( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, string result) { "Given an explicit options builder that makes a fake wrap an object and then makes it call base methods" .x(() => optionsBuilder = options => options .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")) .CallsBaseMethods()); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => result = fake.VirtualMethod(null)); "Then it calls the base method" .x(() => result.Should().Be("implementation value")); }
public void WrappingDuringConstruction( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that makes a fake wrap an object" .x(() => optionsBuilder = options => options.Wrapping(new MakesVirtualCallInConstructor())); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method delegates to the wrapped instance during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("implementation value")); }
public void CallsBaseMethodsOverridesConfigureFake( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, string result) { "Given an explicit options builder that overrides a method and then makes a fake call base methods" .x(() => optionsBuilder = options => options .ConfigureFake( f => A.CallTo(() => f.VirtualMethod(A <string> ._)).Returns("a value from ConfigureFake")) .CallsBaseMethods()); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => result = fake.VirtualMethod(null)); "Then it calls the base method" .x(() => result.Should().Be("implementation value")); }
public void CallsBaseMethodsDuringConstruction( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that makes a fake call base methods" .x(() => optionsBuilder = options => options .CallsBaseMethods()); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method calls the base method during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("implementation value")); }
public static void CallFromConstructor( IFakeObjectContainer fakeObjectContainer, MakesVirtualCallInConstructor fake, string virtualMethodValueInsideOfScope, string virtualMethodValueOutsideOfScope) { "establish" .x(() => { fakeObjectContainer = A.Fake<IFakeObjectContainer>(); A.CallTo(() => fakeObjectContainer.ConfigureFake(A<Type>._, A<object>._)) .Invokes( (Type t, object options) => A.CallTo(options).WithReturnType<string>().Returns("configured value in fake scope")); }); "when configuring a method called by a constructor from within a scope" .x(() => { using (Fake.CreateScope(fakeObjectContainer)) { fake = A.Fake<MakesVirtualCallInConstructor>(); virtualMethodValueInsideOfScope = fake.VirtualMethod(null); } virtualMethodValueOutsideOfScope = fake.VirtualMethod(null); }); "it should use the fake object container to configure the fake" .x(() => A.CallTo(() => fakeObjectContainer.ConfigureFake(typeof(MakesVirtualCallInConstructor), fake)) .MustHaveHappened()); "it should return the configured value within the scope during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake scope")); "it should return the configured value within the scope after the constructor" .x(() => virtualMethodValueInsideOfScope.Should().Be("configured value in fake scope")); "it should return default value outside the scope" .x(() => virtualMethodValueOutsideOfScope.Should().Be(string.Empty)); }
public static void CallFromConstructor( IFakeObjectContainer fakeObjectContainer, MakesVirtualCallInConstructor fake, string virtualMethodValueInsideOfScope, string virtualMethodValueOutsideOfScope) { "establish" .x(() => { fakeObjectContainer = A.Fake <IFakeObjectContainer>(); A.CallTo(() => fakeObjectContainer.ConfigureFake(A <Type> ._, A <object> ._)) .Invokes( (Type t, object options) => A.CallTo(options).WithReturnType <string>().Returns("configured value in fake scope")); }); "when configuring a method called by a constructor from within a scope" .x(() => { using (Fake.CreateScope(fakeObjectContainer)) { fake = A.Fake <MakesVirtualCallInConstructor>(); virtualMethodValueInsideOfScope = fake.VirtualMethod(null); } virtualMethodValueOutsideOfScope = fake.VirtualMethod(null); }); "it should use the fake object container to configure the fake" .x(() => A.CallTo(() => fakeObjectContainer.ConfigureFake(typeof(MakesVirtualCallInConstructor), fake)) .MustHaveHappened()); "it should return the configured value within the scope during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake scope")); "it should return the configured value within the scope after the constructor" .x(() => virtualMethodValueInsideOfScope.Should().Be("configured value in fake scope")); "it should return default value outside the scope" .x(() => virtualMethodValueOutsideOfScope.Should().Be(string.Empty)); }
public void WithArgumentsForConstructorWithExampleConstructor( MakesVirtualCallInConstructor fake, Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder) { "Given a type with a constructor that requires parameters" .See <MakesVirtualCallInConstructor>(); "And an explicit options builder that specifies the constructor arguments by example" .x(() => optionsBuilder = options => options .WithArgumentsForConstructor(() => new MakesVirtualCallInConstructor("first argument", 9))); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then it is constructed with the supplied arguments" .x(() => { fake.ConstructorArgument1.Should().Be("first argument"); fake.ConstructorArgument2.Should().Be(9); }); }
public static void VirtualMethodCalledDuringConstruction( MakesVirtualCallInConstructor fake) { "Given a type with a default constructor" .x(() => { }); // see MakesVirtualCallInConstructor "And the constructor calls a virtual method" .x(() => { }); // see MakesVirtualCallInConstructor.ctor() "And the method returns a non-default value" .x(() => { }); // see MakesVirtualCallInConstructor.VirtualMethod() "When I create a fake of the type" .x(() => fake = A.Fake <MakesVirtualCallInConstructor>()); "Then the method will return a default value" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be(string.Empty)); "And the method call will be recorded" .x(() => A.CallTo(() => fake.VirtualMethod("call in constructor")).MustHaveHappened()); }
public void StrictAfterConstruction( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, Exception exception) { "Given an explicit options builder that makes a fake strict" .x(() => optionsBuilder = options => options .Strict()); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => exception = Record.Exception(() => fake.VirtualMethod(null))); "Then it throws an exception" .x(() => exception .Should() .BeAnExceptionOfType <ExpectationException>() .WithMessage("Call to unconfigured method of strict fake: *VirtualMethod*")); }
public static void VirtualMethodCalledAfterConstruction( MakesVirtualCallInConstructor fake, string result) { "Given a type with a virtual method" .x(() => { }); // see MakesVirtualCallInConstructor "And the method returns a non-default value" .x(() => { }); // see MakesVirtualCallInConstructor.VirtualMethod "And a fake of that type" .x(() => fake = A.Fake <MakesVirtualCallInConstructor>()); "When I call the method" .x(() => result = fake.VirtualMethod("call after constructor")); "Then it will return a default value" .x(() => result.Should().Be(string.Empty)); "And the method call will be recorded" .x(() => A.CallTo(() => fake.VirtualMethod("call after constructor")).MustHaveHappened()); }
public void ConfigureFakeOverridesWrappingDuringConstruction( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that makes a fake wrap an object and then overrides the method" .x(() => optionsBuilder = options => options .Wrapping(new MakesVirtualCallInConstructor()) .ConfigureFake( f => A.CallTo(() => f.VirtualMethod(A <string> ._)).Returns("configured in test"))); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method uses the configured behavior during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured in test")); }
public void StrictOverridesWrapping( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, Exception exception) { "Given an explicit options builder that makes a fake wrap an object and then be strict" .x(() => optionsBuilder = options => options .Wrapping(new MakesVirtualCallInConstructor()) .Strict()); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => exception = Record.Exception(() => fake.VirtualMethod(null))); "Then it throws an exception" .x(() => exception .Should() .BeAnExceptionOfType <ExpectationException>() .WithMessage("Call to non configured method \"VirtualMethod\" of strict fake.")); }
public void StrictOverridesConfigureFake( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake, Exception exception) { "Given an explicit options builder that overrides a method and then makes a fake strict" .x(() => optionsBuilder = options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A <string> ._)) .Returns("configured value of strict fake")) .Strict()); "And a fake created using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "When I call the method" .x(() => exception = Record.Exception(() => fake.VirtualMethod(null))); "Then it throws an exception" .x(() => exception .Should() .BeAnExceptionOfType <ExpectationException>() .WithMessage("Call to unconfigured method of strict fake: *VirtualMethod*")); }
public void StrictDuringConstruction( Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder, MakesVirtualCallInConstructor fake) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that makes a fake strict" .x(() => optionsBuilder = options => options .Strict()); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method throws an exception" .x(() => fake.ExceptionFromVirtualMethodCallInConstructor .Should() .BeAnExceptionOfType <ExpectationException>() .WithMessage("Call to unconfigured method of strict fake: *VirtualMethod*")); }
public static void UsingFakeOutsideOfScope( IFakeObjectContainer fakeObjectContainer, MakesVirtualCallInConstructor fake, string virtualMethodValueOutsideOfScope) { "given an object container" .x(() => fakeObjectContainer = CreateFakeObjectContainer("configured value in fake scope")); "and a fake created within a scope using that container" .x(() => { using (Fake.CreateScope(fakeObjectContainer)) { fake = A.Fake <MakesVirtualCallInConstructor>(); } }); "when the fake is accessed outside the scope" .x(() => virtualMethodValueOutsideOfScope = fake.VirtualMethod("call outside scope")); "then the object container's configuration should not be used" .x(() => virtualMethodValueOutsideOfScope.Should().Be(string.Empty)); }
public static void UsingFakeOutsideOfScope( IFakeObjectContainer fakeObjectContainer, MakesVirtualCallInConstructor fake, string virtualMethodValueOutsideOfScope) { "given an object container" .x(() => fakeObjectContainer = CreateFakeObjectContainer("configured value in fake scope")); "and a fake created within a scope using that container" .x(() => { using (Fake.CreateScope(fakeObjectContainer)) { fake = A.Fake<MakesVirtualCallInConstructor>(); } }); "when the fake is accessed outside the scope" .x(() => virtualMethodValueOutsideOfScope = fake.VirtualMethod("call outside scope")); "then the object container's configuration should not be used" .x(() => virtualMethodValueOutsideOfScope.Should().Be(string.Empty)); }
public void MultipleConfigureFakeConfigurations( MakesVirtualCallInConstructor fake, Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that overrides the method with changing behavior" .x(() => optionsBuilder = options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A <string> ._)).Returns("second value")) .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A <string> ._)).Returns("first value").Once())); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method uses the first behavior during the constructor " .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("first value")); "And the method uses the second behavior thereafter" .x(() => fake.VirtualMethod(null).Should().Be("second value")); }
public void ConfigureFakeDuringConstruction( MakesVirtualCallInConstructor fake, Action <IFakeOptions <MakesVirtualCallInConstructor> > optionsBuilder) { "Given a type with a parameterless constructor" .See <MakesVirtualCallInConstructor>(); "And the constructor calls a virtual method" .See(() => new MakesVirtualCallInConstructor()); "And an explicit options builder that overrides the method" .x(() => optionsBuilder = options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A <string> ._)) .Returns("configured value in fake options"))); "When I create a fake using the options builder" .x(() => fake = this.CreateFake(optionsBuilder)); "Then the method returns the configured value during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake options")); "And it returns the configured value after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("configured value in fake options")); }
public static void CreatingFakeInsideScope( IFakeObjectContainer fakeObjectContainer, IFakeScope scope, MakesVirtualCallInConstructor fake) { "given an object container" .x(() => fakeObjectContainer = CreateFakeObjectContainer("configured value in fake scope")); "and a fake scope using that container" .x(context => scope = Fake.CreateScope(fakeObjectContainer).Using(context)); "when a fake is created inside the scope" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>()); "then the object container should configure the fake" .x(() => A.CallTo(() => fakeObjectContainer.ConfigureFake(typeof(MakesVirtualCallInConstructor), fake)) .MustHaveHappened()); "and the object container's configuration should be used during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake scope")); "and the object container's configuration should be used after the constructor" .x(() => fake.VirtualMethod("call after constructor").Should().Be("configured value in fake scope")); }
public static void CreatingFakeInsideScope( IFakeObjectContainer fakeObjectContainer, IFakeScope scope, MakesVirtualCallInConstructor fake) { "given an object container" .x(() => fakeObjectContainer = CreateFakeObjectContainer("configured value in fake scope")); "and a fake scope using that container" .x(context => scope = Fake.CreateScope(fakeObjectContainer).Using(context)); "when a fake is created inside the scope" .x(() => fake = A.Fake <MakesVirtualCallInConstructor>()); "then the object container should configure the fake" .x(() => A.CallTo(() => fakeObjectContainer.BuildOptions(typeof(MakesVirtualCallInConstructor), A <IFakeOptions> ._)) .MustHaveHappened()); "and the object container's configuration should be used during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value in fake scope")); "and the object container's configuration should be used after the constructor" .x(() => fake.VirtualMethod("call after constructor").Should().Be("configured value in fake scope")); }
public static void WrappingCombinedWithConfigureFake( MakesVirtualCallInConstructor fake) { "When a fake is configured to wrap an object followed by explicit configuration" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Wrapping(new MakesVirtualCallInConstructor()) .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)) .Returns("configured in test")))); "Then it should use the configured behavior during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured in test")); "And it should use the configured behavior after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("configured in test")); }
public static void StrictCombinedWithConfigureFake( MakesVirtualCallInConstructor fake) { "When specifying a strict fake followed by explicit configuration" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Strict() .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)) .Returns("configured value of strict fake")))); "Then it should return the configured value during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("configured value of strict fake")); "And it should return the configured value after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("configured value of strict fake")); }
public static void WrappingOverridesStrict( MakesVirtualCallInConstructor fake) { "When specifying a strict fake followed by configuring it to wrap an object" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Strict() .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")))); "Then it should delegate to the wrapped instance" .x(() => fake.VirtualMethod(null).Should().Be("wrapped value")); }
public static void WrappingOverridesConfigureFake( MakesVirtualCallInConstructor fake) { "When explicit configuration is followed by wrapping an object" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)) .Returns("configured in test")) .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")))); "Then it should delegate to the wrapped instance during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("wrapped value")); "And then it should delegate to the wrapped instance after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("wrapped value")); }
public static void WrappingOverridesCallsBaseMethods( MakesVirtualCallInConstructor fake) { "When specifying that a fake calls base methods followed by wrapping an object" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .CallsBaseMethods() .Wrapping(new DerivedMakesVirtualCallInConstructor("wrapped value")))); "Then it should delegate to the wrapped instance" .x(() => fake.VirtualMethod(null).Should().Be("wrapped value")); }
public static void WrappingDuringConstruction( MakesVirtualCallInConstructor fake) { "When a fake is configured to wrap an object" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>( options => options.Wrapping(new MakesVirtualCallInConstructor()))); "Then it should delegate to the wrapped instance during the constructor" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("implementation value")); "And then it should delegate to the wrapped instance after the constructor" .x(() => fake.VirtualMethod(null).Should().Be("implementation value")); }
public static void MultipleImplementsConfigurations( MakesVirtualCallInConstructor fake) { "When a fake is built to implement two interfaces in turn" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Implements(typeof(IComparable)) .Implements(typeof(ICloneable)))); "Then it should implement both interfaces" .x(() => fake.Should().BeAssignableTo<IComparable>().And .BeAssignableTo<ICloneable>()); }
public static void WithArgumentsForConstructorWithExampleConstructor( MakesVirtualCallInConstructor fake) { "When specifying fake constructor arguments with an example constructor" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .WithArgumentsForConstructor(() => new MakesVirtualCallInConstructor("first argument", 9)))); "Then it should be constructed with the supplied arguments" .x(() => { fake.ConstructorArgument1.Should().Be("first argument"); fake.ConstructorArgument2.Should().Be(9); }); }
public static void WithArgumentsForConstructor( MakesVirtualCallInConstructor fake) { "When specifying fake constructor arguments with a list of arguments" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .WithArgumentsForConstructor(new object[] { "prime argument", 2 }))); "Then it should be constructed with the supplied arguments" .x(() => { fake.ConstructorArgument1.Should().Be("prime argument"); fake.ConstructorArgument2.Should().Be(2); }); }
public static void StrictOverridesWrapping( MakesVirtualCallInConstructor fake) { "When a fake is configured to wrap an object followed by specifying that the fake is strict" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Wrapping(new MakesVirtualCallInConstructor()) .Strict())); "Then it should throw an exception from a method call" .x(() => Record.Exception(() => fake.VirtualMethod(null)) .Should() .BeAnExceptionOfType<ExpectationException>()); }
public static void StrictOverridesConfigureFake( MakesVirtualCallInConstructor fake) { "When explicit fake configuration is followed by specifying that the fake is strict" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .ConfigureFake(f => A.CallTo(() => f.VirtualMethod(A<string>._)) .Returns("configured value of strict fake")) .Strict())); "Then it should throw an exception from a method call" .x(() => Record.Exception(() => fake.VirtualMethod(null)) .Should() .BeAnExceptionOfType<ExpectationException>()); }
public static void StrictOverridesCallsBaseMethods( MakesVirtualCallInConstructor fake) { "When specifying that a fake calls base methods followed by specifying that the fake is strict" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .CallsBaseMethods() .Strict())); "Then it should throw an exception from a method call" .x(() => Record.Exception(() => fake.VirtualMethod(null)) .Should() .BeAnExceptionOfType<ExpectationException>()); }
public static void StrictDuringConstruction( MakesVirtualCallInConstructor fake) { "When specifying a strict fake" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options.Strict())); "Then it should throw an exception from a method call during the constructor" .x(() => fake.ExceptionFromVirtualMethodCallInConstructor .Should() .BeAnExceptionOfType<ExpectationException>() .WithMessage("Call to non configured method \"VirtualMethod\" of strict fake.")); "And it should throw an exception from a method call after the constructor" .x(() => Record.Exception(() => fake.VirtualMethod("call outside constructor")) .Should() .BeAnExceptionOfType<ExpectationException>() .WithMessage("Call to non configured method \"VirtualMethod\" of strict fake.")); }
public static void MultipleWrappingConfigurations( MakesVirtualCallInConstructor fake) { "When a fake is configured to wrap two different objects" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .Wrapping(new DerivedMakesVirtualCallInConstructor("first wrapped value")) .Wrapping(new DerivedMakesVirtualCallInConstructor("second wrapped value")))); "Then it should delegate to the last wrapped instance" .x(() => fake.VirtualMethodValueDuringConstructorCall.Should().Be("second wrapped value")); }
public static void MultipleWithArgumentsForConstructorConfigurations( MakesVirtualCallInConstructor fake) { "When specifying fake constructor arguments twice" .x(() => fake = A.Fake<MakesVirtualCallInConstructor>(options => options .WithArgumentsForConstructor(new object[] { "prime argument", 1 }) .WithArgumentsForConstructor(() => new MakesVirtualCallInConstructor("secondary argument", 2)))); "Then the fake should be constructed with the last set of supplied arguments" .x(() => { fake.ConstructorArgument1.Should().Be("secondary argument"); fake.ConstructorArgument2.Should().Be(2); }); }