diff --git a/Source/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj b/Source/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj index c682242..352a0e6 100644 --- a/Source/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj +++ b/Source/NSubstitute.Acceptance.Specs/NSubstitute.Acceptance.Specs.csproj @@ -71,7 +71,6 @@ - diff --git a/Source/NSubstitute.Acceptance.Specs/SubstituteTests.cs b/Source/NSubstitute.Acceptance.Specs/SubstituteTests.cs deleted file mode 100644 index 70533b3..0000000 --- a/Source/NSubstitute.Acceptance.Specs/SubstituteTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using NSubstitute.Exceptions; -using NUnit.Framework; - -namespace NSubstitute.Acceptance.Specs -{ - [TestFixture] - public class SubstituteTests - { - [TestFixture] - public class ForTests - { - [TestFixture] - public class ThatCallsBaseByDefaultTests - { - [Test] - public void Given_SubstituteForInterface_When_MethodIsCalled_Then_ShouldThrowException() - { - var testAbstractClass = Substitute.For(ThatCallsBase.ByDefault); - Assert.Throws(testAbstractClass.TestMethod); - } - - [Test] - public void Given_SubstituteForAbstractClass_When_AbstractMethodIsCalled_Then_ShouldThrowException() - { - var testAbstractClass = Substitute.For(ThatCallsBase.ByDefault); - Assert.Throws(testAbstractClass.AbstractMethod); - } - - [Test] - public void Given_SubstituteForAction_When_ActionIsCalled_Then_ShouldThrowException() - { - var action = Substitute.For(ThatCallsBase.ByDefault); - Assert.Throws(() => action()); - } - - [Test] - public void Given_SubstituteForFunc_When_FuncIsCalled_Then_ShouldThrowException() - { - var func = Substitute.For>(ThatCallsBase.ByDefault); - Assert.Throws(() => func()); - } - - [Test] - public void Given_SubstituteForEventHandler_When_EventHandlerIsCalled_Then_ShouldThrowException() - { - var eventHandler = Substitute.For(ThatCallsBase.ByDefault); - Assert.Throws(() => eventHandler.Invoke(null, null)); - } - - [Test] - public void Given_SubstituteForAbstractClass_When_MethodWithImplementationIsCalled_Then_ShouldCallBaseImplementation() - { - var testAbstractClass = Substitute.For(ThatCallsBase.ByDefault); - Assert.That(testAbstractClass.MethodWithImplementation(1), Is.EqualTo(1)); - } - - [Test] - public void Given_SubstituteForClass_When_VirtualMethodIsCalled_Then_ShouldCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethod(); - Assert.That(testClass.CalledTimes, Is.EqualTo(1)); - } - - [Test] - public void Given_SubstituteForClass_When_AbstractMethodIsCalled_Then_ShouldCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.AbstractMethod(); - Assert.That(testClass.CalledTimes, Is.EqualTo(1)); - } - - [Test] - public void Given_SubstituteForClass_When_NotVirtualMethodIsCalled_Then_ShouldCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.NotVirtualMethodReturnsSameInt(1); - Assert.That(testClass.CalledTimes, Is.EqualTo(1)); - } - - [Test] - public void Given_SubstituteForClass_When_VirtualMethodIsCalledTwice_Then_ShouldCallBaseImplementationTwice() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethod(); - testClass.VirtualMethod(); - Assert.That(testClass.CalledTimes, Is.EqualTo(2)); - } - - [Test] - public void Given_SubstituteForClass_When_VirtualMethodsReturnValueIsOverwritten_Then_ShouldNotCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethodReturnsSameInt(Arg.Any()).Returns(1); - Assert.That(testClass.CalledTimes, Is.EqualTo(0)); - } - - [Test] - public void Given_SubstituteForClass_And_ReturnValueIsOverwritten_When_VirtualMethodIsCalled_Then_ShouldReturnOverwrittenValue() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethodReturnsSameInt(Arg.Any()).Returns(2); - Assert.That(testClass.VirtualMethodReturnsSameInt(1), Is.EqualTo(2)); - } - - [Test] - public void Given_SubstituteForClass_And_VirtualMethodReturnValueForSpecifiedArg_When_VirtualMethodIsCalledWithSpecifiedArg_Then_ShouldNotCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethodReturnsSameInt(Arg.Is(1)).Returns(2); - Assert.That(testClass.VirtualMethodReturnsSameInt(1), Is.EqualTo(2)); - Assert.That(testClass.CalledTimes, Is.EqualTo(0)); - } - - [Test] - public void Given_SubstituteForClass_And_VirtualMethodReturnValueForSpecifiedArg_When_VirtualMethodIsCalledWithoutSpecifiedArg_Then_ShouldCallBaseImplementation() - { - var testClass = Substitute.For(ThatCallsBase.ByDefault); - testClass.VirtualMethodReturnsSameInt(Arg.Is(1)).Returns(2); - Assert.That(testClass.VirtualMethodReturnsSameInt(3), Is.EqualTo(3)); - Assert.That(testClass.CalledTimes, Is.EqualTo(1)); - } - - public interface ITestInterface - { - void TestMethod(); - } - - public abstract class TestAbstractClass - { - public abstract void AbstractMethod(); - public int MethodWithImplementation(int i) - { - return i; - } - } - - public class TestClass : TestAbstractClass - { - public int CalledTimes { get; set; } - - public virtual int VirtualMethodReturnsSameInt(int i) - { - CalledTimes++; - return i; - } - - public virtual void VirtualMethod() - { - CalledTimes++; - } - - public int NotVirtualMethodReturnsSameInt(int i) - { - CalledTimes++; - return i; - } - - public override void AbstractMethod() - { - CalledTimes++; - } - } - } - } - } -} diff --git a/Source/NSubstitute.Specs/CallFactorySpecs.cs b/Source/NSubstitute.Specs/CallFactorySpecs.cs index 0551bee..635c96c 100644 --- a/Source/NSubstitute.Specs/CallFactorySpecs.cs +++ b/Source/NSubstitute.Specs/CallFactorySpecs.cs @@ -26,7 +26,7 @@ namespace NSubstitute.Specs public override void Because() { - _result = sut.Create(_method, _args, _target); + _result = sut.Create(_method, _args, _target, () => null); } [Test] diff --git a/Source/NSubstitute.Specs/ConfigureCallSpecs.cs b/Source/NSubstitute.Specs/ConfigureCallSpecs.cs index e9228c5..d9cc9ca 100644 --- a/Source/NSubstitute.Specs/ConfigureCallSpecs.cs +++ b/Source/NSubstitute.Specs/ConfigureCallSpecs.cs @@ -11,7 +11,6 @@ namespace NSubstitute.Specs public abstract class Concern : ConcernFor { protected ICallActions _callActions; - protected ICallBaseSpecifications _callBaseSpecifications; protected ICallResults _configuredResults; protected IGetCallSpec _getCallSpec; protected IReturn _compatibleReturnValue; @@ -21,7 +20,6 @@ namespace NSubstitute.Specs _configuredResults = mock(); _callActions = mock(); _getCallSpec = mock(); - _callBaseSpecifications = mock(); _compatibleReturnValue = mock(); _compatibleReturnValue.stub(x => x.CanBeAssignedTo(It.IsAny())).Return(true); @@ -29,7 +27,7 @@ namespace NSubstitute.Specs public override ConfigureCall CreateSubjectUnderTest() { - return new ConfigureCall(_configuredResults, _callActions, _getCallSpec, _callBaseSpecifications); + return new ConfigureCall(_configuredResults, _callActions, _getCallSpec); } } diff --git a/Source/NSubstitute/Core/CallFactory.cs b/Source/NSubstitute/Core/CallFactory.cs index e2ec9e8..aebaa03 100644 --- a/Source/NSubstitute/Core/CallFactory.cs +++ b/Source/NSubstitute/Core/CallFactory.cs @@ -16,7 +16,7 @@ namespace NSubstitute.Core _context = context; } - public ICall Create(MethodInfo methodInfo, object[] arguments, object target, Func baseMethod = null) + public ICall Create(MethodInfo methodInfo, object[] arguments, object target, Func baseMethod) { var argSpecs = (methodInfo.GetParameters().Length == 0) ? EmptyList() : _context.DequeueAllArgumentSpecifications(); return new Call(methodInfo, arguments, target, argSpecs, baseMethod); diff --git a/Source/NSubstitute/Core/ConfigureCall.cs b/Source/NSubstitute/Core/ConfigureCall.cs index a95c7eb..3c8293b 100644 --- a/Source/NSubstitute/Core/ConfigureCall.cs +++ b/Source/NSubstitute/Core/ConfigureCall.cs @@ -7,14 +7,12 @@ namespace NSubstitute.Core private readonly ICallResults _configuredResults; private readonly ICallActions _callActions; private readonly IGetCallSpec _getCallSpec; - private readonly ICallBaseSpecifications _callBaseSpecifications; - public ConfigureCall(ICallResults configuredResults, ICallActions callActions, IGetCallSpec getCallSpec, ICallBaseSpecifications callBaseSpecifications) + public ConfigureCall(ICallResults configuredResults, ICallActions callActions, IGetCallSpec getCallSpec) { _configuredResults = configuredResults; _callActions = callActions; _getCallSpec = getCallSpec; - _callBaseSpecifications = callBaseSpecifications; } public ConfiguredCall SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs) diff --git a/Source/NSubstitute/Core/SubstituteState.cs b/Source/NSubstitute/Core/SubstituteState.cs index 3d73ae2..9dbe9c0 100644 --- a/Source/NSubstitute/Core/SubstituteState.cs +++ b/Source/NSubstitute/Core/SubstituteState.cs @@ -35,7 +35,7 @@ namespace NSubstitute.Core var getCallSpec = new GetCallSpec(callStack, PendingSpecification, CallSpecificationFactory, CallActions); - ConfigureCall = new ConfigureCall(CallResults, CallActions, getCallSpec, CallBaseSpecifications); + ConfigureCall = new ConfigureCall(CallResults, CallActions, getCallSpec); EventHandlerRegistry = new EventHandlerRegistry(); AutoValueProviders = new IAutoValueProvider[] { new AutoSubstituteProvider(substituteFactory), diff --git a/Source/NSubstitute/NSubstitute.csproj b/Source/NSubstitute/NSubstitute.csproj index 2d54ad1..6505082 100644 --- a/Source/NSubstitute/NSubstitute.csproj +++ b/Source/NSubstitute/NSubstitute.csproj @@ -88,7 +88,6 @@ - @@ -269,4 +268,4 @@ - + \ No newline at end of file diff --git a/Source/NSubstitute/Substitute.cs b/Source/NSubstitute/Substitute.cs index aebbaa8..237d7d2 100644 --- a/Source/NSubstitute/Substitute.cs +++ b/Source/NSubstitute/Substitute.cs @@ -22,21 +22,6 @@ namespace NSubstitute return (T) For(new[] {typeof(T)}, constructorArguments); } - /// - /// Substitute for an interface or class. - /// Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members - /// can be recorded or have return values specified. - /// - /// The type of interface or class to substitute. - /// Represents default substitute behavior. If is passed then the substitute calls base implementation by default. - /// Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. - /// A substitute for the interface or class. - public static T For(ThatCallsBase callBaseBehavior, params object[] constructorArguments) - where T : class - { - return (T)For(new[] { typeof(T) }, constructorArguments, callBaseBehavior == ThatCallsBase.ByDefault); - } - /// /// Substitute for multiple interfaces or a class that implements an interface. At most one class can be specified. /// Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members @@ -55,7 +40,7 @@ namespace NSubstitute /// /// Substitute for multiple interfaces or a class that implements multiple interfaces. At most one class can be specified. - /// If additional interfaces are required use the overload. + /// If additional interfaces are required use the overload. /// Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members /// can be recorded or have return values specified. /// @@ -85,20 +70,5 @@ namespace NSubstitute var substituteFactory = SubstitutionContext.Current.SubstituteFactory; return substituteFactory.Create(typesToProxy, constructorArguments); } - - /// - /// Substitute for multiple interfaces or a class that implements multiple interfaces. At most one class can be specified. - /// Be careful when specifying a class, as all non-virtual members will actually be executed. Only virtual members - /// can be recorded or have return values specified. - /// - /// The types of interfaces or a type of class and multiple interfaces the substitute should implement. - /// Arguments required to construct a class being substituted. Not required for interfaces or classes with default constructors. - /// If true the substitute calls base implementation by default if it's not overwritten - /// A substitute implementing the specified types. - private static object For(Type[] typesToProxy, object[] constructorArguments, bool callBaseByDefault) - { - var substituteFactory = SubstitutionContext.Current.SubstituteFactory; - return substituteFactory.Create(typesToProxy, constructorArguments, callBaseByDefault); - } } } \ No newline at end of file diff --git a/Source/NSubstitute/ThatCallsBase.cs b/Source/NSubstitute/ThatCallsBase.cs deleted file mode 100644 index d3c176b..0000000 --- a/Source/NSubstitute/ThatCallsBase.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace NSubstitute -{ - /// - /// Represents the substitute behavior regarding base implementation - /// - public enum ThatCallsBase - { - /// - /// The substitute calls base implementation only when it's specified explicitly. - /// - OnlyWhenSpecified = 0, - - /// - /// The substitute calls base implementation by default. Make sure that you substitute for a class. - /// - ByDefault, - } -}