diff --git a/Rhino.Mocks.GettingStarted/Rhino.Mocks.GettingStarted.csproj b/Rhino.Mocks.GettingStarted/Rhino.Mocks.GettingStarted.csproj index d5057553..029226d2 100644 --- a/Rhino.Mocks.GettingStarted/Rhino.Mocks.GettingStarted.csproj +++ b/Rhino.Mocks.GettingStarted/Rhino.Mocks.GettingStarted.csproj @@ -1,73 +1,73 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {59F8A3E2-80C5-4250-909A-16741DF81B23} - Library - Properties - Rhino.Mocks.GettingStarted - Rhino.Mocks.GettingStarted - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\SharedLibs\nunit.framework.dll - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8} - Rhino.Mocks - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {59F8A3E2-80C5-4250-909A-16741DF81B23} + Library + Properties + Rhino.Mocks.GettingStarted + Rhino.Mocks.GettingStarted + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\SharedLibs\nunit.framework.dll + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8} + Rhino.Mocks + + + + \ No newline at end of file diff --git a/Rhino.Mocks.GettingStarted/Stubs.cs b/Rhino.Mocks.GettingStarted/Stubs.cs index 17a5cc91..e24f9199 100644 --- a/Rhino.Mocks.GettingStarted/Stubs.cs +++ b/Rhino.Mocks.GettingStarted/Stubs.cs @@ -1,29 +1,59 @@ -using NUnit.Framework; - -namespace Rhino.Mocks.GettingStarted -{ - [TestFixture] - public class Stubs - { - [Test] - public void Demonstrate_Stub_Implements_the_passed_type() - { - // Arrange - - // Act - var stub = MockRepository.GenerateStub(); - - // Assert - Assert.That(stub.Implements()); - } - - /// - /// This is just a sample interface, what it is or does isn't really relevant. It could - /// be IUser of IOrder - /// - public interface IFoo - { - string Name { get; set; } - } - } +using NUnit.Framework; + +namespace Rhino.Mocks.GettingStarted +{ + [TestFixture] + public class Stubs + { + [Test] + public void Demonstrate_Stub_Implements_the_passed_type() + { + // Arrange + + // Act + var stub = MockRepository.GenerateStub(); + + // Assert + Assert.That(stub.Implements()); + } + + /// + /// When you need to mock a read-only property of a class. + /// + [Test] + public void How_to_Stub_out_your_own_value_of_a_ReadOnlyProperty() + { + // Arrange + var foo = MockRepository.GenerateStub(); + foo.Stub(x => x.ID).Return(123); + + // Act + var id = foo.ID; + + // Assert + Assert.That(id, Is.EqualTo(123)); + } + + /// + /// This is just a sample interface, what it is or does isn't really relevant. It could + /// be IUser of IOrder + /// + public interface IFoo + { + int ID { get; } + string Name { get; set; } + } + + public class Foo : IFoo + { + private int id; + + public int ID + { + get { return id; } + } + + public string Name { get; set; } + } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/MethodRecorders/RecorderChangerTests.cs b/Rhino.Mocks.Tests/MethodRecorders/RecorderChangerTests.cs index f5af1c01..d5764c53 100644 --- a/Rhino.Mocks.Tests/MethodRecorders/RecorderChangerTests.cs +++ b/Rhino.Mocks.Tests/MethodRecorders/RecorderChangerTests.cs @@ -1,115 +1,115 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System.Reflection; -using Xunit; -using Rhino.Mocks.Expectations; -using Rhino.Mocks.Impl; -using Rhino.Mocks.Interfaces; -using Rhino.Mocks.MethodRecorders; -using Rhino.Mocks.Tests.Expectations; -using Rhino.Mocks.Tests.Impl; - -namespace Rhino.Mocks.Tests.MethodRecorders -{ - using Generated; - - - public class RecorderChangerTests - { - private object proxy; - private MethodInfo method; - private IExpectation expectation; - private object[] args; - private MockRepository mocks; - - public RecorderChangerTests() - { - proxy = new object(); - method = typeof (object).GetMethod("ToString"); - expectation = new AnyArgsExpectation(new FakeInvocation(method), new Range(1, 1)); - args = new object[0]; - mocks = new MockRepository(); - } - - [Fact] - public void ChangeRecorderOnCtor() - { - IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); - new RecorderChanger(mocks, recorder, testRecorder); - recorder.GetAllExpectationsForProxy(new object()); - Assert.True(testRecorder.DoGetAllExpectationsForProxyCalled); - Assert.Same(testRecorder, Get.Recorder(mocks)); - } - - [Fact] - public void ChangeBackOnDispose() - { - IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); - using (new RecorderChanger(mocks, recorder, testRecorder)) - { - Assert.Same(testRecorder, Get.Recorder(mocks)); - } - Assert.NotSame(testRecorder, Get.Recorder(mocks)); - testRecorder.DoRecordCalled = false; - recorder.Record(proxy, method, expectation); - Assert.False(testRecorder.DoRecordCalled); - - } - - [Fact] - public void ChangeRecorderTwice() - { - IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); - using (new RecorderChanger(mocks, recorder, testRecorder)) - { - Assert.Same(testRecorder, Get.Recorder(mocks)); - MethodRecorderBaseTests.TestMethodRecorder testRecorder2 = new MethodRecorderBaseTests.TestMethodRecorder(); - using (new RecorderChanger(mocks, recorder, testRecorder2)) - { - Assert.Same(testRecorder2, Get.Recorder(mocks)); - testRecorder2.DoRecordCalled = false; - recorder.Record(proxy, method, expectation); - Assert.True(testRecorder2.DoRecordCalled); - } - Assert.Same(testRecorder, Get.Recorder(mocks)); - testRecorder.DoRecordCalled = false; - recorder.Record(proxy, method, expectation); - Assert.True(testRecorder.DoRecordCalled); - } - Assert.NotSame(testRecorder, Get.Recorder(mocks)); - testRecorder.DoRecordCalled = false; - recorder.Record(proxy, method, expectation); - Assert.False(testRecorder.DoRecordCalled); - } - } +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System.Reflection; +using Xunit; +using Rhino.Mocks.Expectations; +using Rhino.Mocks.Impl; +using Rhino.Mocks.Interfaces; +using Rhino.Mocks.MethodRecorders; +using Rhino.Mocks.Tests.Expectations; +using Rhino.Mocks.Tests.Impl; + +namespace Rhino.Mocks.Tests.MethodRecorders +{ + using Generated; + + + public class RecorderChangerTests + { + private object proxy; + private MethodInfo method; + private IExpectation expectation; + private object[] args; + private MockRepository mocks; + + public RecorderChangerTests() + { + proxy = new object(); + method = typeof (object).GetMethod("ToString"); + expectation = new AnyArgsExpectation(new FakeInvocation(method), new Range(1, 1)); + args = new object[0]; + mocks = new MockRepository(); + } + + [Fact] + public void ChangeRecorderOnCtor() + { + IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); + new RecorderChanger(mocks, recorder, testRecorder); + recorder.GetAllExpectationsForProxy(new object()); + Assert.True(testRecorder.DoGetAllExpectationsForProxyCalled); + Assert.Same(testRecorder, Get.Recorder(mocks)); + } + + [Fact] + public void ChangeBackOnDispose() + { + IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); + using (new RecorderChanger(mocks, recorder, testRecorder)) + { + Assert.Same(testRecorder, Get.Recorder(mocks)); + } + Assert.NotSame(testRecorder, Get.Recorder(mocks)); + testRecorder.DoRecordCalled = false; + recorder.Record(proxy, method, expectation); + Assert.False(testRecorder.DoRecordCalled); + + } + + [Fact] + public void ChangeRecorderTwice() + { + IMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + MethodRecorderBaseTests.TestMethodRecorder testRecorder = new MethodRecorderBaseTests.TestMethodRecorder(); + using (new RecorderChanger(mocks, recorder, testRecorder)) + { + Assert.Same(testRecorder, Get.Recorder(mocks)); + MethodRecorderBaseTests.TestMethodRecorder testRecorder2 = new MethodRecorderBaseTests.TestMethodRecorder(); + using (new RecorderChanger(mocks, recorder, testRecorder2)) + { + Assert.Same(testRecorder2, Get.Recorder(mocks)); + testRecorder2.DoRecordCalled = false; + recorder.Record(proxy, method, expectation); + Assert.True(testRecorder2.DoRecordCalled); + } + Assert.Same(testRecorder, Get.Recorder(mocks)); + testRecorder.DoRecordCalled = false; + recorder.Record(proxy, method, expectation); + Assert.True(testRecorder.DoRecordCalled); + } + Assert.NotSame(testRecorder, Get.Recorder(mocks)); + testRecorder.DoRecordCalled = false; + recorder.Record(proxy, method, expectation); + Assert.False(testRecorder.DoRecordCalled); + } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/MethodRecorders/UnorderedMethodRecorderTests.cs b/Rhino.Mocks.Tests/MethodRecorders/UnorderedMethodRecorderTests.cs index 5ae5b274..92dbf96b 100644 --- a/Rhino.Mocks.Tests/MethodRecorders/UnorderedMethodRecorderTests.cs +++ b/Rhino.Mocks.Tests/MethodRecorders/UnorderedMethodRecorderTests.cs @@ -1,77 +1,77 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Expectations; -using Rhino.Mocks.Generated; -using Rhino.Mocks.Impl; -using Rhino.Mocks.Interfaces; -using Rhino.Mocks.MethodRecorders; -using Rhino.Mocks.Tests.Expectations; - -namespace Rhino.Mocks.Tests.MethodRecorders -{ - - public class UnorderedMethodRecorderTests : IMethodRecorderTests - { - [Fact] - public void CanRecordMethodsAndVerifyThem() - { - UnorderedMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - recorder.Record(demo, voidNoArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); - recorder.Record(demo, voidThreeArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); - - Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidThreeArgs),demo, voidThreeArgs, new object[0])); - Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs),demo, voidNoArgs, new object[0])); - } - - - [Fact] - public void ReplayUnrecordedMethods() - { - UnorderedMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - recorder.Record(demo, voidNoArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); - recorder.Record(demo, voidThreeArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); - - Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidThreeArgs),demo, voidThreeArgs, new object[0])); - Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs),demo, voidNoArgs, new object[0])); - - Assert.Throws("IDemo.VoidNoArgs(); Expected #1, Actual #2.", - () => - recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs), demo, - voidNoArgs, new object[0])); - } - - protected override IMethodRecorder CreateRecorder() - { - return new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); - } - } +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Expectations; +using Rhino.Mocks.Generated; +using Rhino.Mocks.Impl; +using Rhino.Mocks.Interfaces; +using Rhino.Mocks.MethodRecorders; +using Rhino.Mocks.Tests.Expectations; + +namespace Rhino.Mocks.Tests.MethodRecorders +{ + + public class UnorderedMethodRecorderTests : IMethodRecorderTests + { + [Fact] + public void CanRecordMethodsAndVerifyThem() + { + UnorderedMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + recorder.Record(demo, voidNoArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); + recorder.Record(demo, voidThreeArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); + + Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidThreeArgs),demo, voidThreeArgs, new object[0])); + Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs),demo, voidNoArgs, new object[0])); + } + + + [Fact] + public void ReplayUnrecordedMethods() + { + UnorderedMethodRecorder recorder = new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + recorder.Record(demo, voidNoArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); + recorder.Record(demo, voidThreeArgs, new AnyArgsExpectation(new FakeInvocation(voidNoArgs), new Range(1, 1))); + + Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidThreeArgs),demo, voidThreeArgs, new object[0])); + Assert.NotNull(recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs),demo, voidNoArgs, new object[0])); + + Assert.Throws("IDemo.VoidNoArgs(); Expected #1, Actual #2.", + () => + recorder.GetRecordedExpectation(new FakeInvocation(voidNoArgs), demo, + voidNoArgs, new object[0])); + } + + protected override IMethodRecorder CreateRecorder() + { + return new UnorderedMethodRecorder(new ProxyMethodExpectationsDictionary()); + } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/MockRepositoryTests.cs b/Rhino.Mocks.Tests/MockRepositoryTests.cs index f6183d60..d4c7f125 100644 --- a/Rhino.Mocks.Tests/MockRepositoryTests.cs +++ b/Rhino.Mocks.Tests/MockRepositoryTests.cs @@ -1,638 +1,638 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Interfaces; - -namespace Rhino.Mocks.Tests -{ - - public class MockRepositoryTests - { - private MockRepository mocks; - private IDemo demo; - - public MockRepositoryTests() - { - mocks = new MockRepository(); - demo = this.mocks.StrictMock(typeof(IDemo)) as IDemo; - } - - [Fact] - public void CreatesNewMockObject() - { - Assert.NotNull(demo); - } - - [Fact] - public void CallMethodOnMockObject() - { - demo.ReturnStringNoArgs(); - } - - [Fact] - public void RecordWithBadReplayCauseException() - { - demo.ReturnStringNoArgs(); - LastCall.On(demo).Return(null); - mocks.Replay(demo); - Assert.Throws( - "IDemo.ReturnStringNoArgs(); Expected #1, Actual #0.", - () => mocks.Verify(demo)); - } - - [Fact] - public void RecordTwoMethodsButReplayOneCauseException() - { - demo.ReturnStringNoArgs(); - LastCall.On(demo).Return(null).Repeat.Twice(); - mocks.Replay(demo); - demo.ReturnStringNoArgs(); - Assert.Throws( - "IDemo.ReturnStringNoArgs(); Expected #2, Actual #1.", - () => mocks.Verify(demo)); - } - - [Fact] - public void CallingReplayOnNonMockThrows() - { - MockRepository mocks = new MockRepository(); - Assert.Throws( - "The object is not a mock object that belong to this repository.", - () => mocks.Replay(new object())); - } - - [Fact] - public void CallingVerifyOnNonMockThrows() - { - MockRepository mocks = new MockRepository(); - Assert.Throws( - "The object is not a mock object that belong to this repository.", - () => mocks.Verify(new object())); - } - - [Fact] - public void TryingToReplayMockMoreThanOnceThrows() - { - mocks.Replay(demo); - Assert.Throws( - "This action is invalid when the mock object is in replay state.", - () => mocks.Replay(demo)); - } - - [Fact] - public void CallingReplayAndThenReplayAll() - { - mocks.Replay(demo); - mocks.ReplayAll(); - } - - - [Fact] - public void CallingVerifyAndThenVerifyAll() - { - mocks.ReplayAll(); - mocks.Verify(demo); - mocks.VerifyAll(); - } - - [Fact] - public void CallingVerifyWithoutReplayFirstCauseException() - { - Assert.Throws( - "This action is invalid when the mock object {Rhino.Mocks.Tests.IDemo} is in record state.", - () => mocks.Verify(demo)); - } - - [Fact] - public void UsingVerifiedObjectThrows() - { - mocks.Replay(demo); - mocks.Verify(demo); - Assert.Throws( - "This action is invalid when the mock object is in verified state.", - () => demo.ReturnIntNoArgs()); - } - - - [Fact] - public void CallingLastMethodOptionsOnReplay() - { - demo.VoidNoArgs(); - mocks.Replay(demo); - Assert.Throws( - "This action is invalid when the mock object is in replay state.", - () => LastCall.On(demo)); - } - - [Fact] - public void NotClosingMethodBeforeReplaying() - { - demo.StringArgString(""); - Assert.Throws( - "Previous method 'IDemo.StringArgString(\"\");' requires a return value or an exception to throw.", - () => mocks.Replay(demo)); - } - - [Fact] - public void GetmocksFromProxy() - { - IMockedObject mockedObj = demo as IMockedObject; - Assert.NotNull(mockedObj); - MockRepository MockRepository = mockedObj.Repository; - Assert.NotNull(MockRepository); - Assert.Same(mocks, MockRepository); - } - - [Fact] - public void CallingLastCallWithoutHavingLastCallThrows() - { - Assert.Throws( - "There is no matching last call on this object. Are you sure that the last call was a virtual or interface method call?", - () => LastCall.On(demo)); - } - - [Fact] - public void SetReturnValue() - { - demo.ReturnStringNoArgs(); - string retVal = "Ayende"; - LastCall.On(demo).Return(retVal); - mocks.Replay(demo); - Assert.Equal(retVal, demo.ReturnStringNoArgs()); - mocks.Verify(demo); - } - - [Fact] - public void SetReturnValueAndNumberOfRepeats() - { - demo.ReturnStringNoArgs(); - string retVal = "Ayende"; - LastCall.On(demo).Return(retVal).Repeat.Twice(); - mocks.Replay(demo); - Assert.Equal(retVal, demo.ReturnStringNoArgs()); - Assert.Equal(retVal, demo.ReturnStringNoArgs()); - mocks.Verify(demo); - } - - [Fact] - public void SetMethodToThrow() - { - demo.VoidStringArg("test"); - LastCall.On(demo).Throw(new ArgumentException("Reserved value, must be zero")); - mocks.Replay(demo); - Assert.Throws("Reserved value, must be zero", - () => demo.VoidStringArg("test")); - } - - [Fact] - public void SettingMethodToThrowTwice() - { - demo.VoidStringArg("test"); - string exceptionMessage = "Reserved value, must be zero"; - LastCall.On(demo).Throw(new ArgumentException(exceptionMessage)).Repeat.Twice(); - mocks.Replay(demo); - for (int i = 0; i < 2; i++) - { - try - { - demo.VoidStringArg("test"); - Assert.False(true, "Expected exception"); - } - catch (ArgumentException e) - { - Assert.Equal(exceptionMessage, e.Message); - } - } - } - - [Fact] - public void ReturnningValueType() - { - demo.ReturnIntNoArgs(); - LastCall.On(demo).Return(2); - mocks.Replay(demo); - Assert.Equal(2, demo.ReturnIntNoArgs()); - } - - [Fact] - public void CallingSecondMethodWithoutSetupRequiredInfoOnFirstOne() - { - demo.ReturnIntNoArgs(); - Assert.Throws( - "Previous method 'IDemo.ReturnIntNoArgs();' requires a return value or an exception to throw.", - () => demo.ReturnIntNoArgs()); - } - - [Fact] - public void TryingToSetUnrelatedTypeAsReturnValueThrows() - { - demo.ReturnIntNoArgs(); - Assert.Throws( - "Type 'System.DateTime' doesn't match the return type 'System.Int32' for method 'IDemo.ReturnIntNoArgs();'", - () => LastCall.On(demo).Return(new DateTime())); - } - - [Fact] - public void ReturnNullForValueType() - { - demo.ReturnIntNoArgs(); - Assert.Throws( - "Type 'null' doesn't match the return type 'System.Int32' for method 'IDemo.ReturnIntNoArgs();'", - () => LastCall.On(demo).Return(null)); - } - - [Fact] - public void ReturnValueForVoidMethod() - { - demo.VoidNoArgs(); - Assert.Throws( - "Type 'System.Int32' doesn't match the return type 'System.Void' for method 'IDemo.VoidNoArgs();'", - () => LastCall.On(demo).Return(3)); - } - - [Fact] - public void ReturnDerivedType() - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(DemoEnum.Demo); - } - - [Fact] - public void SetExceptionAndThenSetReturn() - { - demo.EnumNoArgs(); - LastCall.On(demo).Throw(new Exception()); - demo.EnumNoArgs(); - LastCall.On(demo).Return(DemoEnum.Demo); - mocks.Replay(demo); - try - { - demo.EnumNoArgs(); - Assert.False(true, "Expected exception"); - } - catch (Exception) - { - } - DemoEnum d = DemoEnum.NonDemo; - d = (DemoEnum)demo.EnumNoArgs(); - Assert.Equal(d, DemoEnum.Demo); - } - - [Fact] - public void SetReturnValueAndExceptionThrows() - { - demo.EnumNoArgs(); - LastCall.On(demo).Throw(new Exception()); - Assert.Throws( - "Can set only a single return value or exception to throw or delegate to execute on the same method call.", - () => LastCall.On(demo).Return(DemoEnum.Demo)); - } - - [Fact] - public void SetExceptionAndThenThrows() - { - demo.EnumNoArgs(); - LastCall.On(demo).Throw(new Exception()); - Assert.Throws( - "Can set only a single return value or exception to throw or delegate to execute on the same method call.", - () => LastCall.On(demo).Return(DemoEnum.Demo)); - } - - [Fact] - public void SetTwoReturnValues() - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(DemoEnum.Demo); - Assert.Throws( - "Can set only a single return value or exception to throw or delegate to execute on the same method call.", - () => LastCall.On(demo).Return(DemoEnum.Demo)); - } - - [Fact] - public void SetTwoExceptions() - { - demo.EnumNoArgs(); - LastCall.On(demo).Throw(new Exception()); - Assert.Throws( - "Can set only a single return value or exception to throw or delegate to execute on the same method call.", - () => LastCall.On(demo).Throw(new Exception())); - - } - - [Fact] - public void ExpectMethodOnce() - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(DemoEnum.NonDemo).Repeat.Once(); - mocks.Replay(demo); - DemoEnum d = (DemoEnum)demo.EnumNoArgs(); - Assert.Equal(d, DemoEnum.NonDemo); - try - { - demo.EnumNoArgs(); - Assert.False(true, "Expected exception"); - } - catch (ExpectationViolationException e) - { - Assert.Equal("IDemo.EnumNoArgs(); Expected #1, Actual #2.", e.Message); - } - } - - [Fact] - public void ExpectMethodAlways() - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(DemoEnum.NonDemo).Repeat.Any(); - mocks.Replay(demo); - demo.EnumNoArgs(); - demo.EnumNoArgs(); - demo.EnumNoArgs(); - mocks.Verify(demo); - } - - [Fact] - public void DifferentArgumentsCauseException() - { - demo.VoidStringArg("Hello"); - mocks.Replay(demo); - Assert.Throws( - "IDemo.VoidStringArg(\"World\"); Expected #0, Actual #1.\r\nIDemo.VoidStringArg(\"Hello\"); Expected #1, Actual #0.", - () => demo.VoidStringArg("World")); - } - - [Fact] - public void VerifyingArguments() - { - demo.VoidStringArg("Hello"); - mocks.Replay(demo); - demo.VoidStringArg("Hello"); - mocks.Verify(demo); - } - - [Fact] - public void IgnoreArgument() - { - demo.VoidStringArg("Hello"); - LastCall.On(demo).IgnoreArguments(); - mocks.Replay(demo); - demo.VoidStringArg("World"); - mocks.Verify(demo); - } - - [Fact] - public void IgnoreArgsAndReturnValue() - { - demo.StringArgString("Hello"); - string objToReturn = "World"; - LastCall.On(demo).IgnoreArguments().Repeat.Twice().Return(objToReturn); - mocks.Replay(demo); - Assert.Equal(objToReturn, demo.StringArgString("foo")); - Assert.Equal(objToReturn, demo.StringArgString("bar")); - mocks.Verify(demo); - } - - [Fact] - public void RepeatThreeTimes() - { - demo.StringArgString("Hello"); - string objToReturn = "World"; - LastCall.On(demo).IgnoreArguments().Repeat.Times(3).Return(objToReturn); - mocks.Replay(demo); - Assert.Equal(objToReturn, demo.StringArgString("foo")); - Assert.Equal(objToReturn, demo.StringArgString("bar")); - Assert.Equal(objToReturn, demo.StringArgString("bar")); - mocks.Verify(demo); - } - - [Fact] - public void RepeatOneToThreeTimes() - { - demo.StringArgString("Hello"); - string objToReturn = "World"; - LastCall.On(demo).IgnoreArguments().Repeat.Times(1, 3).Return(objToReturn); - mocks.Replay(demo); - Assert.Equal(objToReturn, demo.StringArgString("foo")); - Assert.Equal(objToReturn, demo.StringArgString("bar")); - mocks.Verify(demo); - } - - [Fact] - public void ThrowingExceptions() - { - demo.StringArgString("Ayende"); - LastCall.On(demo).Throw(new Exception("Ugh! It's alive!")).IgnoreArguments(); - mocks.Replay(demo); - Assert.Throws("Ugh! It's alive!", - () => demo.StringArgString(null)); - } - - - [Fact] - public void ThrowingExceptionsWhenOrdered() - { - using (mocks.Ordered()) - { - demo.StringArgString("Ayende"); - LastCall.On(demo).Throw(new Exception("Ugh! It's alive!")).IgnoreArguments(); - } - mocks.Replay(demo); - Assert.Throws("Ugh! It's alive!", - () => demo.StringArgString(null)); - } - - [Fact] - public void ExpectationExceptionWhileUsingDisposableThrowTheCorrectExpectation() - { - mocks.Replay(demo); - Assert.Throws( - "IDemo.VoidNoArgs(); Expected #0, Actual #1.", - () => demo.VoidNoArgs()); - } - - [Fact] - public void MockObjectThrowsForUnexpectedCall() - { - MockRepository mocks = new MockRepository(); - IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); - mocks.ReplayAll(); - Assert.Throws( - "IDemo.VoidNoArgs(); Expected #0, Actual #1.", - () => demo.VoidNoArgs()); - } - - - - [Fact] - public void MockObjectThrowsForUnexpectedCall_WhenVerified_IfFirstExceptionWasCaught() - { - MockRepository mocks = new MockRepository(); - IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); - mocks.ReplayAll(); - try - { - demo.VoidNoArgs(); - } - catch (Exception) { } - Assert.Throws( - "IDemo.VoidNoArgs(); Expected #0, Actual #1.", - () => mocks.VerifyAll()); - } - - [Fact] - public void DyamicMockAcceptUnexpectedCall() - { - MockRepository mocks = new MockRepository(); - IDemo demo = (IDemo)mocks.DynamicMock(typeof(IDemo)); - mocks.ReplayAll(); - demo.VoidNoArgs(); - mocks.VerifyAll(); - } - - [Fact] - public void RepositoryThrowsWithConstructorArgsForMockInterface() - { - MockRepository mocks = new MockRepository(); - Assert.Throws(() => - { - IDemo demo = (IDemo) mocks.StrictMock(typeof (IDemo), "Foo"); - }); - } - - [Fact] - public void RepositoryThrowsWithConstructorArgsForMockDelegate() - { - MockRepository mocks = new MockRepository(); - Assert.Throws(() => - { - EventHandler handler = (EventHandler) mocks.StrictMock(typeof (EventHandler), "Foo"); - }); - } - - [Fact] - public void RepositoryThrowsWithWrongConstructorArgsForMockClass() - { - MockRepository mocks = new MockRepository(); - // There is no constructor on object that takes a string - // parameter, so this should fail. - try - { - object o = mocks.StrictMock(typeof(object), "Foo"); - - Assert.False(true, "The above call should have failed"); - } - catch(ArgumentException argEx) - { - Assert.Contains("Can not instantiate proxy of class: System.Object.", argEx.Message); - } - } - - [Fact] - public void IsInReplayModeThrowsWhenPassedNull() - { - Assert.Throws(() => mocks.IsInReplayMode(null)); - } - - [Fact] - public void IsInReplayModeThrowsWhenPassedNonMock() - { - Assert.Throws(() => mocks.IsInReplayMode(new object())); - } - - [Fact] - public void IsInReplayModeReturnsTrueWhenMockInReplay() - { - mocks.Replay(demo); - - Assert.True(mocks.IsInReplayMode(demo)); - } - - [Fact] - public void IsInReplayModeReturnsFalseWhenMockInRecord() - { - Assert.False(mocks.IsInReplayMode(demo)); - } - - [Fact] - public void GenerateMockForClassWithNoDefaultConstructor() - { - Assert.NotNull(MockRepository.GenerateMock(null, 0)); - } - - [Fact] - public void GenerateMockForClassWithDefaultConstructor() - { - Assert.NotNull(MockRepository.GenerateMock()); - } - - [Fact] - public void GenerateMockForInterface() - { - Assert.NotNull(MockRepository.GenerateMock()); - } - - [Fact] - public void GenerateStrictMockWithRemoting() - { - IDemo mock = MockRepository.GenerateStrictMockWithRemoting(); - Assert.NotNull(mock); -#if DOTNET35 - Assert.True(mock.GetMockRepository().IsInReplayMode(mock)); -#endif - } - - [Fact] - public void GenerateDynamicMockWithRemoting() - { - IDemo mock = MockRepository.GenerateDynamicMockWithRemoting(); - Assert.NotNull(mock); -#if DOTNET35 - Assert.True(mock.GetMockRepository().IsInReplayMode(mock)); -#endif - } - - public class ClassWithNonDefaultConstructor - { - public ClassWithNonDefaultConstructor(string someString, int someInt) {} - } - public class ClassWithDefaultConstructor {} - - #region Implementation - - private enum DemoEnum - { - Demo, - NonDemo - } - - #endregion - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Interfaces; + +namespace Rhino.Mocks.Tests +{ + + public class MockRepositoryTests + { + private MockRepository mocks; + private IDemo demo; + + public MockRepositoryTests() + { + mocks = new MockRepository(); + demo = this.mocks.StrictMock(typeof(IDemo)) as IDemo; + } + + [Fact] + public void CreatesNewMockObject() + { + Assert.NotNull(demo); + } + + [Fact] + public void CallMethodOnMockObject() + { + demo.ReturnStringNoArgs(); + } + + [Fact] + public void RecordWithBadReplayCauseException() + { + demo.ReturnStringNoArgs(); + LastCall.On(demo).Return(null); + mocks.Replay(demo); + Assert.Throws( + "IDemo.ReturnStringNoArgs(); Expected #1, Actual #0.", + () => mocks.Verify(demo)); + } + + [Fact] + public void RecordTwoMethodsButReplayOneCauseException() + { + demo.ReturnStringNoArgs(); + LastCall.On(demo).Return(null).Repeat.Twice(); + mocks.Replay(demo); + demo.ReturnStringNoArgs(); + Assert.Throws( + "IDemo.ReturnStringNoArgs(); Expected #2, Actual #1.", + () => mocks.Verify(demo)); + } + + [Fact] + public void CallingReplayOnNonMockThrows() + { + MockRepository mocks = new MockRepository(); + Assert.Throws( + "The object is not a mock object that belong to this repository.", + () => mocks.Replay(new object())); + } + + [Fact] + public void CallingVerifyOnNonMockThrows() + { + MockRepository mocks = new MockRepository(); + Assert.Throws( + "The object is not a mock object that belong to this repository.", + () => mocks.Verify(new object())); + } + + [Fact] + public void TryingToReplayMockMoreThanOnceThrows() + { + mocks.Replay(demo); + Assert.Throws( + "This action is invalid when the mock object is in replay state.", + () => mocks.Replay(demo)); + } + + [Fact] + public void CallingReplayAndThenReplayAll() + { + mocks.Replay(demo); + mocks.ReplayAll(); + } + + + [Fact] + public void CallingVerifyAndThenVerifyAll() + { + mocks.ReplayAll(); + mocks.Verify(demo); + mocks.VerifyAll(); + } + + [Fact] + public void CallingVerifyWithoutReplayFirstCauseException() + { + Assert.Throws( + "This action is invalid when the mock object {Rhino.Mocks.Tests.IDemo} is in record state.", + () => mocks.Verify(demo)); + } + + [Fact] + public void UsingVerifiedObjectThrows() + { + mocks.Replay(demo); + mocks.Verify(demo); + Assert.Throws( + "This action is invalid when the mock object is in verified state.", + () => demo.ReturnIntNoArgs()); + } + + + [Fact] + public void CallingLastMethodOptionsOnReplay() + { + demo.VoidNoArgs(); + mocks.Replay(demo); + Assert.Throws( + "This action is invalid when the mock object is in replay state.", + () => LastCall.On(demo)); + } + + [Fact] + public void NotClosingMethodBeforeReplaying() + { + demo.StringArgString(""); + Assert.Throws( + "Previous method 'IDemo.StringArgString(\"\");' requires a return value or an exception to throw.", + () => mocks.Replay(demo)); + } + + [Fact] + public void GetmocksFromProxy() + { + IMockedObject mockedObj = demo as IMockedObject; + Assert.NotNull(mockedObj); + MockRepository MockRepository = mockedObj.Repository; + Assert.NotNull(MockRepository); + Assert.Same(mocks, MockRepository); + } + + [Fact] + public void CallingLastCallWithoutHavingLastCallThrows() + { + Assert.Throws( + "There is no matching last call on this object. Are you sure that the last call was a virtual or interface method call?", + () => LastCall.On(demo)); + } + + [Fact] + public void SetReturnValue() + { + demo.ReturnStringNoArgs(); + string retVal = "Ayende"; + LastCall.On(demo).Return(retVal); + mocks.Replay(demo); + Assert.Equal(retVal, demo.ReturnStringNoArgs()); + mocks.Verify(demo); + } + + [Fact] + public void SetReturnValueAndNumberOfRepeats() + { + demo.ReturnStringNoArgs(); + string retVal = "Ayende"; + LastCall.On(demo).Return(retVal).Repeat.Twice(); + mocks.Replay(demo); + Assert.Equal(retVal, demo.ReturnStringNoArgs()); + Assert.Equal(retVal, demo.ReturnStringNoArgs()); + mocks.Verify(demo); + } + + [Fact] + public void SetMethodToThrow() + { + demo.VoidStringArg("test"); + LastCall.On(demo).Throw(new ArgumentException("Reserved value, must be zero")); + mocks.Replay(demo); + Assert.Throws("Reserved value, must be zero", + () => demo.VoidStringArg("test")); + } + + [Fact] + public void SettingMethodToThrowTwice() + { + demo.VoidStringArg("test"); + string exceptionMessage = "Reserved value, must be zero"; + LastCall.On(demo).Throw(new ArgumentException(exceptionMessage)).Repeat.Twice(); + mocks.Replay(demo); + for (int i = 0; i < 2; i++) + { + try + { + demo.VoidStringArg("test"); + Assert.False(true, "Expected exception"); + } + catch (ArgumentException e) + { + Assert.Equal(exceptionMessage, e.Message); + } + } + } + + [Fact] + public void ReturnningValueType() + { + demo.ReturnIntNoArgs(); + LastCall.On(demo).Return(2); + mocks.Replay(demo); + Assert.Equal(2, demo.ReturnIntNoArgs()); + } + + [Fact] + public void CallingSecondMethodWithoutSetupRequiredInfoOnFirstOne() + { + demo.ReturnIntNoArgs(); + Assert.Throws( + "Previous method 'IDemo.ReturnIntNoArgs();' requires a return value or an exception to throw.", + () => demo.ReturnIntNoArgs()); + } + + [Fact] + public void TryingToSetUnrelatedTypeAsReturnValueThrows() + { + demo.ReturnIntNoArgs(); + Assert.Throws( + "Type 'System.DateTime' doesn't match the return type 'System.Int32' for method 'IDemo.ReturnIntNoArgs();'", + () => LastCall.On(demo).Return(new DateTime())); + } + + [Fact] + public void ReturnNullForValueType() + { + demo.ReturnIntNoArgs(); + Assert.Throws( + "Type 'null' doesn't match the return type 'System.Int32' for method 'IDemo.ReturnIntNoArgs();'", + () => LastCall.On(demo).Return(null)); + } + + [Fact] + public void ReturnValueForVoidMethod() + { + demo.VoidNoArgs(); + Assert.Throws( + "Type 'System.Int32' doesn't match the return type 'System.Void' for method 'IDemo.VoidNoArgs();'", + () => LastCall.On(demo).Return(3)); + } + + [Fact] + public void ReturnDerivedType() + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(DemoEnum.Demo); + } + + [Fact] + public void SetExceptionAndThenSetReturn() + { + demo.EnumNoArgs(); + LastCall.On(demo).Throw(new Exception()); + demo.EnumNoArgs(); + LastCall.On(demo).Return(DemoEnum.Demo); + mocks.Replay(demo); + try + { + demo.EnumNoArgs(); + Assert.False(true, "Expected exception"); + } + catch (Exception) + { + } + DemoEnum d = DemoEnum.NonDemo; + d = (DemoEnum)demo.EnumNoArgs(); + Assert.Equal(d, DemoEnum.Demo); + } + + [Fact] + public void SetReturnValueAndExceptionThrows() + { + demo.EnumNoArgs(); + LastCall.On(demo).Throw(new Exception()); + Assert.Throws( + "Can set only a single return value or exception to throw or delegate to execute on the same method call.", + () => LastCall.On(demo).Return(DemoEnum.Demo)); + } + + [Fact] + public void SetExceptionAndThenThrows() + { + demo.EnumNoArgs(); + LastCall.On(demo).Throw(new Exception()); + Assert.Throws( + "Can set only a single return value or exception to throw or delegate to execute on the same method call.", + () => LastCall.On(demo).Return(DemoEnum.Demo)); + } + + [Fact] + public void SetTwoReturnValues() + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(DemoEnum.Demo); + Assert.Throws( + "Can set only a single return value or exception to throw or delegate to execute on the same method call.", + () => LastCall.On(demo).Return(DemoEnum.Demo)); + } + + [Fact] + public void SetTwoExceptions() + { + demo.EnumNoArgs(); + LastCall.On(demo).Throw(new Exception()); + Assert.Throws( + "Can set only a single return value or exception to throw or delegate to execute on the same method call.", + () => LastCall.On(demo).Throw(new Exception())); + + } + + [Fact] + public void ExpectMethodOnce() + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(DemoEnum.NonDemo).Repeat.Once(); + mocks.Replay(demo); + DemoEnum d = (DemoEnum)demo.EnumNoArgs(); + Assert.Equal(d, DemoEnum.NonDemo); + try + { + demo.EnumNoArgs(); + Assert.False(true, "Expected exception"); + } + catch (ExpectationViolationException e) + { + Assert.Equal("IDemo.EnumNoArgs(); Expected #1, Actual #2.", e.Message); + } + } + + [Fact] + public void ExpectMethodAlways() + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(DemoEnum.NonDemo).Repeat.Any(); + mocks.Replay(demo); + demo.EnumNoArgs(); + demo.EnumNoArgs(); + demo.EnumNoArgs(); + mocks.Verify(demo); + } + + [Fact] + public void DifferentArgumentsCauseException() + { + demo.VoidStringArg("Hello"); + mocks.Replay(demo); + Assert.Throws( + "IDemo.VoidStringArg(\"World\"); Expected #0, Actual #1.\r\nIDemo.VoidStringArg(\"Hello\"); Expected #1, Actual #0.", + () => demo.VoidStringArg("World")); + } + + [Fact] + public void VerifyingArguments() + { + demo.VoidStringArg("Hello"); + mocks.Replay(demo); + demo.VoidStringArg("Hello"); + mocks.Verify(demo); + } + + [Fact] + public void IgnoreArgument() + { + demo.VoidStringArg("Hello"); + LastCall.On(demo).IgnoreArguments(); + mocks.Replay(demo); + demo.VoidStringArg("World"); + mocks.Verify(demo); + } + + [Fact] + public void IgnoreArgsAndReturnValue() + { + demo.StringArgString("Hello"); + string objToReturn = "World"; + LastCall.On(demo).IgnoreArguments().Repeat.Twice().Return(objToReturn); + mocks.Replay(demo); + Assert.Equal(objToReturn, demo.StringArgString("foo")); + Assert.Equal(objToReturn, demo.StringArgString("bar")); + mocks.Verify(demo); + } + + [Fact] + public void RepeatThreeTimes() + { + demo.StringArgString("Hello"); + string objToReturn = "World"; + LastCall.On(demo).IgnoreArguments().Repeat.Times(3).Return(objToReturn); + mocks.Replay(demo); + Assert.Equal(objToReturn, demo.StringArgString("foo")); + Assert.Equal(objToReturn, demo.StringArgString("bar")); + Assert.Equal(objToReturn, demo.StringArgString("bar")); + mocks.Verify(demo); + } + + [Fact] + public void RepeatOneToThreeTimes() + { + demo.StringArgString("Hello"); + string objToReturn = "World"; + LastCall.On(demo).IgnoreArguments().Repeat.Times(1, 3).Return(objToReturn); + mocks.Replay(demo); + Assert.Equal(objToReturn, demo.StringArgString("foo")); + Assert.Equal(objToReturn, demo.StringArgString("bar")); + mocks.Verify(demo); + } + + [Fact] + public void ThrowingExceptions() + { + demo.StringArgString("Ayende"); + LastCall.On(demo).Throw(new Exception("Ugh! It's alive!")).IgnoreArguments(); + mocks.Replay(demo); + Assert.Throws("Ugh! It's alive!", + () => demo.StringArgString(null)); + } + + + [Fact] + public void ThrowingExceptionsWhenOrdered() + { + using (mocks.Ordered()) + { + demo.StringArgString("Ayende"); + LastCall.On(demo).Throw(new Exception("Ugh! It's alive!")).IgnoreArguments(); + } + mocks.Replay(demo); + Assert.Throws("Ugh! It's alive!", + () => demo.StringArgString(null)); + } + + [Fact] + public void ExpectationExceptionWhileUsingDisposableThrowTheCorrectExpectation() + { + mocks.Replay(demo); + Assert.Throws( + "IDemo.VoidNoArgs(); Expected #0, Actual #1.", + () => demo.VoidNoArgs()); + } + + [Fact] + public void MockObjectThrowsForUnexpectedCall() + { + MockRepository mocks = new MockRepository(); + IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); + mocks.ReplayAll(); + Assert.Throws( + "IDemo.VoidNoArgs(); Expected #0, Actual #1.", + () => demo.VoidNoArgs()); + } + + + + [Fact] + public void MockObjectThrowsForUnexpectedCall_WhenVerified_IfFirstExceptionWasCaught() + { + MockRepository mocks = new MockRepository(); + IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); + mocks.ReplayAll(); + try + { + demo.VoidNoArgs(); + } + catch (Exception) { } + Assert.Throws( + "IDemo.VoidNoArgs(); Expected #0, Actual #1.", + () => mocks.VerifyAll()); + } + + [Fact] + public void DyamicMockAcceptUnexpectedCall() + { + MockRepository mocks = new MockRepository(); + IDemo demo = (IDemo)mocks.DynamicMock(typeof(IDemo)); + mocks.ReplayAll(); + demo.VoidNoArgs(); + mocks.VerifyAll(); + } + + [Fact] + public void RepositoryThrowsWithConstructorArgsForMockInterface() + { + MockRepository mocks = new MockRepository(); + Assert.Throws(() => + { + IDemo demo = (IDemo) mocks.StrictMock(typeof (IDemo), "Foo"); + }); + } + + [Fact] + public void RepositoryThrowsWithConstructorArgsForMockDelegate() + { + MockRepository mocks = new MockRepository(); + Assert.Throws(() => + { + EventHandler handler = (EventHandler) mocks.StrictMock(typeof (EventHandler), "Foo"); + }); + } + + [Fact] + public void RepositoryThrowsWithWrongConstructorArgsForMockClass() + { + MockRepository mocks = new MockRepository(); + // There is no constructor on object that takes a string + // parameter, so this should fail. + try + { + object o = mocks.StrictMock(typeof(object), "Foo"); + + Assert.False(true, "The above call should have failed"); + } + catch(ArgumentException argEx) + { + Assert.Contains("Can not instantiate proxy of class: System.Object.", argEx.Message); + } + } + + [Fact] + public void IsInReplayModeThrowsWhenPassedNull() + { + Assert.Throws(() => mocks.IsInReplayMode(null)); + } + + [Fact] + public void IsInReplayModeThrowsWhenPassedNonMock() + { + Assert.Throws(() => mocks.IsInReplayMode(new object())); + } + + [Fact] + public void IsInReplayModeReturnsTrueWhenMockInReplay() + { + mocks.Replay(demo); + + Assert.True(mocks.IsInReplayMode(demo)); + } + + [Fact] + public void IsInReplayModeReturnsFalseWhenMockInRecord() + { + Assert.False(mocks.IsInReplayMode(demo)); + } + + [Fact] + public void GenerateMockForClassWithNoDefaultConstructor() + { + Assert.NotNull(MockRepository.GenerateMock(null, 0)); + } + + [Fact] + public void GenerateMockForClassWithDefaultConstructor() + { + Assert.NotNull(MockRepository.GenerateMock()); + } + + [Fact] + public void GenerateMockForInterface() + { + Assert.NotNull(MockRepository.GenerateMock()); + } + + [Fact] + public void GenerateStrictMockWithRemoting() + { + IDemo mock = MockRepository.GenerateStrictMockWithRemoting(); + Assert.NotNull(mock); +#if DOTNET35 + Assert.True(mock.GetMockRepository().IsInReplayMode(mock)); +#endif + } + + [Fact] + public void GenerateDynamicMockWithRemoting() + { + IDemo mock = MockRepository.GenerateDynamicMockWithRemoting(); + Assert.NotNull(mock); +#if DOTNET35 + Assert.True(mock.GetMockRepository().IsInReplayMode(mock)); +#endif + } + + public class ClassWithNonDefaultConstructor + { + public ClassWithNonDefaultConstructor(string someString, int someInt) {} + } + public class ClassWithDefaultConstructor {} + + #region Implementation + + private enum DemoEnum + { + Demo, + NonDemo + } + + #endregion + } +} diff --git a/Rhino.Mocks.Tests/MockWithRefAndOutParams.cs b/Rhino.Mocks.Tests/MockWithRefAndOutParams.cs index 4ac013d5..a67f17b2 100644 --- a/Rhino.Mocks.Tests/MockWithRefAndOutParams.cs +++ b/Rhino.Mocks.Tests/MockWithRefAndOutParams.cs @@ -1,196 +1,196 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Text; -using Xunit; - -namespace Rhino.Mocks.Tests -{ - - public class MockWithRefAndOutParams - { - MockRepository mocks; - IRefAndOut target; - private RemotingProxyWithOutRef remotingTarget; - - public MockWithRefAndOutParams() - { - mocks = new MockRepository(); - target = (IRefAndOut)mocks.StrictMock(typeof(IRefAndOut)); - remotingTarget = mocks.StrictMock(); - } - - [Fact] - public void RefString() - { - string s = ""; - target.RefStr(ref s); - LastCall.Do(new RefStrDel(SayHello)); - mocks.ReplayAll(); - target.RefStr(ref s); - Assert.Equal("Hello", s); - } - - [Fact] - public void OutString() - { - string s = ""; - target.OutStr(out s); - LastCall.Do(new OutStrDel(OutSayHello)); - mocks.ReplayAll(); - target.OutStr(out s); - Assert.Equal("Hello", s); - } - - [Fact] - public void OutInt() - { - int i = 0; - target.OutInt(out i); - LastCall.Do(new OutIntDel(OutFive)); - mocks.ReplayAll(); - target.OutInt(out i); - Assert.Equal(5, i); - } - - [Fact] - public void RefInt() - { - int i = 0; - target.RefInt(ref i); - LastCall.Do(new RefIntDel(RefFive)); - mocks.ReplayAll(); - target.RefInt(ref i); - Assert.Equal(5, i); - } - - - [Fact] - public void RemotingRefString() - { - string s = ""; - remotingTarget.RefStr(ref s); - LastCall.Do(new RefStrDel(SayHello)); - mocks.ReplayAll(); - remotingTarget.RefStr(ref s); - Assert.Equal("Hello", s); - } - - [Fact] - public void RemotingOutString() - { - string s = ""; - remotingTarget.OutStr(out s); - LastCall.Do(new OutStrDel(OutSayHello)); - mocks.ReplayAll(); - remotingTarget.OutStr(out s); - Assert.Equal("Hello", s); - } - - [Fact] - public void RemotingOutInt() - { - int i = 0; - remotingTarget.OutInt(out i); - LastCall.Do(new OutIntDel(OutFive)); - mocks.ReplayAll(); - remotingTarget.OutInt(out i); - Assert.Equal(5, i); - } - - [Fact] - public void RemotingRefInt() - { - int i = 0; - remotingTarget.RefInt(ref i); - LastCall.Do(new RefIntDel(RefFive)); - mocks.ReplayAll(); - remotingTarget.RefInt(ref i); - Assert.Equal(5, i); - } - - private void RefFive(ref int i) - { - i = 5; - } - - private void SayHello(ref string s) - { - s = "Hello"; - } - - private void OutFive(out int i) - { - i = 5; - } - - private void OutSayHello(out string s) - { - s = "Hello"; - } - - public delegate void RefStrDel(ref string s); - public delegate void RefIntDel(ref int i); - public delegate void OutStrDel(out string s); - public delegate void OutIntDel(out int i); - - } - - public interface IRefAndOut - { - void RefInt(ref int i); - void RefStr(ref string s); - - void OutStr(out string s); - void OutInt(out int i); - } - - public class RemotingProxyWithOutRef : MarshalByRefObject - { - public void RefInt(ref int i) - { - i = 2; - } - - public void RefStr(ref string s) - { - s = "b"; - } - - public void OutStr(out string s) - { - s = "a"; - } - public void OutInt(out int i) - { - i = 1; - } - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Text; +using Xunit; + +namespace Rhino.Mocks.Tests +{ + + public class MockWithRefAndOutParams + { + MockRepository mocks; + IRefAndOut target; + private RemotingProxyWithOutRef remotingTarget; + + public MockWithRefAndOutParams() + { + mocks = new MockRepository(); + target = (IRefAndOut)mocks.StrictMock(typeof(IRefAndOut)); + remotingTarget = mocks.StrictMock(); + } + + [Fact] + public void RefString() + { + string s = ""; + target.RefStr(ref s); + LastCall.Do(new RefStrDel(SayHello)); + mocks.ReplayAll(); + target.RefStr(ref s); + Assert.Equal("Hello", s); + } + + [Fact] + public void OutString() + { + string s = ""; + target.OutStr(out s); + LastCall.Do(new OutStrDel(OutSayHello)); + mocks.ReplayAll(); + target.OutStr(out s); + Assert.Equal("Hello", s); + } + + [Fact] + public void OutInt() + { + int i = 0; + target.OutInt(out i); + LastCall.Do(new OutIntDel(OutFive)); + mocks.ReplayAll(); + target.OutInt(out i); + Assert.Equal(5, i); + } + + [Fact] + public void RefInt() + { + int i = 0; + target.RefInt(ref i); + LastCall.Do(new RefIntDel(RefFive)); + mocks.ReplayAll(); + target.RefInt(ref i); + Assert.Equal(5, i); + } + + + [Fact] + public void RemotingRefString() + { + string s = ""; + remotingTarget.RefStr(ref s); + LastCall.Do(new RefStrDel(SayHello)); + mocks.ReplayAll(); + remotingTarget.RefStr(ref s); + Assert.Equal("Hello", s); + } + + [Fact] + public void RemotingOutString() + { + string s = ""; + remotingTarget.OutStr(out s); + LastCall.Do(new OutStrDel(OutSayHello)); + mocks.ReplayAll(); + remotingTarget.OutStr(out s); + Assert.Equal("Hello", s); + } + + [Fact] + public void RemotingOutInt() + { + int i = 0; + remotingTarget.OutInt(out i); + LastCall.Do(new OutIntDel(OutFive)); + mocks.ReplayAll(); + remotingTarget.OutInt(out i); + Assert.Equal(5, i); + } + + [Fact] + public void RemotingRefInt() + { + int i = 0; + remotingTarget.RefInt(ref i); + LastCall.Do(new RefIntDel(RefFive)); + mocks.ReplayAll(); + remotingTarget.RefInt(ref i); + Assert.Equal(5, i); + } + + private void RefFive(ref int i) + { + i = 5; + } + + private void SayHello(ref string s) + { + s = "Hello"; + } + + private void OutFive(out int i) + { + i = 5; + } + + private void OutSayHello(out string s) + { + s = "Hello"; + } + + public delegate void RefStrDel(ref string s); + public delegate void RefIntDel(ref int i); + public delegate void OutStrDel(out string s); + public delegate void OutIntDel(out int i); + + } + + public interface IRefAndOut + { + void RefInt(ref int i); + void RefStr(ref string s); + + void OutStr(out string s); + void OutInt(out int i); + } + + public class RemotingProxyWithOutRef : MarshalByRefObject + { + public void RefInt(ref int i) + { + i = 2; + } + + public void RefStr(ref string s) + { + s = "b"; + } + + public void OutStr(out string s) + { + s = "a"; + } + public void OutInt(out int i) + { + i = 1; + } + } +} diff --git a/Rhino.Mocks.Tests/MockingAbstractClass.cs b/Rhino.Mocks.Tests/MockingAbstractClass.cs index 768b7027..7ae38df7 100644 --- a/Rhino.Mocks.Tests/MockingAbstractClass.cs +++ b/Rhino.Mocks.Tests/MockingAbstractClass.cs @@ -1,103 +1,103 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; - -namespace Rhino.Mocks.Tests -{ - using Xunit; - - - public class MockingAbstractClass : IDisposable - { - private MockRepository mocks; - - public MockingAbstractClass() - { - mocks = new MockRepository(); - } - - public void Dispose() - { - mocks.VerifyAll(); - } - - [Fact] - public void MockAbsPropertyGetter() - { - AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); - Expect.Call(ac.AbPropGet).Return("n"); - mocks.ReplayAll(); - Assert.Equal("n", ac.AbPropGet); - } - - [Fact] - public void MockAbsPropertySetter() - { - AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); - Expect.Call(ac.AbPropSet = "n"); - mocks.ReplayAll(); - ac.AbPropSet = "n"; - } - - - [Fact] - public void MockAbsProp() - { - AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); - Expect.Call(ac.AbProp = "n"); - Expect.Call(ac.AbProp).Return("u"); - mocks.ReplayAll(); - ac.AbProp = "n"; - Assert.Equal("u", ac.AbProp); - } - - [Fact] - public void MockAbstractMethod() - { - AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); - Expect.Call(ac.Method()).Return(45); - mocks.ReplayAll(); - Assert.Equal(45, ac.Method()); - - } - - public abstract class AbsCls - { - public abstract string AbPropGet { get; } - - public abstract string AbPropSet { set; } - - public abstract string AbProp { get; set; } - - public abstract int Method(); - - } - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; + +namespace Rhino.Mocks.Tests +{ + using Xunit; + + + public class MockingAbstractClass : IDisposable + { + private MockRepository mocks; + + public MockingAbstractClass() + { + mocks = new MockRepository(); + } + + public void Dispose() + { + mocks.VerifyAll(); + } + + [Fact] + public void MockAbsPropertyGetter() + { + AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); + Expect.Call(ac.AbPropGet).Return("n"); + mocks.ReplayAll(); + Assert.Equal("n", ac.AbPropGet); + } + + [Fact] + public void MockAbsPropertySetter() + { + AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); + Expect.Call(ac.AbPropSet = "n"); + mocks.ReplayAll(); + ac.AbPropSet = "n"; + } + + + [Fact] + public void MockAbsProp() + { + AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); + Expect.Call(ac.AbProp = "n"); + Expect.Call(ac.AbProp).Return("u"); + mocks.ReplayAll(); + ac.AbProp = "n"; + Assert.Equal("u", ac.AbProp); + } + + [Fact] + public void MockAbstractMethod() + { + AbsCls ac = (AbsCls)mocks.StrictMock(typeof(AbsCls)); + Expect.Call(ac.Method()).Return(45); + mocks.ReplayAll(); + Assert.Equal(45, ac.Method()); + + } + + public abstract class AbsCls + { + public abstract string AbPropGet { get; } + + public abstract string AbPropSet { set; } + + public abstract string AbProp { get; set; } + + public abstract int Method(); + + } + } +} diff --git a/Rhino.Mocks.Tests/MockingClassesTests.cs b/Rhino.Mocks.Tests/MockingClassesTests.cs index 75ec8352..78c1a46a 100644 --- a/Rhino.Mocks.Tests/MockingClassesTests.cs +++ b/Rhino.Mocks.Tests/MockingClassesTests.cs @@ -1,312 +1,312 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Diagnostics; -using System.IO; -using Xunit; -using Rhino.Mocks.Interfaces; - -namespace Rhino.Mocks.Tests -{ - - public class MockingClassesTests - { - private MockRepository mocks; - private DemoClass demoClass; - - public MockingClassesTests() - { - mocks = new MockRepository(); - demoClass = (DemoClass) mocks.StrictMock(typeof (DemoClass)); - } - - - [Fact] - public void MockAClass() - { - IMockedObject mockedObject = demoClass as IMockedObject; - Assert.Equal(mocks, mockedObject.Repository); - } - - [Fact] - public void MockVirtualCall() - { - demoClass.Two(); - LastCall.On(demoClass).Return(3); - mocks.Replay(demoClass); - Assert.Equal(3, demoClass.Two()); - mocks.Verify(demoClass); - } - - [Fact] - public void CantMockNonVirtualCall() - { - demoClass.One(); - Assert.Throws( - "There is no matching last call on this object. Are you sure that the last call was a virtual or interface method call?", - () => LastCall.On(demoClass).Return(3)); - - } - - [Fact] - public void MockClassWithParametrizedCtor() - { - ParametrizedCtor pc = mocks.StrictMock(typeof (ParametrizedCtor), 3, "Hello") as ParametrizedCtor; - Assert.Equal(3, pc.Int); - Assert.Equal("Hello", pc.String); - pc.Add(0, 1); - LastCall.On(pc).Return(10); - mocks.Replay(pc); - Assert.Equal(10, pc.Add(0, 1)); - mocks.Verify(pc); - } - - [Fact] - public void MockClassWithOverloadedCtor() - { - OverLoadedCtor oc = mocks.StrictMock(typeof (OverLoadedCtor), 1) as OverLoadedCtor; - OverLoadCtorExercise(oc, 1, null); - oc = mocks.StrictMock(typeof (OverLoadedCtor), "Hello") as OverLoadedCtor; - OverLoadCtorExercise(oc, 0, "Hello"); - oc = mocks.StrictMock(typeof (OverLoadedCtor), 33, "Hello") as OverLoadedCtor; - OverLoadCtorExercise(oc, 33, "Hello"); - } - - [Fact] - public void BadParamsToCtor() - { - try - { - mocks.StrictMock(typeof(OverLoadedCtor), "Ayende", 55); - - Assert.False(true, "The above call should have failed"); - } - catch (ArgumentException argumentException) - { - Assert.Contains( - "Can not instantiate proxy of class: Rhino.Mocks.Tests.MockingClassesTests+OverLoadedCtor", - argumentException.Message); - } - } - - - [Fact] - public void MockSealedClass() - { - MockRepository mocks = new MockRepository(); - Assert.Throws("Can't create mocks of sealed classes", - () => mocks.StrictMock(typeof (File))); - } - - [Fact] - public void CallNonVirtualMethodThatImplementsAnInterface() - { - ((IDisposable)demoClass).Dispose(); - Assert.Throws( - "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", - () => LastCall.Repeat.Never()); - - } - - - #region Can call object's method without implementing them - - [Fact] - public void ToStringMocked() - { - if (demoClass.ToString()=="") - { - Assert.False(true, "ToString() of a mocked object is empty"); - } - } - - [Fact] - public void GetTypeMocked() - { - Assert.True(typeof (DemoClass).IsAssignableFrom(demoClass.GetType())); - } - - [Fact] - public void GetHashCodeMocked() - { - Assert.Equal(demoClass.GetHashCode(), demoClass.GetHashCode()); - } - - [Fact] - public void EqualsMocked() - { - Assert.True(demoClass.Equals(demoClass)); - } - - #endregion - - #region Classes - - public class DemoClass : IDisposable - { - int _prop; - public bool disposableCalled; - - public virtual int Prop - { - get { return _prop; } - set { _prop = value; } - } - - public int One() - { - return 1; - } - - public virtual int Two() - { - return 2; - } - - void IDisposable.Dispose() - { - disposableCalled = true; - } - } - - public abstract class AbstractDemo - { - public virtual int Five() - { - return 0; - } - - public abstract string Six(); - } - - public class ParametrizedCtor - { - private int i; - private string s; - - public ParametrizedCtor(int i, string s) - { - this.i = i; - this.s = s; - } - - public int Int - { - get { return i; } - set { i = value; } - } - - public string String - { - get { return s; } - set { s = value; } - } - - public virtual int Add(int i1, int i2) - { - return i1 + i2; - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } - - public class OverLoadedCtor - { - private int i; - private string s; - - public OverLoadedCtor(int i) - { - this.i = i; - } - - public OverLoadedCtor(string s) - { - this.s = s; - } - - public OverLoadedCtor(int i, string s) - { - this.i = i; - this.s = s; - } - - public int I - { - get { return i; } - } - - public string S - { - get { return s; } - } - - public virtual string Concat(string s1, string s2) - { - return s1 + s2; - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } - - #endregion - - #region Implementation - - private void OverLoadCtorExercise(OverLoadedCtor oc, int i, string s) - { - Assert.Equal(i, oc.I); - Assert.Equal(s, oc.S); - oc.Concat("Ayende", "Rahien"); - LastCall.On(oc).Return("Hello, World"); - mocks.Replay(oc); - Assert.Equal("Hello, World", oc.Concat("Ayende", "Rahien")); - mocks.Verify(oc); - } - - #endregion - } +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Diagnostics; +using System.IO; +using Xunit; +using Rhino.Mocks.Interfaces; + +namespace Rhino.Mocks.Tests +{ + + public class MockingClassesTests + { + private MockRepository mocks; + private DemoClass demoClass; + + public MockingClassesTests() + { + mocks = new MockRepository(); + demoClass = (DemoClass) mocks.StrictMock(typeof (DemoClass)); + } + + + [Fact] + public void MockAClass() + { + IMockedObject mockedObject = demoClass as IMockedObject; + Assert.Equal(mocks, mockedObject.Repository); + } + + [Fact] + public void MockVirtualCall() + { + demoClass.Two(); + LastCall.On(demoClass).Return(3); + mocks.Replay(demoClass); + Assert.Equal(3, demoClass.Two()); + mocks.Verify(demoClass); + } + + [Fact] + public void CantMockNonVirtualCall() + { + demoClass.One(); + Assert.Throws( + "There is no matching last call on this object. Are you sure that the last call was a virtual or interface method call?", + () => LastCall.On(demoClass).Return(3)); + + } + + [Fact] + public void MockClassWithParametrizedCtor() + { + ParametrizedCtor pc = mocks.StrictMock(typeof (ParametrizedCtor), 3, "Hello") as ParametrizedCtor; + Assert.Equal(3, pc.Int); + Assert.Equal("Hello", pc.String); + pc.Add(0, 1); + LastCall.On(pc).Return(10); + mocks.Replay(pc); + Assert.Equal(10, pc.Add(0, 1)); + mocks.Verify(pc); + } + + [Fact] + public void MockClassWithOverloadedCtor() + { + OverLoadedCtor oc = mocks.StrictMock(typeof (OverLoadedCtor), 1) as OverLoadedCtor; + OverLoadCtorExercise(oc, 1, null); + oc = mocks.StrictMock(typeof (OverLoadedCtor), "Hello") as OverLoadedCtor; + OverLoadCtorExercise(oc, 0, "Hello"); + oc = mocks.StrictMock(typeof (OverLoadedCtor), 33, "Hello") as OverLoadedCtor; + OverLoadCtorExercise(oc, 33, "Hello"); + } + + [Fact] + public void BadParamsToCtor() + { + try + { + mocks.StrictMock(typeof(OverLoadedCtor), "Ayende", 55); + + Assert.False(true, "The above call should have failed"); + } + catch (ArgumentException argumentException) + { + Assert.Contains( + "Can not instantiate proxy of class: Rhino.Mocks.Tests.MockingClassesTests+OverLoadedCtor", + argumentException.Message); + } + } + + + [Fact] + public void MockSealedClass() + { + MockRepository mocks = new MockRepository(); + Assert.Throws("Can't create mocks of sealed classes", + () => mocks.StrictMock(typeof (File))); + } + + [Fact] + public void CallNonVirtualMethodThatImplementsAnInterface() + { + ((IDisposable)demoClass).Dispose(); + Assert.Throws( + "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", + () => LastCall.Repeat.Never()); + + } + + + #region Can call object's method without implementing them + + [Fact] + public void ToStringMocked() + { + if (demoClass.ToString()=="") + { + Assert.False(true, "ToString() of a mocked object is empty"); + } + } + + [Fact] + public void GetTypeMocked() + { + Assert.True(typeof (DemoClass).IsAssignableFrom(demoClass.GetType())); + } + + [Fact] + public void GetHashCodeMocked() + { + Assert.Equal(demoClass.GetHashCode(), demoClass.GetHashCode()); + } + + [Fact] + public void EqualsMocked() + { + Assert.True(demoClass.Equals(demoClass)); + } + + #endregion + + #region Classes + + public class DemoClass : IDisposable + { + int _prop; + public bool disposableCalled; + + public virtual int Prop + { + get { return _prop; } + set { _prop = value; } + } + + public int One() + { + return 1; + } + + public virtual int Two() + { + return 2; + } + + void IDisposable.Dispose() + { + disposableCalled = true; + } + } + + public abstract class AbstractDemo + { + public virtual int Five() + { + return 0; + } + + public abstract string Six(); + } + + public class ParametrizedCtor + { + private int i; + private string s; + + public ParametrizedCtor(int i, string s) + { + this.i = i; + this.s = s; + } + + public int Int + { + get { return i; } + set { i = value; } + } + + public string String + { + get { return s; } + set { s = value; } + } + + public virtual int Add(int i1, int i2) + { + return i1 + i2; + } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + public class OverLoadedCtor + { + private int i; + private string s; + + public OverLoadedCtor(int i) + { + this.i = i; + } + + public OverLoadedCtor(string s) + { + this.s = s; + } + + public OverLoadedCtor(int i, string s) + { + this.i = i; + this.s = s; + } + + public int I + { + get { return i; } + } + + public string S + { + get { return s; } + } + + public virtual string Concat(string s1, string s2) + { + return s1 + s2; + } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + + #endregion + + #region Implementation + + private void OverLoadCtorExercise(OverLoadedCtor oc, int i, string s) + { + Assert.Equal(i, oc.I); + Assert.Equal(s, oc.S); + oc.Concat("Ayende", "Rahien"); + LastCall.On(oc).Return("Hello, World"); + mocks.Replay(oc); + Assert.Equal("Hello, World", oc.Concat("Ayende", "Rahien")); + mocks.Verify(oc); + } + + #endregion + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/MockingDelegatesTests.cs b/Rhino.Mocks.Tests/MockingDelegatesTests.cs index fdd66d6b..56782871 100644 --- a/Rhino.Mocks.Tests/MockingDelegatesTests.cs +++ b/Rhino.Mocks.Tests/MockingDelegatesTests.cs @@ -1,244 +1,244 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.IO; -using System.Reflection; -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Interfaces; - -namespace Rhino.Mocks.Tests -{ - public delegate object ObjectDelegateWithNoParams(); - - - public class MockingDelegatesTests - { - private MockRepository mocks; - private delegate object ObjectDelegateWithNoParams(); - private delegate void VoidDelegateWithParams(string a); - private delegate string StringDelegateWithParams(int a, string b); - private delegate int IntDelegateWithRefAndOutParams(ref int a, out string b); - - public MockingDelegatesTests() - { - mocks = new MockRepository(); - } - - [Fact] - public void CallingMockedDelegatesWithoutOn() - { - ObjectDelegateWithNoParams d1 = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); - Expect.Call(d1()).Return(1); - - mocks.ReplayAll(); - - Assert.Equal(1, d1()); - } - - [Fact] - public void MockTwoDelegatesWithTheSameName() - { - ObjectDelegateWithNoParams d1 = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); - Tests.ObjectDelegateWithNoParams d2 = (Tests.ObjectDelegateWithNoParams)mocks.StrictMock(typeof(Tests.ObjectDelegateWithNoParams)); - - Expect.On(d1).Call(d1()).Return(1); - Expect.On(d2).Call(d2()).Return(2); - - mocks.ReplayAll(); - - Assert.Equal(1, d1()); - Assert.Equal(2, d2()); - - mocks.VerifyAll(); - } - - [Fact] - public void MockObjectDelegateWithNoParams() - { - ObjectDelegateWithNoParams d = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); - - Expect.On(d).Call(d()).Return("abc"); - Expect.On(d).Call(d()).Return("def"); - - mocks.Replay(d); - - Assert.Equal("abc", d()); - Assert.Equal("def", d()); - - try - { - d(); - Assert.False(true, "Expected an expectation violation to occur."); - } - catch (ExpectationViolationException) - { - // Expected. - } - } - - [Fact] - public void MockVoidDelegateWithNoParams() - { - VoidDelegateWithParams d = (VoidDelegateWithParams)mocks.StrictMock(typeof(VoidDelegateWithParams)); - d("abc"); - d("efg"); - - mocks.Replay(d); - - d("abc"); - d("efg"); - - try - { - d("hij"); - Assert.False(true, "Expected an expectation violation to occur."); - } - catch (ExpectationViolationException) - { - // Expected. - } - } - - [Fact] - public void MockStringDelegateWithParams() - { - StringDelegateWithParams d = (StringDelegateWithParams)mocks.StrictMock(typeof(StringDelegateWithParams)); - - Expect.On(d).Call(d(1, "111")).Return("abc"); - Expect.On(d).Call(d(2, "222")).Return("def"); - - mocks.Replay(d); - - Assert.Equal("abc", d(1, "111")); - Assert.Equal("def", d(2, "222")); - - try - { - d(3, "333"); - Assert.False(true, "Expected an expectation violation to occur."); - } - catch (ExpectationViolationException) - { - // Expected. - } - } - - [Fact] - public void MockIntDelegateWithRefAndOutParams() - { - IntDelegateWithRefAndOutParams d = (IntDelegateWithRefAndOutParams)mocks.StrictMock(typeof(IntDelegateWithRefAndOutParams)); - - int a = 3; - string b = null; - Expect.On(d).Call(d(ref a, out b)).Do(new IntDelegateWithRefAndOutParams(Return1_Plus2_A)); - - mocks.Replay(d); - - Assert.Equal(1, d(ref a, out b)); - Assert.Equal(5, a); - Assert.Equal("A", b); - - try - { - d(ref a, out b); - Assert.False(true, "Expected an expectation violation to occur."); - } - catch (ExpectationViolationException) - { - // Expected. - } - - } - - [Fact] - public void InterceptsDynamicInvokeAlso() - { - IntDelegateWithRefAndOutParams d = (IntDelegateWithRefAndOutParams)mocks.StrictMock(typeof(IntDelegateWithRefAndOutParams)); - - int a = 3; - string b = null; - Expect.On(d).Call(d(ref a, out b)).Do(new IntDelegateWithRefAndOutParams(Return1_Plus2_A)); - - mocks.Replay(d); - - object[] args = new object[] { 3, null }; - Assert.Equal(1, d.DynamicInvoke(args)); - Assert.Equal(5, args[0]); - Assert.Equal("A", args[1]); - - try - { - d.DynamicInvoke(args); - Assert.False(true, "Expected an expectation violation to occur."); - } - catch (TargetInvocationException ex) - { - // Expected. - Assert.True(ex.InnerException is ExpectationViolationException); - } - } - - [Fact] - public void DelegateBaseTypeCannotBeMocked() - { - Assert.Throws("Cannot mock the Delegate base type.", - () => mocks.StrictMock(typeof (Delegate))); - } - - private int Return1_Plus2_A(ref int a, out string b) - { - a += 2; - b = "A"; - return 1; - } - - [Fact] - public void GenericDelegate() - { - Action action = mocks.StrictMock>(); - for (int i = 0; i < 10; i++) - { - action(i); - } - mocks.ReplayAll(); - ForEachFromZeroToNine(action); - mocks.VerifyAll(); - } - - private void ForEachFromZeroToNine(Action act) - { - for (int i = 0; i < 10; i++) - { - act(i); - } - } - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.IO; +using System.Reflection; +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Interfaces; + +namespace Rhino.Mocks.Tests +{ + public delegate object ObjectDelegateWithNoParams(); + + + public class MockingDelegatesTests + { + private MockRepository mocks; + private delegate object ObjectDelegateWithNoParams(); + private delegate void VoidDelegateWithParams(string a); + private delegate string StringDelegateWithParams(int a, string b); + private delegate int IntDelegateWithRefAndOutParams(ref int a, out string b); + + public MockingDelegatesTests() + { + mocks = new MockRepository(); + } + + [Fact] + public void CallingMockedDelegatesWithoutOn() + { + ObjectDelegateWithNoParams d1 = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); + Expect.Call(d1()).Return(1); + + mocks.ReplayAll(); + + Assert.Equal(1, d1()); + } + + [Fact] + public void MockTwoDelegatesWithTheSameName() + { + ObjectDelegateWithNoParams d1 = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); + Tests.ObjectDelegateWithNoParams d2 = (Tests.ObjectDelegateWithNoParams)mocks.StrictMock(typeof(Tests.ObjectDelegateWithNoParams)); + + Expect.On(d1).Call(d1()).Return(1); + Expect.On(d2).Call(d2()).Return(2); + + mocks.ReplayAll(); + + Assert.Equal(1, d1()); + Assert.Equal(2, d2()); + + mocks.VerifyAll(); + } + + [Fact] + public void MockObjectDelegateWithNoParams() + { + ObjectDelegateWithNoParams d = (ObjectDelegateWithNoParams)mocks.StrictMock(typeof(ObjectDelegateWithNoParams)); + + Expect.On(d).Call(d()).Return("abc"); + Expect.On(d).Call(d()).Return("def"); + + mocks.Replay(d); + + Assert.Equal("abc", d()); + Assert.Equal("def", d()); + + try + { + d(); + Assert.False(true, "Expected an expectation violation to occur."); + } + catch (ExpectationViolationException) + { + // Expected. + } + } + + [Fact] + public void MockVoidDelegateWithNoParams() + { + VoidDelegateWithParams d = (VoidDelegateWithParams)mocks.StrictMock(typeof(VoidDelegateWithParams)); + d("abc"); + d("efg"); + + mocks.Replay(d); + + d("abc"); + d("efg"); + + try + { + d("hij"); + Assert.False(true, "Expected an expectation violation to occur."); + } + catch (ExpectationViolationException) + { + // Expected. + } + } + + [Fact] + public void MockStringDelegateWithParams() + { + StringDelegateWithParams d = (StringDelegateWithParams)mocks.StrictMock(typeof(StringDelegateWithParams)); + + Expect.On(d).Call(d(1, "111")).Return("abc"); + Expect.On(d).Call(d(2, "222")).Return("def"); + + mocks.Replay(d); + + Assert.Equal("abc", d(1, "111")); + Assert.Equal("def", d(2, "222")); + + try + { + d(3, "333"); + Assert.False(true, "Expected an expectation violation to occur."); + } + catch (ExpectationViolationException) + { + // Expected. + } + } + + [Fact] + public void MockIntDelegateWithRefAndOutParams() + { + IntDelegateWithRefAndOutParams d = (IntDelegateWithRefAndOutParams)mocks.StrictMock(typeof(IntDelegateWithRefAndOutParams)); + + int a = 3; + string b = null; + Expect.On(d).Call(d(ref a, out b)).Do(new IntDelegateWithRefAndOutParams(Return1_Plus2_A)); + + mocks.Replay(d); + + Assert.Equal(1, d(ref a, out b)); + Assert.Equal(5, a); + Assert.Equal("A", b); + + try + { + d(ref a, out b); + Assert.False(true, "Expected an expectation violation to occur."); + } + catch (ExpectationViolationException) + { + // Expected. + } + + } + + [Fact] + public void InterceptsDynamicInvokeAlso() + { + IntDelegateWithRefAndOutParams d = (IntDelegateWithRefAndOutParams)mocks.StrictMock(typeof(IntDelegateWithRefAndOutParams)); + + int a = 3; + string b = null; + Expect.On(d).Call(d(ref a, out b)).Do(new IntDelegateWithRefAndOutParams(Return1_Plus2_A)); + + mocks.Replay(d); + + object[] args = new object[] { 3, null }; + Assert.Equal(1, d.DynamicInvoke(args)); + Assert.Equal(5, args[0]); + Assert.Equal("A", args[1]); + + try + { + d.DynamicInvoke(args); + Assert.False(true, "Expected an expectation violation to occur."); + } + catch (TargetInvocationException ex) + { + // Expected. + Assert.True(ex.InnerException is ExpectationViolationException); + } + } + + [Fact] + public void DelegateBaseTypeCannotBeMocked() + { + Assert.Throws("Cannot mock the Delegate base type.", + () => mocks.StrictMock(typeof (Delegate))); + } + + private int Return1_Plus2_A(ref int a, out string b) + { + a += 2; + b = "A"; + return 1; + } + + [Fact] + public void GenericDelegate() + { + Action action = mocks.StrictMock>(); + for (int i = 0; i < 10; i++) + { + action(i); + } + mocks.ReplayAll(); + ForEachFromZeroToNine(action); + mocks.VerifyAll(); + } + + private void ForEachFromZeroToNine(Action act) + { + for (int i = 0; i < 10; i++) + { + act(i); + } + } + } +} diff --git a/Rhino.Mocks.Tests/MockingGenericInterfaces.cs b/Rhino.Mocks.Tests/MockingGenericInterfaces.cs index a1e6b101..d5c6f7ee 100644 --- a/Rhino.Mocks.Tests/MockingGenericInterfaces.cs +++ b/Rhino.Mocks.Tests/MockingGenericInterfaces.cs @@ -1,73 +1,73 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Collections.Generic; -using System.Text; -using Xunit; - -namespace Rhino.Mocks.Tests -{ - - public class MockingGenericInterfaces : IDisposable - { - MockRepository mocks; - - public MockingGenericInterfaces() - { - mocks = new MockRepository(); - } - - public void Dispose() - { - mocks.VerifyAll(); - } - - [Fact] - public void MockAGenericInterface() - { - IList list = mocks.StrictMock>(); - Assert.NotNull(list); - Expect.Call(list.Count).Return(5); - mocks.ReplayAll(); - Assert.Equal(5, list.Count); - } - - [Fact] - public void DynamicMockOfGeneric() - { - IList list = mocks.DynamicMock>(); - Assert.NotNull(list); - Expect.Call(list.Count).Return(5); - mocks.ReplayAll(); - Assert.Equal(5, list.Count); - list.Add(4); - } - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace Rhino.Mocks.Tests +{ + + public class MockingGenericInterfaces : IDisposable + { + MockRepository mocks; + + public MockingGenericInterfaces() + { + mocks = new MockRepository(); + } + + public void Dispose() + { + mocks.VerifyAll(); + } + + [Fact] + public void MockAGenericInterface() + { + IList list = mocks.StrictMock>(); + Assert.NotNull(list); + Expect.Call(list.Count).Return(5); + mocks.ReplayAll(); + Assert.Equal(5, list.Count); + } + + [Fact] + public void DynamicMockOfGeneric() + { + IList list = mocks.DynamicMock>(); + Assert.NotNull(list); + Expect.Call(list.Count).Return(5); + mocks.ReplayAll(); + Assert.Equal(5, list.Count); + list.Add(4); + } + } +} diff --git a/Rhino.Mocks.Tests/MultiMocks.cs b/Rhino.Mocks.Tests/MultiMocks.cs index 1ea97603..e961e7cf 100644 --- a/Rhino.Mocks.Tests/MultiMocks.cs +++ b/Rhino.Mocks.Tests/MultiMocks.cs @@ -1,484 +1,484 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Collections; -using System.ComponentModel; -using System.IO; -using System.Text; -using System.Xml; - -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Interfaces; - -namespace Rhino.Mocks.Tests -{ - - public class MultiMocks - { - #region CanCreateAStrictMultiMockFromTwoInterfaces - [Fact] - public void CanCreateAStrictMultiMockFromTwoInterfacesNonGeneric() - { - MockRepository mocks = new MockRepository(); - IDemo demo = (IDemo)mocks.StrictMultiMock(typeof(IDemo), typeof(IDisposable)); - CanCreateAStrictMultiMockFromTwoInterfacesCommon(mocks, demo); - } - - [Fact] - public void CanCreateAStrictMultiMockFromTwoInterfacesGeneric() - { - MockRepository mocks = new MockRepository(); - IDemo demo = mocks.StrictMultiMock(typeof(IDisposable)); - CanCreateAStrictMultiMockFromTwoInterfacesCommon(mocks, demo); - } - - private static void CanCreateAStrictMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo) - { - demo.ReturnIntNoArgs(); - LastCall.Return(1); - IDisposable disposable = demo as IDisposable; - - Assert.NotNull(disposable); - disposable.Dispose(); - - mocks.ReplayAll(); - - Assert.Equal(1, demo.ReturnIntNoArgs()); - disposable.Dispose(); - - mocks.VerifyAll(); - } - #endregion - - #region ClearStrictCollectionAndDisposesIt - [Fact] - public void ClearStrictCollectionAndDisposesItNonGeneric() - { - MockRepository mocks = new MockRepository(); - CollectionBase collection = (CollectionBase)mocks.StrictMultiMock(typeof(CollectionBase), - typeof(IDisposable)); - ClearStrictCollectionAndDisposesItCommon(mocks, collection); - } - - [Fact] - public void ClearStrictCollectionAndDisposesItGeneric() - { - MockRepository mocks = new MockRepository(); - CollectionBase collection = mocks.StrictMultiMock(typeof(IDisposable)); - ClearStrictCollectionAndDisposesItCommon(mocks, collection); - } - - private static void ClearStrictCollectionAndDisposesItCommon(MockRepository mocks, CollectionBase collection) - { - collection.Clear(); - ((IDisposable)collection).Dispose(); - - mocks.ReplayAll(); - CleanCollection(collection); - mocks.VerifyAll(); - } - - private static void CleanCollection(CollectionBase collection) - { - collection.Clear(); - IDisposable disposable = collection as IDisposable; - if(disposable!=null) - disposable.Dispose(); - } - #endregion - - #region CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric - [Fact] - public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric() - { - MockRepository mocks = new MockRepository(); - XmlReader reader = (XmlReader)mocks.StrictMultiMock(typeof(XmlReader), typeof(ICloneable), typeof(IHasXmlNode)); - - CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); - } - - [Fact] - public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesGeneric() - { - MockRepository mocks = new MockRepository(); - XmlReader reader = mocks.StrictMultiMock(typeof(ICloneable), typeof(IHasXmlNode)); - - CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); - } - - private static void CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(MockRepository mocks, XmlReader reader) - { - Expect.Call( reader.AttributeCount ).Return( 3 ); - - ICloneable cloneable = reader as ICloneable; - Assert.NotNull( cloneable ); - - Expect.Call( cloneable.Clone() ).Return( reader ); - - IHasXmlNode hasXmlNode = reader as IHasXmlNode; - Assert.NotNull( hasXmlNode ); - - XmlNode node = new XmlDocument(); - Expect.Call( hasXmlNode.GetNode() ).Return( node ); - - mocks.ReplayAll(); - - Assert.Equal( 3, reader.AttributeCount ); - Assert.Equal( node, hasXmlNode.GetNode() ); - - Assert.Same( cloneable, cloneable.Clone() ); - - mocks.VerifyAll(); - } - #endregion - - #region CanCreateAStrictMultiMockWithConstructorArgs - [Fact] - public void CanCreateAStrictMultiMockWithConstructorArgsNonGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); - - StringWriter mockedWriter = (StringWriter)mocks.StrictMultiMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Strict); - } - - [Fact] - public void CanCreateAStrictMultiMockWithConstructorArgsGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = mocks.StrictMock(); - - StringWriter mockedWriter = mocks.StrictMultiMock( - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Strict); - } - - #endregion - - #region CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric - [Fact] - public void CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric() - { - MockRepository mocks = new MockRepository(); - object o = mocks.DynamicMultiMock(typeof(IDemo), typeof(IEditableObject)); - - IDemo demo = o as IDemo; - IEditableObject editable = o as IEditableObject; - - CanCreateADynamicMultiMockFromTwoInterfacesCommon(mocks, demo, editable); - } - - [Fact] - public void CanCreateADynamicMultiMockFromTwoInterfacesGeneric() - { - MockRepository mocks = new MockRepository(); - IDemo demo = mocks.DynamicMultiMock(typeof(IEditableObject)); - IEditableObject editable = demo as IEditableObject; - - CanCreateADynamicMultiMockFromTwoInterfacesCommon(mocks, demo, editable); - } - - private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable) - { - Assert.NotNull(demo); - Assert.NotNull(editable); - - // Set expectation on one member on each interface - - Expect.Call(demo.ReadOnly).Return("foo"); - editable.BeginEdit(); - - mocks.ReplayAll(); - - // Drive two members on each interface to check dynamic nature - - Assert.Equal("foo", demo.ReadOnly); - demo.VoidNoArgs(); - - editable.BeginEdit(); - editable.EndEdit(); - - mocks.VerifyAll(); - } - #endregion - - #region CanCreateADynamicMultiMockWithConstructorArgs - [Fact] - public void CanCreateADynamicMultiMockWithConstructorArgsNonGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); - - StringWriter mockedWriter = (StringWriter)mocks.DynamicMultiMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); - } - - [Fact] - public void CanCreateADynamicMultiMockWithConstructorArgsGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = mocks.StrictMock(); - - StringWriter mockedWriter = mocks.DynamicMultiMock( - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); - } - - #endregion - - #region CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric - [Fact] - public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric() - { - MockRepository mocks = new MockRepository(); - XmlReader reader = (XmlReader)mocks.PartialMultiMock(typeof(XmlReader), typeof(ICloneable), typeof(IHasXmlNode)); - - CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); - } - - [Fact] - public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesGeneric() - { - MockRepository mocks = new MockRepository(); - XmlReader reader = mocks.PartialMultiMock(typeof(ICloneable), typeof(IHasXmlNode)); - - CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); - } - - private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(MockRepository mocks, XmlReader reader) - { - Expect.Call(reader.AttributeCount).Return(3); - - ICloneable cloneable = reader as ICloneable; - Assert.NotNull(cloneable); - - Expect.Call(cloneable.Clone()).Return(reader); - - IHasXmlNode hasXmlNode = reader as IHasXmlNode; - Assert.NotNull(hasXmlNode); - - XmlNode node = new XmlDocument(); - Expect.Call(hasXmlNode.GetNode()).Return(node); - - mocks.ReplayAll(); - - Assert.Equal(3, reader.AttributeCount); - Assert.Equal(node, hasXmlNode.GetNode()); - - Assert.Same(cloneable, cloneable.Clone()); - - mocks.VerifyAll(); - } - #endregion - - #region CanConstructAPartialMultiMockWithConstructorArgs - [Fact] - public void CanCreateAPartialMultiMockWithConstructorArgsNonGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); - - StringWriter mockedWriter = (StringWriter)mocks.PartialMultiMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Partial); - } - - [Fact] - public void CanCreateAPartialMultiMockWithConstructorArgsGeneric() - { - MockRepository mocks = new MockRepository(); - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = mocks.StrictMock(); - - StringWriter mockedWriter = mocks.PartialMultiMock( - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Partial); - } - #endregion - - #region Check cannot create multi mocks using extra classes - [Fact] - public void CannotMultiMockUsingClassesAsExtras() - { - MockRepository mocks = new MockRepository(); - Assert.Throws(() => mocks.StrictMultiMock(typeof (XmlReader), typeof (XmlWriter))); - } - #endregion - - #region RepeatedInterfaceMultiMocks - public interface IMulti - { - void OriginalMethod1(); - void OriginalMethod2(); - } - public class MultiClass : IMulti - { - // NON-virtual method - public void OriginalMethod1() { } - // VIRTUAL method - public virtual void OriginalMethod2() { } - } - public interface ISpecialMulti : IMulti - { - void ExtraMethod(); - } - - [Fact] - public void RepeatedInterfaceMultiMocks() - { - MockRepository mocks = new MockRepository(); - object o = mocks.StrictMultiMock(typeof(MultiClass), typeof(ISpecialMulti)); - - Assert.True(o is MultiClass, "Object should be MultiClass"); - Assert.True(o is IMulti, "Object should be IMulti"); - Assert.True(o is ISpecialMulti, "Object should be ISpecialMulti"); - } - #endregion - - #region CommonConstructorArgsTest - private enum MockType { Strict, Dynamic, Partial } - - // Helper class to provide a common set of tests for constructor-args based - // multi-mocks testing. Exercises a mocked StringWriter (which should also be an IDataErrorInfo) - // constructed with a mocked IFormatProvider. The test checks the semantics - // of the mocked StringWriter to compare it with the expected semantics. - private static void CommonConstructorArgsTest(MockRepository mocks, StringBuilder stringBuilder, IFormatProvider formatProvider, StringWriter mockedWriter, MockType mockType) - { - string stringToWrite = "The original string"; - string stringToWriteLine = "Extra bit"; - - IDataErrorInfo errorInfo = mockedWriter as IDataErrorInfo; - Assert.NotNull(errorInfo); - - // Configure expectations for mocked writer - SetupResult.For(mockedWriter.FormatProvider).CallOriginalMethod(OriginalCallOptions.CreateExpectation); - mockedWriter.Write((string)null); - LastCall.IgnoreArguments().CallOriginalMethod(OriginalCallOptions.CreateExpectation); - - mockedWriter.Flush(); - LastCall.Repeat.Any().CallOriginalMethod(OriginalCallOptions.CreateExpectation); - - mockedWriter.Close(); - - // Configure expectations for object through interface - Expect.Call(errorInfo.Error).Return(null).Repeat.Once(); - Expect.Call(errorInfo.Error).Return("error!!!").Repeat.Once(); - - mocks.ReplayAll(); - - // Ensure that arguments arrived okay - // Is the format provider correct - Assert.Same(formatProvider, mockedWriter.FormatProvider); - // Does writing to the writer forward to our stringbuilder from the constructor? - mockedWriter.Write(stringToWrite); - mockedWriter.Flush(); - - // Let's see what mode our mock is running in. - // We have not configured WriteLine at all, so: - // a) if we're running as a strict mock, it'll fail - // b) if we're running as a dynamic mock, it'll no-op - // c) if we're running as a partial mock, it'll work - try - { - mockedWriter.WriteLine(stringToWriteLine); - } - catch (ExpectationViolationException) - { - // We're operating strictly. - Assert.Equal(MockType.Strict, mockType); - } - - string expectedStringBuilderContents = null; - switch (mockType) - { - case MockType.Dynamic: - case MockType.Strict: - // The writeline won't have done anything - expectedStringBuilderContents = stringToWrite; - break; - case MockType.Partial: - // The writeline will have worked - expectedStringBuilderContents = stringToWrite + stringToWriteLine + Environment.NewLine; - break; - } - - Assert.Equal(expectedStringBuilderContents, stringBuilder.ToString()); - - // Satisfy expectations. - mockedWriter.Close(); - Assert.Null(errorInfo.Error); - Assert.Equal("error!!!", errorInfo.Error); - - if(MockType.Strict != mockType) - mocks.VerifyAll(); - } - #endregion - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Text; +using System.Xml; + +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Interfaces; + +namespace Rhino.Mocks.Tests +{ + + public class MultiMocks + { + #region CanCreateAStrictMultiMockFromTwoInterfaces + [Fact] + public void CanCreateAStrictMultiMockFromTwoInterfacesNonGeneric() + { + MockRepository mocks = new MockRepository(); + IDemo demo = (IDemo)mocks.StrictMultiMock(typeof(IDemo), typeof(IDisposable)); + CanCreateAStrictMultiMockFromTwoInterfacesCommon(mocks, demo); + } + + [Fact] + public void CanCreateAStrictMultiMockFromTwoInterfacesGeneric() + { + MockRepository mocks = new MockRepository(); + IDemo demo = mocks.StrictMultiMock(typeof(IDisposable)); + CanCreateAStrictMultiMockFromTwoInterfacesCommon(mocks, demo); + } + + private static void CanCreateAStrictMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo) + { + demo.ReturnIntNoArgs(); + LastCall.Return(1); + IDisposable disposable = demo as IDisposable; + + Assert.NotNull(disposable); + disposable.Dispose(); + + mocks.ReplayAll(); + + Assert.Equal(1, demo.ReturnIntNoArgs()); + disposable.Dispose(); + + mocks.VerifyAll(); + } + #endregion + + #region ClearStrictCollectionAndDisposesIt + [Fact] + public void ClearStrictCollectionAndDisposesItNonGeneric() + { + MockRepository mocks = new MockRepository(); + CollectionBase collection = (CollectionBase)mocks.StrictMultiMock(typeof(CollectionBase), + typeof(IDisposable)); + ClearStrictCollectionAndDisposesItCommon(mocks, collection); + } + + [Fact] + public void ClearStrictCollectionAndDisposesItGeneric() + { + MockRepository mocks = new MockRepository(); + CollectionBase collection = mocks.StrictMultiMock(typeof(IDisposable)); + ClearStrictCollectionAndDisposesItCommon(mocks, collection); + } + + private static void ClearStrictCollectionAndDisposesItCommon(MockRepository mocks, CollectionBase collection) + { + collection.Clear(); + ((IDisposable)collection).Dispose(); + + mocks.ReplayAll(); + CleanCollection(collection); + mocks.VerifyAll(); + } + + private static void CleanCollection(CollectionBase collection) + { + collection.Clear(); + IDisposable disposable = collection as IDisposable; + if(disposable!=null) + disposable.Dispose(); + } + #endregion + + #region CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric + [Fact] + public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric() + { + MockRepository mocks = new MockRepository(); + XmlReader reader = (XmlReader)mocks.StrictMultiMock(typeof(XmlReader), typeof(ICloneable), typeof(IHasXmlNode)); + + CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); + } + + [Fact] + public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesGeneric() + { + MockRepository mocks = new MockRepository(); + XmlReader reader = mocks.StrictMultiMock(typeof(ICloneable), typeof(IHasXmlNode)); + + CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); + } + + private static void CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(MockRepository mocks, XmlReader reader) + { + Expect.Call( reader.AttributeCount ).Return( 3 ); + + ICloneable cloneable = reader as ICloneable; + Assert.NotNull( cloneable ); + + Expect.Call( cloneable.Clone() ).Return( reader ); + + IHasXmlNode hasXmlNode = reader as IHasXmlNode; + Assert.NotNull( hasXmlNode ); + + XmlNode node = new XmlDocument(); + Expect.Call( hasXmlNode.GetNode() ).Return( node ); + + mocks.ReplayAll(); + + Assert.Equal( 3, reader.AttributeCount ); + Assert.Equal( node, hasXmlNode.GetNode() ); + + Assert.Same( cloneable, cloneable.Clone() ); + + mocks.VerifyAll(); + } + #endregion + + #region CanCreateAStrictMultiMockWithConstructorArgs + [Fact] + public void CanCreateAStrictMultiMockWithConstructorArgsNonGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); + + StringWriter mockedWriter = (StringWriter)mocks.StrictMultiMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Strict); + } + + [Fact] + public void CanCreateAStrictMultiMockWithConstructorArgsGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = mocks.StrictMock(); + + StringWriter mockedWriter = mocks.StrictMultiMock( + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Strict); + } + + #endregion + + #region CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric + [Fact] + public void CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric() + { + MockRepository mocks = new MockRepository(); + object o = mocks.DynamicMultiMock(typeof(IDemo), typeof(IEditableObject)); + + IDemo demo = o as IDemo; + IEditableObject editable = o as IEditableObject; + + CanCreateADynamicMultiMockFromTwoInterfacesCommon(mocks, demo, editable); + } + + [Fact] + public void CanCreateADynamicMultiMockFromTwoInterfacesGeneric() + { + MockRepository mocks = new MockRepository(); + IDemo demo = mocks.DynamicMultiMock(typeof(IEditableObject)); + IEditableObject editable = demo as IEditableObject; + + CanCreateADynamicMultiMockFromTwoInterfacesCommon(mocks, demo, editable); + } + + private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable) + { + Assert.NotNull(demo); + Assert.NotNull(editable); + + // Set expectation on one member on each interface + + Expect.Call(demo.ReadOnly).Return("foo"); + editable.BeginEdit(); + + mocks.ReplayAll(); + + // Drive two members on each interface to check dynamic nature + + Assert.Equal("foo", demo.ReadOnly); + demo.VoidNoArgs(); + + editable.BeginEdit(); + editable.EndEdit(); + + mocks.VerifyAll(); + } + #endregion + + #region CanCreateADynamicMultiMockWithConstructorArgs + [Fact] + public void CanCreateADynamicMultiMockWithConstructorArgsNonGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); + + StringWriter mockedWriter = (StringWriter)mocks.DynamicMultiMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); + } + + [Fact] + public void CanCreateADynamicMultiMockWithConstructorArgsGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = mocks.StrictMock(); + + StringWriter mockedWriter = mocks.DynamicMultiMock( + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); + } + + #endregion + + #region CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric + [Fact] + public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric() + { + MockRepository mocks = new MockRepository(); + XmlReader reader = (XmlReader)mocks.PartialMultiMock(typeof(XmlReader), typeof(ICloneable), typeof(IHasXmlNode)); + + CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); + } + + [Fact] + public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesGeneric() + { + MockRepository mocks = new MockRepository(); + XmlReader reader = mocks.PartialMultiMock(typeof(ICloneable), typeof(IHasXmlNode)); + + CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(mocks, reader); + } + + private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(MockRepository mocks, XmlReader reader) + { + Expect.Call(reader.AttributeCount).Return(3); + + ICloneable cloneable = reader as ICloneable; + Assert.NotNull(cloneable); + + Expect.Call(cloneable.Clone()).Return(reader); + + IHasXmlNode hasXmlNode = reader as IHasXmlNode; + Assert.NotNull(hasXmlNode); + + XmlNode node = new XmlDocument(); + Expect.Call(hasXmlNode.GetNode()).Return(node); + + mocks.ReplayAll(); + + Assert.Equal(3, reader.AttributeCount); + Assert.Equal(node, hasXmlNode.GetNode()); + + Assert.Same(cloneable, cloneable.Clone()); + + mocks.VerifyAll(); + } + #endregion + + #region CanConstructAPartialMultiMockWithConstructorArgs + [Fact] + public void CanCreateAPartialMultiMockWithConstructorArgsNonGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)mocks.StrictMock(typeof(IFormatProvider)); + + StringWriter mockedWriter = (StringWriter)mocks.PartialMultiMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Partial); + } + + [Fact] + public void CanCreateAPartialMultiMockWithConstructorArgsGeneric() + { + MockRepository mocks = new MockRepository(); + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = mocks.StrictMock(); + + StringWriter mockedWriter = mocks.PartialMultiMock( + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(mocks, stringBuilder, formatProvider, mockedWriter, MockType.Partial); + } + #endregion + + #region Check cannot create multi mocks using extra classes + [Fact] + public void CannotMultiMockUsingClassesAsExtras() + { + MockRepository mocks = new MockRepository(); + Assert.Throws(() => mocks.StrictMultiMock(typeof (XmlReader), typeof (XmlWriter))); + } + #endregion + + #region RepeatedInterfaceMultiMocks + public interface IMulti + { + void OriginalMethod1(); + void OriginalMethod2(); + } + public class MultiClass : IMulti + { + // NON-virtual method + public void OriginalMethod1() { } + // VIRTUAL method + public virtual void OriginalMethod2() { } + } + public interface ISpecialMulti : IMulti + { + void ExtraMethod(); + } + + [Fact] + public void RepeatedInterfaceMultiMocks() + { + MockRepository mocks = new MockRepository(); + object o = mocks.StrictMultiMock(typeof(MultiClass), typeof(ISpecialMulti)); + + Assert.True(o is MultiClass, "Object should be MultiClass"); + Assert.True(o is IMulti, "Object should be IMulti"); + Assert.True(o is ISpecialMulti, "Object should be ISpecialMulti"); + } + #endregion + + #region CommonConstructorArgsTest + private enum MockType { Strict, Dynamic, Partial } + + // Helper class to provide a common set of tests for constructor-args based + // multi-mocks testing. Exercises a mocked StringWriter (which should also be an IDataErrorInfo) + // constructed with a mocked IFormatProvider. The test checks the semantics + // of the mocked StringWriter to compare it with the expected semantics. + private static void CommonConstructorArgsTest(MockRepository mocks, StringBuilder stringBuilder, IFormatProvider formatProvider, StringWriter mockedWriter, MockType mockType) + { + string stringToWrite = "The original string"; + string stringToWriteLine = "Extra bit"; + + IDataErrorInfo errorInfo = mockedWriter as IDataErrorInfo; + Assert.NotNull(errorInfo); + + // Configure expectations for mocked writer + SetupResult.For(mockedWriter.FormatProvider).CallOriginalMethod(OriginalCallOptions.CreateExpectation); + mockedWriter.Write((string)null); + LastCall.IgnoreArguments().CallOriginalMethod(OriginalCallOptions.CreateExpectation); + + mockedWriter.Flush(); + LastCall.Repeat.Any().CallOriginalMethod(OriginalCallOptions.CreateExpectation); + + mockedWriter.Close(); + + // Configure expectations for object through interface + Expect.Call(errorInfo.Error).Return(null).Repeat.Once(); + Expect.Call(errorInfo.Error).Return("error!!!").Repeat.Once(); + + mocks.ReplayAll(); + + // Ensure that arguments arrived okay + // Is the format provider correct + Assert.Same(formatProvider, mockedWriter.FormatProvider); + // Does writing to the writer forward to our stringbuilder from the constructor? + mockedWriter.Write(stringToWrite); + mockedWriter.Flush(); + + // Let's see what mode our mock is running in. + // We have not configured WriteLine at all, so: + // a) if we're running as a strict mock, it'll fail + // b) if we're running as a dynamic mock, it'll no-op + // c) if we're running as a partial mock, it'll work + try + { + mockedWriter.WriteLine(stringToWriteLine); + } + catch (ExpectationViolationException) + { + // We're operating strictly. + Assert.Equal(MockType.Strict, mockType); + } + + string expectedStringBuilderContents = null; + switch (mockType) + { + case MockType.Dynamic: + case MockType.Strict: + // The writeline won't have done anything + expectedStringBuilderContents = stringToWrite; + break; + case MockType.Partial: + // The writeline will have worked + expectedStringBuilderContents = stringToWrite + stringToWriteLine + Environment.NewLine; + break; + } + + Assert.Equal(expectedStringBuilderContents, stringBuilder.ToString()); + + // Satisfy expectations. + mockedWriter.Close(); + Assert.Null(errorInfo.Error); + Assert.Equal("error!!!", errorInfo.Error); + + if(MockType.Strict != mockType) + mocks.VerifyAll(); + } + #endregion + } +} diff --git a/Rhino.Mocks.Tests/MultiMocksWithAAA.cs b/Rhino.Mocks.Tests/MultiMocksWithAAA.cs index 89c61334..98fac63c 100644 --- a/Rhino.Mocks.Tests/MultiMocksWithAAA.cs +++ b/Rhino.Mocks.Tests/MultiMocksWithAAA.cs @@ -1,461 +1,461 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Collections; -using System.ComponentModel; -using System.IO; -using System.Text; -using System.Xml; - -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Interfaces; - -namespace Rhino.Mocks.Tests -{ - - public class MultiMocksAAA - { - [Fact] - public void CanCreateADynamicMultiMockFromTwoInterfacesGenericAndAssertWasCalled() - { - IDemo demo = MockRepository.GenerateMock(); - IEditableObject editable = demo as IEditableObject; - - demo.ReturnIntNoArgs(); - editable.BeginEdit(); - editable.CancelEdit(); // we don't care about this - editable.EndEdit(); - - demo.AssertWasCalled(x => x.ReturnIntNoArgs()); - editable.AssertWasCalled(x => x.BeginEdit()); - editable.AssertWasCalled(x => x.EndEdit()); - - // Double check all expectations were verified - editable.VerifyAllExpectations(); - } - - #region CanCreateAStrictMultiMockFromTwoInterfaces - [Fact] - public void CanCreateAStrictMultiMockFromTwoInterfacesNonGeneric() - { - IDemo demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo), new Type[]{typeof(IDisposable)}); - CanCreateAStrictMultiMockFromTwoInterfacesCommon(demo); - } - - [Fact] - public void CanCreateAStrictMultiMockFromTwoInterfacesGeneric() - { - IDemo demo = MockRepository.GenerateStrictMock(); - CanCreateAStrictMultiMockFromTwoInterfacesCommon(demo); - } - - private static void CanCreateAStrictMultiMockFromTwoInterfacesCommon(IDemo demo) - { - demo.Expect(x => x.ReturnIntNoArgs()).Return(1); - IDisposable disposable = demo as IDisposable; - Assert.NotNull(disposable); - disposable.Expect(x => x.Dispose()); - - Assert.Equal(1, demo.ReturnIntNoArgs()); - disposable.Dispose(); - - demo.VerifyAllExpectations(); - } - #endregion - - #region ClearStrictCollectionAndDisposesIt - [Fact] - public void ClearStrictCollectionAndDisposesItNonGeneric() - { - CollectionBase collection = (CollectionBase)MockRepository.GenerateStrictMock(typeof(CollectionBase), new Type[]{typeof(IDisposable)}); - ClearStrictCollectionAndDisposesItCommon(collection); - } - - [Fact] - public void ClearStrictCollectionAndDisposesItGeneric() - { - CollectionBase collection = MockRepository.GenerateStrictMock(); - ClearStrictCollectionAndDisposesItCommon(collection); - } - - private static void ClearStrictCollectionAndDisposesItCommon(CollectionBase collection) - { - collection.Expect(x => x.Clear()); - ((IDisposable)collection).Expect(x => x.Dispose()); - - CleanCollection(collection); - collection.VerifyAllExpectations(); - } - - private static void CleanCollection(CollectionBase collection) - { - collection.Clear(); - IDisposable disposable = collection as IDisposable; - if (disposable != null) - disposable.Dispose(); - } - #endregion - - #region CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric - [Fact] - public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric() - { - XmlReader reader = (XmlReader)MockRepository.GenerateStrictMock(typeof(XmlReader), new Type[]{typeof(ICloneable), typeof(IHasXmlNode)}); - - CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(reader); - } - - [Fact] - public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesGeneric() - { - XmlReader reader = MockRepository.GenerateStrictMock(); - - CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(reader); - } - - private static void CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(XmlReader reader) - { - reader.Expect(x => x.AttributeCount).Return(3); - - ICloneable cloneable = reader as ICloneable; - Assert.NotNull(cloneable); - cloneable.Expect(x => x.Clone()).Return(reader); - - IHasXmlNode hasXmlNode = reader as IHasXmlNode; - Assert.NotNull(hasXmlNode); - - XmlNode node = new XmlDocument(); - hasXmlNode.Expect(x => x.GetNode()).Return(node); - - Assert.Equal(3, reader.AttributeCount); - Assert.Equal(node, hasXmlNode.GetNode()); - - Assert.Same(cloneable, cloneable.Clone()); - - reader.VerifyAllExpectations(); - } - #endregion - - #region CanCreateAStrictMultiMockWithConstructorArgs - [Fact] - public void CanCreateAStrictMultiMockWithConstructorArgsNonGeneric() - { - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); - - StringWriter mockedWriter = (StringWriter)MockRepository.GenerateStrictMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Strict); - } - - [Fact] - public void CanCreateAStrictMultiMockWithConstructorArgsGeneric() - { - - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); - - StringWriter mockedWriter = MockRepository.GenerateStrictMock( - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Strict); - } - - #endregion - - #region CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric - [Fact] - public void CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric() - { - object o = MockRepository.GenerateMock(typeof(IDemo), new Type[]{typeof(IEditableObject)}); - - IDemo demo = o as IDemo; - IEditableObject editable = o as IEditableObject; - - CanCreateADynamicMultiMockFromTwoInterfacesCommon(demo, editable); - } - - [Fact] - public void CanCreateADynamicMultiMockFromTwoInterfacesGeneric() - { - IDemo demo = MockRepository.GenerateMock(); - IEditableObject editable = demo as IEditableObject; - - CanCreateADynamicMultiMockFromTwoInterfacesCommon(demo, editable); - } - - private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable) - { - Assert.NotNull(demo); - Assert.NotNull(editable); - - // Set expectation on one member on each interface - - demo.Expect(x => demo.ReadOnly).Return("foo"); - editable.Expect(x => x.BeginEdit()); - - // Drive two members on each interface to check dynamic nature - - Assert.Equal("foo", demo.ReadOnly); - demo.VoidNoArgs(); - - editable.BeginEdit(); - editable.EndEdit(); - - demo.VerifyAllExpectations(); - } - #endregion - - #region CanCreateADynamicMultiMockWithConstructorArgs - [Fact] - public void CanCreateADynamicMultiMockWithConstructorArgsNonGeneric() - { - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); - - StringWriter mockedWriter = (StringWriter)MockRepository.GenerateMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); - } - - [Fact] - public void CanCreateADynamicMultiMockWithConstructorArgsGeneric() - { - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); - - StringWriter mockedWriter = MockRepository.GenerateMock( - stringBuilder, - formatProvider - ); - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); - } - - #endregion - - #region CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric - [Fact] - public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric() - { - XmlReader reader = (XmlReader)MockRepository.GeneratePartialMock(typeof(XmlReader), new Type[]{typeof(ICloneable), typeof(IHasXmlNode)}); - - CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(reader); - } - - [Fact] - public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesGeneric() - { - XmlReader reader = MockRepository.GeneratePartialMock(); - - CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(reader); - } - - private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(XmlReader reader) - { - reader.Expect(x => x.AttributeCount).Return(3); - - ICloneable cloneable = reader as ICloneable; - Assert.NotNull(cloneable); - - cloneable.Expect(x => x.Clone()).Return(reader); - - IHasXmlNode hasXmlNode = reader as IHasXmlNode; - Assert.NotNull(hasXmlNode); - - XmlNode node = new XmlDocument(); - hasXmlNode.Expect(x => x.GetNode()).Return(node); - - Assert.Equal(3, reader.AttributeCount); - Assert.Equal(node, hasXmlNode.GetNode()); - - Assert.Same(cloneable, cloneable.Clone()); - - reader.VerifyAllExpectations(); - } - #endregion - - #region CanConstructAPartialMultiMockWithConstructorArgs - [Fact] - public void CanCreateAPartialMultiMockWithConstructorArgsNonGeneric() - { - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); - - StringWriter mockedWriter = (StringWriter)MockRepository.GeneratePartialMock( - typeof(StringWriter), - new Type[] { typeof(IDataErrorInfo) }, - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Partial); - } - - [Fact] - public void CanCreateAPartialMultiMockWithConstructorArgsGeneric() - { - StringBuilder stringBuilder = new StringBuilder(); - IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); - - StringWriter mockedWriter = MockRepository.GeneratePartialMock( - stringBuilder, - formatProvider - ); - - CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Partial); - } - #endregion - - #region Check cannot create multi mocks using extra classes - [Fact] - public void CannotMultiMockUsingClassesAsExtras() - { - Assert.Throws( - () => MockRepository.GenerateStrictMock(typeof (XmlReader), new Type[] {typeof (XmlWriter)})); - } - #endregion - - #region RepeatedInterfaceMultiMocks - public interface IMulti - { - void OriginalMethod1(); - void OriginalMethod2(); - } - public class MultiClass : IMulti - { - // NON-virtual method - public void OriginalMethod1() { } - // VIRTUAL method - public virtual void OriginalMethod2() { } - } - public interface ISpecialMulti : IMulti - { - void ExtraMethod(); - } - - [Fact] - public void RepeatedInterfaceMultiMocks() - { - object o = MockRepository.GenerateStrictMock(typeof(MultiClass), new Type[]{typeof(ISpecialMulti)}); - - Assert.True(o is MultiClass, "Object should be MultiClass"); - Assert.True(o is IMulti, "Object should be IMulti"); - Assert.True(o is ISpecialMulti, "Object should be ISpecialMulti"); - } - #endregion - - #region CommonConstructorArgsTest - private enum MockType { Strict, Dynamic, Partial } - - // Helper class to provide a common set of tests for constructor-args based - // multi-mocks testing. Exercises a mocked StringWriter (which should also be an IDataErrorInfo) - // constructed with a mocked IFormatProvider. The test checks the semantics - // of the mocked StringWriter to compare it with the expected semantics. - private static void CommonConstructorArgsTest(StringBuilder stringBuilder, IFormatProvider formatProvider, StringWriter mockedWriter, MockType mockType) - { - string stringToWrite = "The original string"; - string stringToWriteLine = "Extra bit"; - - IDataErrorInfo errorInfo = mockedWriter as IDataErrorInfo; - Assert.NotNull(errorInfo); - - // Configure expectations for mocked writer - mockedWriter.Stub(x => x.FormatProvider).Return(formatProvider).CallOriginalMethod(OriginalCallOptions.CreateExpectation); - mockedWriter.Expect(x => x.Write((string) null)).IgnoreArguments().CallOriginalMethod(OriginalCallOptions.CreateExpectation); - mockedWriter.Expect(x => x.Flush()).Repeat.Any().CallOriginalMethod(OriginalCallOptions.CreateExpectation); - mockedWriter.Expect(x => x.Close()); - - - // Configure expectations for object through interface - errorInfo.Expect(x => x.Error).Return(null).Repeat.Once(); - errorInfo.Expect(x => x.Error).Return("error!!!").Repeat.Once(); - - // Ensure that arguments arrived okay - // Is the format provider correct - Assert.Same(formatProvider, mockedWriter.FormatProvider); - // Does writing to the writer forward to our stringbuilder from the constructor? - mockedWriter.Write(stringToWrite); - mockedWriter.Flush(); - - // Let's see what mode our mock is running in. - // We have not configured WriteLine at all, so: - // a) if we're running as a strict mock, it'll fail - // b) if we're running as a dynamic mock, it'll no-op - // c) if we're running as a partial mock, it'll work - try - { - mockedWriter.WriteLine(stringToWriteLine); - } - catch (ExpectationViolationException) - { - // We're operating strictly. - Assert.Equal(MockType.Strict, mockType); - } - - string expectedStringBuilderContents = null; - switch (mockType) - { - case MockType.Dynamic: - case MockType.Strict: - // The writeline won't have done anything - expectedStringBuilderContents = stringToWrite; - break; - case MockType.Partial: - // The writeline will have worked - expectedStringBuilderContents = stringToWrite + stringToWriteLine + Environment.NewLine; - break; - } - - Assert.Equal(expectedStringBuilderContents, stringBuilder.ToString()); - - // Satisfy expectations. - mockedWriter.Close(); - Assert.Null(errorInfo.Error); - Assert.Equal("error!!!", errorInfo.Error); - - if (MockType.Strict != mockType) - mockedWriter.VerifyAllExpectations(); - } - #endregion - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Text; +using System.Xml; + +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Interfaces; + +namespace Rhino.Mocks.Tests +{ + + public class MultiMocksAAA + { + [Fact] + public void CanCreateADynamicMultiMockFromTwoInterfacesGenericAndAssertWasCalled() + { + IDemo demo = MockRepository.GenerateMock(); + IEditableObject editable = demo as IEditableObject; + + demo.ReturnIntNoArgs(); + editable.BeginEdit(); + editable.CancelEdit(); // we don't care about this + editable.EndEdit(); + + demo.AssertWasCalled(x => x.ReturnIntNoArgs()); + editable.AssertWasCalled(x => x.BeginEdit()); + editable.AssertWasCalled(x => x.EndEdit()); + + // Double check all expectations were verified + editable.VerifyAllExpectations(); + } + + #region CanCreateAStrictMultiMockFromTwoInterfaces + [Fact] + public void CanCreateAStrictMultiMockFromTwoInterfacesNonGeneric() + { + IDemo demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo), new Type[]{typeof(IDisposable)}); + CanCreateAStrictMultiMockFromTwoInterfacesCommon(demo); + } + + [Fact] + public void CanCreateAStrictMultiMockFromTwoInterfacesGeneric() + { + IDemo demo = MockRepository.GenerateStrictMock(); + CanCreateAStrictMultiMockFromTwoInterfacesCommon(demo); + } + + private static void CanCreateAStrictMultiMockFromTwoInterfacesCommon(IDemo demo) + { + demo.Expect(x => x.ReturnIntNoArgs()).Return(1); + IDisposable disposable = demo as IDisposable; + Assert.NotNull(disposable); + disposable.Expect(x => x.Dispose()); + + Assert.Equal(1, demo.ReturnIntNoArgs()); + disposable.Dispose(); + + demo.VerifyAllExpectations(); + } + #endregion + + #region ClearStrictCollectionAndDisposesIt + [Fact] + public void ClearStrictCollectionAndDisposesItNonGeneric() + { + CollectionBase collection = (CollectionBase)MockRepository.GenerateStrictMock(typeof(CollectionBase), new Type[]{typeof(IDisposable)}); + ClearStrictCollectionAndDisposesItCommon(collection); + } + + [Fact] + public void ClearStrictCollectionAndDisposesItGeneric() + { + CollectionBase collection = MockRepository.GenerateStrictMock(); + ClearStrictCollectionAndDisposesItCommon(collection); + } + + private static void ClearStrictCollectionAndDisposesItCommon(CollectionBase collection) + { + collection.Expect(x => x.Clear()); + ((IDisposable)collection).Expect(x => x.Dispose()); + + CleanCollection(collection); + collection.VerifyAllExpectations(); + } + + private static void CleanCollection(CollectionBase collection) + { + collection.Clear(); + IDisposable disposable = collection as IDisposable; + if (disposable != null) + disposable.Dispose(); + } + #endregion + + #region CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric + [Fact] + public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesNonGeneric() + { + XmlReader reader = (XmlReader)MockRepository.GenerateStrictMock(typeof(XmlReader), new Type[]{typeof(ICloneable), typeof(IHasXmlNode)}); + + CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(reader); + } + + [Fact] + public void CanCreateAStrictMultiMockFromClassAndTwoInterfacesGeneric() + { + XmlReader reader = MockRepository.GenerateStrictMock(); + + CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(reader); + } + + private static void CanCreateAStrictMultiMockFromClassAndTwoInterfacesCommon(XmlReader reader) + { + reader.Expect(x => x.AttributeCount).Return(3); + + ICloneable cloneable = reader as ICloneable; + Assert.NotNull(cloneable); + cloneable.Expect(x => x.Clone()).Return(reader); + + IHasXmlNode hasXmlNode = reader as IHasXmlNode; + Assert.NotNull(hasXmlNode); + + XmlNode node = new XmlDocument(); + hasXmlNode.Expect(x => x.GetNode()).Return(node); + + Assert.Equal(3, reader.AttributeCount); + Assert.Equal(node, hasXmlNode.GetNode()); + + Assert.Same(cloneable, cloneable.Clone()); + + reader.VerifyAllExpectations(); + } + #endregion + + #region CanCreateAStrictMultiMockWithConstructorArgs + [Fact] + public void CanCreateAStrictMultiMockWithConstructorArgsNonGeneric() + { + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); + + StringWriter mockedWriter = (StringWriter)MockRepository.GenerateStrictMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Strict); + } + + [Fact] + public void CanCreateAStrictMultiMockWithConstructorArgsGeneric() + { + + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); + + StringWriter mockedWriter = MockRepository.GenerateStrictMock( + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Strict); + } + + #endregion + + #region CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric + [Fact] + public void CanCreateADynamicMultiMockFromTwoInterfacesNonGeneric() + { + object o = MockRepository.GenerateMock(typeof(IDemo), new Type[]{typeof(IEditableObject)}); + + IDemo demo = o as IDemo; + IEditableObject editable = o as IEditableObject; + + CanCreateADynamicMultiMockFromTwoInterfacesCommon(demo, editable); + } + + [Fact] + public void CanCreateADynamicMultiMockFromTwoInterfacesGeneric() + { + IDemo demo = MockRepository.GenerateMock(); + IEditableObject editable = demo as IEditableObject; + + CanCreateADynamicMultiMockFromTwoInterfacesCommon(demo, editable); + } + + private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable) + { + Assert.NotNull(demo); + Assert.NotNull(editable); + + // Set expectation on one member on each interface + + demo.Expect(x => demo.ReadOnly).Return("foo"); + editable.Expect(x => x.BeginEdit()); + + // Drive two members on each interface to check dynamic nature + + Assert.Equal("foo", demo.ReadOnly); + demo.VoidNoArgs(); + + editable.BeginEdit(); + editable.EndEdit(); + + demo.VerifyAllExpectations(); + } + #endregion + + #region CanCreateADynamicMultiMockWithConstructorArgs + [Fact] + public void CanCreateADynamicMultiMockWithConstructorArgsNonGeneric() + { + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); + + StringWriter mockedWriter = (StringWriter)MockRepository.GenerateMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); + } + + [Fact] + public void CanCreateADynamicMultiMockWithConstructorArgsGeneric() + { + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); + + StringWriter mockedWriter = MockRepository.GenerateMock( + stringBuilder, + formatProvider + ); + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Dynamic); + } + + #endregion + + #region CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric + [Fact] + public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesNonGeneric() + { + XmlReader reader = (XmlReader)MockRepository.GeneratePartialMock(typeof(XmlReader), new Type[]{typeof(ICloneable), typeof(IHasXmlNode)}); + + CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(reader); + } + + [Fact] + public void CanCreateAPartialMultiMockFromClassAndTwoInterfacesGeneric() + { + XmlReader reader = MockRepository.GeneratePartialMock(); + + CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(reader); + } + + private static void CanCreateAPartialMultiMockFromClassAndTwoInterfacesCommon(XmlReader reader) + { + reader.Expect(x => x.AttributeCount).Return(3); + + ICloneable cloneable = reader as ICloneable; + Assert.NotNull(cloneable); + + cloneable.Expect(x => x.Clone()).Return(reader); + + IHasXmlNode hasXmlNode = reader as IHasXmlNode; + Assert.NotNull(hasXmlNode); + + XmlNode node = new XmlDocument(); + hasXmlNode.Expect(x => x.GetNode()).Return(node); + + Assert.Equal(3, reader.AttributeCount); + Assert.Equal(node, hasXmlNode.GetNode()); + + Assert.Same(cloneable, cloneable.Clone()); + + reader.VerifyAllExpectations(); + } + #endregion + + #region CanConstructAPartialMultiMockWithConstructorArgs + [Fact] + public void CanCreateAPartialMultiMockWithConstructorArgsNonGeneric() + { + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = (IFormatProvider)MockRepository.GenerateStrictMock(typeof(IFormatProvider), new Type[0]); + + StringWriter mockedWriter = (StringWriter)MockRepository.GeneratePartialMock( + typeof(StringWriter), + new Type[] { typeof(IDataErrorInfo) }, + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Partial); + } + + [Fact] + public void CanCreateAPartialMultiMockWithConstructorArgsGeneric() + { + StringBuilder stringBuilder = new StringBuilder(); + IFormatProvider formatProvider = MockRepository.GenerateStrictMock(); + + StringWriter mockedWriter = MockRepository.GeneratePartialMock( + stringBuilder, + formatProvider + ); + + CommonConstructorArgsTest(stringBuilder, formatProvider, mockedWriter, MockType.Partial); + } + #endregion + + #region Check cannot create multi mocks using extra classes + [Fact] + public void CannotMultiMockUsingClassesAsExtras() + { + Assert.Throws( + () => MockRepository.GenerateStrictMock(typeof (XmlReader), new Type[] {typeof (XmlWriter)})); + } + #endregion + + #region RepeatedInterfaceMultiMocks + public interface IMulti + { + void OriginalMethod1(); + void OriginalMethod2(); + } + public class MultiClass : IMulti + { + // NON-virtual method + public void OriginalMethod1() { } + // VIRTUAL method + public virtual void OriginalMethod2() { } + } + public interface ISpecialMulti : IMulti + { + void ExtraMethod(); + } + + [Fact] + public void RepeatedInterfaceMultiMocks() + { + object o = MockRepository.GenerateStrictMock(typeof(MultiClass), new Type[]{typeof(ISpecialMulti)}); + + Assert.True(o is MultiClass, "Object should be MultiClass"); + Assert.True(o is IMulti, "Object should be IMulti"); + Assert.True(o is ISpecialMulti, "Object should be ISpecialMulti"); + } + #endregion + + #region CommonConstructorArgsTest + private enum MockType { Strict, Dynamic, Partial } + + // Helper class to provide a common set of tests for constructor-args based + // multi-mocks testing. Exercises a mocked StringWriter (which should also be an IDataErrorInfo) + // constructed with a mocked IFormatProvider. The test checks the semantics + // of the mocked StringWriter to compare it with the expected semantics. + private static void CommonConstructorArgsTest(StringBuilder stringBuilder, IFormatProvider formatProvider, StringWriter mockedWriter, MockType mockType) + { + string stringToWrite = "The original string"; + string stringToWriteLine = "Extra bit"; + + IDataErrorInfo errorInfo = mockedWriter as IDataErrorInfo; + Assert.NotNull(errorInfo); + + // Configure expectations for mocked writer + mockedWriter.Stub(x => x.FormatProvider).Return(formatProvider).CallOriginalMethod(OriginalCallOptions.CreateExpectation); + mockedWriter.Expect(x => x.Write((string) null)).IgnoreArguments().CallOriginalMethod(OriginalCallOptions.CreateExpectation); + mockedWriter.Expect(x => x.Flush()).Repeat.Any().CallOriginalMethod(OriginalCallOptions.CreateExpectation); + mockedWriter.Expect(x => x.Close()); + + + // Configure expectations for object through interface + errorInfo.Expect(x => x.Error).Return(null).Repeat.Once(); + errorInfo.Expect(x => x.Error).Return("error!!!").Repeat.Once(); + + // Ensure that arguments arrived okay + // Is the format provider correct + Assert.Same(formatProvider, mockedWriter.FormatProvider); + // Does writing to the writer forward to our stringbuilder from the constructor? + mockedWriter.Write(stringToWrite); + mockedWriter.Flush(); + + // Let's see what mode our mock is running in. + // We have not configured WriteLine at all, so: + // a) if we're running as a strict mock, it'll fail + // b) if we're running as a dynamic mock, it'll no-op + // c) if we're running as a partial mock, it'll work + try + { + mockedWriter.WriteLine(stringToWriteLine); + } + catch (ExpectationViolationException) + { + // We're operating strictly. + Assert.Equal(MockType.Strict, mockType); + } + + string expectedStringBuilderContents = null; + switch (mockType) + { + case MockType.Dynamic: + case MockType.Strict: + // The writeline won't have done anything + expectedStringBuilderContents = stringToWrite; + break; + case MockType.Partial: + // The writeline will have worked + expectedStringBuilderContents = stringToWrite + stringToWriteLine + Environment.NewLine; + break; + } + + Assert.Equal(expectedStringBuilderContents, stringBuilder.ToString()); + + // Satisfy expectations. + mockedWriter.Close(); + Assert.Null(errorInfo.Error); + Assert.Equal("error!!!", errorInfo.Error); + + if (MockType.Strict != mockType) + mockedWriter.VerifyAllExpectations(); + } + #endregion + } +} diff --git a/Rhino.Mocks.Tests/OrderTest.cs b/Rhino.Mocks.Tests/OrderTest.cs index 8d1a0e91..ca2c86dd 100644 --- a/Rhino.Mocks.Tests/OrderTest.cs +++ b/Rhino.Mocks.Tests/OrderTest.cs @@ -1,245 +1,245 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Text; - -using Xunit; - -namespace Rhino.Mocks.Tests -{ - - public class OrderedTests - { - private delegate void ConfigureMockDelegate(MockRepository mocks, I1 mockObject); - - #region TestOrderedTimesMin0 - //Test that a Times min of 0 works correctly inside an ordered recorder - [Fact] - public void TestOrderedTimesMin0() - { - ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMin0); - - // Let's check all the valid possibilities - AssertOrderValidity(deleg, true, ""); - AssertOrderValidity(deleg, true, "A"); - AssertOrderValidity(deleg, true, "C"); - AssertOrderValidity(deleg, true, "B"); - AssertOrderValidity(deleg, true, "AB"); - AssertOrderValidity(deleg, true, "AC"); - AssertOrderValidity(deleg, true, "BC"); - AssertOrderValidity(deleg, true, "ABC"); - - // Let's check some invalid ones - AssertOrderValidity(deleg, false, "CB"); - AssertOrderValidity(deleg, false, "CA"); - AssertOrderValidity(deleg, false, "BA"); - AssertOrderValidity(deleg, false, "AA"); - AssertOrderValidity(deleg, false, "ABB"); - } - - private static void ConfigureOrderedTimesMin0(MockRepository mocks, I1 mockObject) - { - using (mocks.Ordered()) - { - mockObject.A(); - LastCall.Repeat.Times(0, 1); - mockObject.B(); - LastCall.Repeat.Times(0, 1); - mockObject.C(); - LastCall.Repeat.Times(0, 1); - } - } - #endregion - - #region TestOrderedTimesMinNonZeroMaxHigherThanMin - - [Fact] - public void TestOrderedTimesMinNonZeroMaxHigherThanMin() - { - ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMinNonZeroMaxHigherThanMin); - - // Let's check all the valid possibilities - AssertOrderValidity(deleg, true, "ABC"); - AssertOrderValidity(deleg, true, "ABBC"); - AssertOrderValidity(deleg, true, "ABBBC"); - - // Let's check some invalid ones - AssertOrderValidity(deleg, false, "BC"); // Missing A - AssertOrderValidity(deleg, false, "AC"); // Too few Bs - AssertOrderValidity(deleg, false, "ABBBBC"); // Too many Bs - } - - private static void ConfigureOrderedTimesMinNonZeroMaxHigherThanMin(MockRepository mocks, I1 mockObject) - { - using (mocks.Ordered()) - { - mockObject.A(); - mockObject.B(); - LastCall.Repeat.Times(1, 3); - mockObject.C(); - } - } - #endregion - - #region TestOrderedAtLeastOnce - [Fact] - public void TestOrderedAtLeastOnce() - { - ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedAtLeastOnce); - - // Let's check some of the valid possibilities - AssertOrderValidity(deleg, true, "ABC"); - AssertOrderValidity(deleg, true, "ABBC"); - AssertOrderValidity(deleg, true, "ABBBBBBBBBBBBBBBBBBBBC"); - - // Let's check some invalid ones - AssertOrderValidity(deleg, false, "BC"); // Missing A - AssertOrderValidity(deleg, false, "AC"); // Too few Bs - } - - private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject) - { - using (mocks.Ordered()) - { - mockObject.A(); - mockObject.B(); - LastCall.Repeat.AtLeastOnce(); - mockObject.C(); - } - } - #endregion - - #region TestOrderedTimesMin0WithNestedUnordered - [Fact] - public void TestOrderedTimesMin0WithNestedUnordered() - { - ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMin0WithNestedUnordered); - - // Let's check all the valid possibilities - AssertOrderValidity(deleg, true, "BC"); - AssertOrderValidity(deleg, true, "CB"); - AssertOrderValidity(deleg, true, "ABC"); - AssertOrderValidity(deleg, true, "ACB"); - AssertOrderValidity(deleg, true, "BCA"); - AssertOrderValidity(deleg, true, "CBA"); - AssertOrderValidity(deleg, true, "ABCA"); - AssertOrderValidity(deleg, true, "ACBA"); - - // Let's check some invalid ones - AssertOrderValidity(deleg, false, ""); - AssertOrderValidity(deleg, false, "AA"); - AssertOrderValidity(deleg, false, "AABC"); - AssertOrderValidity(deleg, false, "AACB"); - AssertOrderValidity(deleg, false, "ABCAA"); - } - - private static void ConfigureOrderedTimesMin0WithNestedUnordered(MockRepository mocks, I1 mockObject) - { - using (mocks.Ordered()) - { - mockObject.A(); - LastCall.Repeat.Times(0, 1); - using (mocks.Unordered()) - { - mockObject.B(); - mockObject.C(); - } - mockObject.A(); - LastCall.Repeat.Times(0, 1); - } - } - #endregion - - #region Helper method for performing easy configuration and replay testing - /// - /// Sets up a mock, and runs through methods as specified by characters in . - /// - /// A delegate to use to configure the mock. - /// Whether the order should be valid or not. - /// The method order (e.g. "ABC", "ABBC"). - private static void AssertOrderValidity( ConfigureMockDelegate mockConfigurer, bool isValid, - string methodOrder ) - { - MockRepository mocks = new MockRepository(); - - I1 i = mocks.StrictMock(typeof(I1)) as I1; - - mockConfigurer(mocks, i); - - mocks.ReplayAll(); - - try - { - foreach (char c in methodOrder) - { - switch (c) - { - case 'A': - i.A(); - break; - case 'B': - i.B(); - break; - case 'C': - i.C(); - break; - default: - throw new NotSupportedException(); - } - } - mocks.VerifyAll(); - } - catch (Exceptions.ExpectationViolationException ex) - { - if (isValid) - { - Assert.False(true, string.Format("Order {0} was supposed to be ok, but got error: {1}", methodOrder, ex.Message)); - } - else - { - return; - } - } - - if (!isValid) - { - Assert.False(true, string.Format("Order {0} was supposed to fail, but did not.", methodOrder)); - } - } - #endregion - } - - public interface I1 - { - void A(); - void B(); - void C(); - } -} +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Text; + +using Xunit; + +namespace Rhino.Mocks.Tests +{ + + public class OrderedTests + { + private delegate void ConfigureMockDelegate(MockRepository mocks, I1 mockObject); + + #region TestOrderedTimesMin0 + //Test that a Times min of 0 works correctly inside an ordered recorder + [Fact] + public void TestOrderedTimesMin0() + { + ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMin0); + + // Let's check all the valid possibilities + AssertOrderValidity(deleg, true, ""); + AssertOrderValidity(deleg, true, "A"); + AssertOrderValidity(deleg, true, "C"); + AssertOrderValidity(deleg, true, "B"); + AssertOrderValidity(deleg, true, "AB"); + AssertOrderValidity(deleg, true, "AC"); + AssertOrderValidity(deleg, true, "BC"); + AssertOrderValidity(deleg, true, "ABC"); + + // Let's check some invalid ones + AssertOrderValidity(deleg, false, "CB"); + AssertOrderValidity(deleg, false, "CA"); + AssertOrderValidity(deleg, false, "BA"); + AssertOrderValidity(deleg, false, "AA"); + AssertOrderValidity(deleg, false, "ABB"); + } + + private static void ConfigureOrderedTimesMin0(MockRepository mocks, I1 mockObject) + { + using (mocks.Ordered()) + { + mockObject.A(); + LastCall.Repeat.Times(0, 1); + mockObject.B(); + LastCall.Repeat.Times(0, 1); + mockObject.C(); + LastCall.Repeat.Times(0, 1); + } + } + #endregion + + #region TestOrderedTimesMinNonZeroMaxHigherThanMin + + [Fact] + public void TestOrderedTimesMinNonZeroMaxHigherThanMin() + { + ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMinNonZeroMaxHigherThanMin); + + // Let's check all the valid possibilities + AssertOrderValidity(deleg, true, "ABC"); + AssertOrderValidity(deleg, true, "ABBC"); + AssertOrderValidity(deleg, true, "ABBBC"); + + // Let's check some invalid ones + AssertOrderValidity(deleg, false, "BC"); // Missing A + AssertOrderValidity(deleg, false, "AC"); // Too few Bs + AssertOrderValidity(deleg, false, "ABBBBC"); // Too many Bs + } + + private static void ConfigureOrderedTimesMinNonZeroMaxHigherThanMin(MockRepository mocks, I1 mockObject) + { + using (mocks.Ordered()) + { + mockObject.A(); + mockObject.B(); + LastCall.Repeat.Times(1, 3); + mockObject.C(); + } + } + #endregion + + #region TestOrderedAtLeastOnce + [Fact] + public void TestOrderedAtLeastOnce() + { + ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedAtLeastOnce); + + // Let's check some of the valid possibilities + AssertOrderValidity(deleg, true, "ABC"); + AssertOrderValidity(deleg, true, "ABBC"); + AssertOrderValidity(deleg, true, "ABBBBBBBBBBBBBBBBBBBBC"); + + // Let's check some invalid ones + AssertOrderValidity(deleg, false, "BC"); // Missing A + AssertOrderValidity(deleg, false, "AC"); // Too few Bs + } + + private static void ConfigureOrderedAtLeastOnce(MockRepository mocks, I1 mockObject) + { + using (mocks.Ordered()) + { + mockObject.A(); + mockObject.B(); + LastCall.Repeat.AtLeastOnce(); + mockObject.C(); + } + } + #endregion + + #region TestOrderedTimesMin0WithNestedUnordered + [Fact] + public void TestOrderedTimesMin0WithNestedUnordered() + { + ConfigureMockDelegate deleg = new ConfigureMockDelegate(ConfigureOrderedTimesMin0WithNestedUnordered); + + // Let's check all the valid possibilities + AssertOrderValidity(deleg, true, "BC"); + AssertOrderValidity(deleg, true, "CB"); + AssertOrderValidity(deleg, true, "ABC"); + AssertOrderValidity(deleg, true, "ACB"); + AssertOrderValidity(deleg, true, "BCA"); + AssertOrderValidity(deleg, true, "CBA"); + AssertOrderValidity(deleg, true, "ABCA"); + AssertOrderValidity(deleg, true, "ACBA"); + + // Let's check some invalid ones + AssertOrderValidity(deleg, false, ""); + AssertOrderValidity(deleg, false, "AA"); + AssertOrderValidity(deleg, false, "AABC"); + AssertOrderValidity(deleg, false, "AACB"); + AssertOrderValidity(deleg, false, "ABCAA"); + } + + private static void ConfigureOrderedTimesMin0WithNestedUnordered(MockRepository mocks, I1 mockObject) + { + using (mocks.Ordered()) + { + mockObject.A(); + LastCall.Repeat.Times(0, 1); + using (mocks.Unordered()) + { + mockObject.B(); + mockObject.C(); + } + mockObject.A(); + LastCall.Repeat.Times(0, 1); + } + } + #endregion + + #region Helper method for performing easy configuration and replay testing + /// + /// Sets up a mock, and runs through methods as specified by characters in . + /// + /// A delegate to use to configure the mock. + /// Whether the order should be valid or not. + /// The method order (e.g. "ABC", "ABBC"). + private static void AssertOrderValidity( ConfigureMockDelegate mockConfigurer, bool isValid, + string methodOrder ) + { + MockRepository mocks = new MockRepository(); + + I1 i = mocks.StrictMock(typeof(I1)) as I1; + + mockConfigurer(mocks, i); + + mocks.ReplayAll(); + + try + { + foreach (char c in methodOrder) + { + switch (c) + { + case 'A': + i.A(); + break; + case 'B': + i.B(); + break; + case 'C': + i.C(); + break; + default: + throw new NotSupportedException(); + } + } + mocks.VerifyAll(); + } + catch (Exceptions.ExpectationViolationException ex) + { + if (isValid) + { + Assert.False(true, string.Format("Order {0} was supposed to be ok, but got error: {1}", methodOrder, ex.Message)); + } + else + { + return; + } + } + + if (!isValid) + { + Assert.False(true, string.Format("Order {0} was supposed to fail, but did not.", methodOrder)); + } + } + #endregion + } + + public interface I1 + { + void A(); + void B(); + void C(); + } +} diff --git a/Rhino.Mocks.Tests/PartialMockTests.cs b/Rhino.Mocks.Tests/PartialMockTests.cs index 3faf0b2a..7fef8d6d 100644 --- a/Rhino.Mocks.Tests/PartialMockTests.cs +++ b/Rhino.Mocks.Tests/PartialMockTests.cs @@ -39,8 +39,8 @@ namespace Rhino.Mocks.Tests public class PartialMockTests { MockRepository mocks; - AbstractClass abs; - + AbstractClass abs; + public PartialMockTests() { mocks = new MockRepository(); @@ -90,9 +90,9 @@ public void CantCreatePartialMockFromInterfaces() [Fact] public void CallAnAbstractMethodWithoutSettingExpectation() { - mocks.ReplayAll(); - Assert.Throws("AbstractClass.Decrement(); Expected #0, Actual #1.", - () => abs.Decrement()); + mocks.ReplayAll(); + Assert.Throws("AbstractClass.Decrement(); Expected #0, Actual #1.", + () => abs.Decrement()); ; } diff --git a/Rhino.Mocks.Tests/PartialMockTestsAAA.cs b/Rhino.Mocks.Tests/PartialMockTestsAAA.cs index 2264675c..447e7a12 100644 --- a/Rhino.Mocks.Tests/PartialMockTestsAAA.cs +++ b/Rhino.Mocks.Tests/PartialMockTestsAAA.cs @@ -37,8 +37,8 @@ namespace Rhino.Mocks.Tests public class PartialMockTestsAAA { - private AbstractClass abs; - + private AbstractClass abs; + public PartialMockTestsAAA() { abs = (AbstractClass) MockRepository.GeneratePartialMock(typeof (AbstractClass), new Type[] {}); diff --git a/Rhino.Mocks.Tests/PropertySetterFixture.cs b/Rhino.Mocks.Tests/PropertySetterFixture.cs index 0256ebde..a070924e 100644 --- a/Rhino.Mocks.Tests/PropertySetterFixture.cs +++ b/Rhino.Mocks.Tests/PropertySetterFixture.cs @@ -1,91 +1,91 @@ -using Xunit; -using Rhino.Mocks.Exceptions; - -namespace Rhino.Mocks.Tests -{ - - public class PropertySetterFixture - { - [Fact] - public void Setter_Expectation_With_Custom_Ignore_Arguments() - { - MockRepository mocks = new MockRepository(); - - IBar bar = mocks.StrictMock(); - - using(mocks.Record()) - { - Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument(); - } - - using(mocks.Playback()) - { - bar.Foo = 2; - } - - mocks.VerifyAll(); - } - - [Fact] - public void Setter_Expectation_Not_Fullfilled() - { - MockRepository mocks = new MockRepository(); - - IBar bar = mocks.StrictMock(); - - using (mocks.Record()) - { - Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument(); - } - - Assert.Throws("IBar.set_Foo(any); Expected #1, Actual #0.", () => - { - using (mocks.Playback()) - { - } - }); - } - - [Fact] - public void Setter_Expectation_With_Correct_Argument() - { - MockRepository mocks = new MockRepository(); - - IBar bar = mocks.StrictMock(); - - using (mocks.Record()) - { - Expect.Call(bar.Foo).SetPropertyWithArgument(1); - } - - using (mocks.Playback()) - { - bar.Foo = 1; - } - - mocks.VerifyAll(); - } - - [Fact] - public void Setter_Expectation_With_Wrong_Argument() - { - MockRepository mocks = new MockRepository(); - - IBar bar = mocks.StrictMock(); - - using (mocks.Record()) - { - Expect.Call(bar.Foo).SetPropertyWithArgument(1); - } - - mocks.Playback(); - Assert.Throws( - "IBar.set_Foo(0); Expected #0, Actual #1.\r\nIBar.set_Foo(1); Expected #1, Actual #0.", () => { bar.Foo = 0; }); - } - } - - public interface IBar - { - int Foo { get; set; } - } +using Xunit; +using Rhino.Mocks.Exceptions; + +namespace Rhino.Mocks.Tests +{ + + public class PropertySetterFixture + { + [Fact] + public void Setter_Expectation_With_Custom_Ignore_Arguments() + { + MockRepository mocks = new MockRepository(); + + IBar bar = mocks.StrictMock(); + + using(mocks.Record()) + { + Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument(); + } + + using(mocks.Playback()) + { + bar.Foo = 2; + } + + mocks.VerifyAll(); + } + + [Fact] + public void Setter_Expectation_Not_Fullfilled() + { + MockRepository mocks = new MockRepository(); + + IBar bar = mocks.StrictMock(); + + using (mocks.Record()) + { + Expect.Call(bar.Foo).SetPropertyAndIgnoreArgument(); + } + + Assert.Throws("IBar.set_Foo(any); Expected #1, Actual #0.", () => + { + using (mocks.Playback()) + { + } + }); + } + + [Fact] + public void Setter_Expectation_With_Correct_Argument() + { + MockRepository mocks = new MockRepository(); + + IBar bar = mocks.StrictMock(); + + using (mocks.Record()) + { + Expect.Call(bar.Foo).SetPropertyWithArgument(1); + } + + using (mocks.Playback()) + { + bar.Foo = 1; + } + + mocks.VerifyAll(); + } + + [Fact] + public void Setter_Expectation_With_Wrong_Argument() + { + MockRepository mocks = new MockRepository(); + + IBar bar = mocks.StrictMock(); + + using (mocks.Record()) + { + Expect.Call(bar.Foo).SetPropertyWithArgument(1); + } + + mocks.Playback(); + Assert.Throws( + "IBar.set_Foo(0); Expected #0, Actual #1.\r\nIBar.set_Foo(1); Expected #1, Actual #0.", () => { bar.Foo = 0; }); + } + } + + public interface IBar + { + int Foo { get; set; } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/RecordReplaySyntax/RecordPlaybackTests.cs b/Rhino.Mocks.Tests/RecordReplaySyntax/RecordPlaybackTests.cs index 25d29201..7e7356da 100644 --- a/Rhino.Mocks.Tests/RecordReplaySyntax/RecordPlaybackTests.cs +++ b/Rhino.Mocks.Tests/RecordReplaySyntax/RecordPlaybackTests.cs @@ -60,13 +60,13 @@ public void PlaybackThrowsOtherExceptionDoesntReport() using (mockRepository.Record()) { Expect.Call(mockedFoo.Bar()).Return(42); - } - Assert.Throws(delegate - { - using (mockRepository.Playback()) - { - throw new ArgumentException(); - } + } + Assert.Throws(delegate + { + using (mockRepository.Playback()) + { + throw new ArgumentException(); + } }); } @@ -76,13 +76,13 @@ public void RecordThrowsOtherExceptionDoesntReport() MockRepository mockRepository; mockRepository = new MockRepository(); IFoo mockedFoo = mockRepository.StrictMock(); - Assert.Throws(() => - { + Assert.Throws(() => + { using (mockRepository.Record()) { mockedFoo.Bar(); //create expectation but doesn't setup return value throw new ArgumentException(); - } + } }); } } diff --git a/Rhino.Mocks.Tests/RecordingMocks.cs b/Rhino.Mocks.Tests/RecordingMocks.cs index 7caf6f4c..9f58243a 100644 --- a/Rhino.Mocks.Tests/RecordingMocks.cs +++ b/Rhino.Mocks.Tests/RecordingMocks.cs @@ -560,7 +560,7 @@ public void CanAssertOnMethodCallUsingConstraints_WhenMethodNotFound() demo.Bar("yoho"); - Assert.Throws( + Assert.Throws( "IFoo54.Bar(a => (a.StartsWith(\"b\") && a.Contains(\"ba\"))); Expected #1, Actual #0." , () => demo.AssertWasCalled(x => x.Bar(Arg.Matches((string a) => a.StartsWith("b") && a.Contains("ba"))))); } diff --git a/Rhino.Mocks.Tests/RecursiveMocks.cs b/Rhino.Mocks.Tests/RecursiveMocks.cs index fdc2ddbe..15e1f773 100644 --- a/Rhino.Mocks.Tests/RecursiveMocks.cs +++ b/Rhino.Mocks.Tests/RecursiveMocks.cs @@ -36,8 +36,8 @@ public void CanUseRecursiveMocksSimpler() mockService.Expect(x => x.Identity.Name).Return("foo"); Assert.Equal("foo", mockService.Identity.Name); - } - + } + [Fact(Skip = "Not supported right now as per Oren")] public void CanUseRecursiveMocksSimplerAlternateSyntax() { @@ -46,8 +46,8 @@ public void CanUseRecursiveMocksSimplerAlternateSyntax() Expect.Call(mockService.Identity.Name).Return("foo"); Assert.Equal("foo", mockService.Identity.Name); - } - + } + [Fact(Skip = "Not supported in replay mode")] public void WillGetSameInstanceOfRecursedMockForGenerateMockStatic() { @@ -58,8 +58,8 @@ public void WillGetSameInstanceOfRecursedMockForGenerateMockStatic() Assert.Same(i1, i2); Assert.NotNull(i1); - } - + } + [Fact(Skip = "Not supported in replay mode")] public void WillGetSameInstanceOfRecursedMockInReplayMode() { diff --git a/Rhino.Mocks.Tests/RemotingMockTests.cs b/Rhino.Mocks.Tests/RemotingMockTests.cs index 4ca781ca..bff035f7 100644 --- a/Rhino.Mocks.Tests/RemotingMockTests.cs +++ b/Rhino.Mocks.Tests/RemotingMockTests.cs @@ -1,389 +1,389 @@ -#region license - -// Copyright (c) 2007 Ivan Krivyakov (ivan@ikriv.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#endregion - -using System; -using Xunit; -using Rhino.Mocks.Exceptions; - -namespace Rhino.Mocks.Tests -{ - - public class StrictMockTests - { - public class TestClass : MarshalByRefObject - { - public TestClass(string unused) - { - throw new InvalidCastException("Real method should never be called"); - } - - public void Method() - { - throw new InvalidCastException("Real method should never be called"); - } - - public int MethodReturningInt() - { - throw new InvalidCastException("Real method should never be called"); - } - - public string MethodReturningString() - { - throw new InvalidCastException("Real method should never be called"); - } - - public string MethodGettingParameters(int intParam, string stringParam) - { - throw new InvalidCastException("Real method should never be called"); - } - - public void MethodAcceptingTestClass(TestClass other) - { - throw new InvalidCastException("Real method should never be called"); - } - - public int GenericMethod(string parameter) - { - throw new InvalidCastException("Real method should never be called"); - } - - public T GenericMethodReturningGenericType(string parameter) - { - throw new InvalidCastException("Real method should never be called"); - } - - public T GenericMethodWithGenericParam( T parameter ) - { - throw new InvalidCastException("Real method should never be called"); - } - - public string StringProperty - { - get - { - throw new InvalidCastException("Real method should never be called"); - } - set - { - throw new InvalidCastException("Real method should never be called"); - } - } - } - - public class GenericTestClass : MarshalByRefObject - { - public int Method(T parameter) - { - throw new InvalidCastException("Real method should never be called"); - } - - public U GenericMethod(T parameter) - { - throw new InvalidCastException("Real method should never be called"); - } - } - - [Fact] - public void CanMockVoidMethod() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - t.Method(); - mocks.ReplayAll(); - t.Method(); - mocks.VerifyAll(); - } - - [Fact] - public void ThrowOnUnexpectedVoidMethod() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - mocks.ReplayAll(); - - Assert.Throws( - "TestClass.Method(); Expected #0, Actual #1.", - () => t.Method()); - } - - [Fact] - public void CanMockMethodReturningInt() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.MethodReturningInt()).Return(42); - mocks.ReplayAll(); - Assert.Equal(42, t.MethodReturningInt()); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockMethodReturningString() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.MethodReturningString()).Return("foo"); - mocks.ReplayAll(); - Assert.Equal("foo", t.MethodReturningString()); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockMethodGettingParameters() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.MethodGettingParameters(42, "foo")).Return("bar"); - mocks.ReplayAll(); - Assert.Equal("bar", t.MethodGettingParameters(42, "foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanRejectIncorrectParameters() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.MethodGettingParameters(42, "foo")).Return("bar"); - mocks.ReplayAll(); - Assert.Throws( - "TestClass.MethodGettingParameters(19, \"foo\"); Expected #0, Actual #1.\r\nTestClass.MethodGettingParameters(42, \"foo\"); Expected #1, Actual #0.", - () => t.MethodGettingParameters(19, "foo")); - } - - [Fact] - public void CanMockPropertyGet() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.StringProperty).Return("foo"); - mocks.ReplayAll(); - Assert.Equal("foo", t.StringProperty); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockPropertySet() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - t.StringProperty = "foo"; - mocks.ReplayAll(); - t.StringProperty = "foo"; - mocks.VerifyAll(); - } - - [Fact] - public void CanRejectIncorrectPropertySet() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - t.StringProperty = "foo"; - mocks.ReplayAll(); - Assert.Throws( - "TestClass.set_StringProperty(\"bar\"); Expected #0, Actual #1.\r\nTestClass.set_StringProperty(\"foo\"); Expected #1, Actual #0.", - () => t.StringProperty = "bar"); - } - - [Fact] - public void CanMockGenericClass() - { - MockRepository mocks = new MockRepository(); - GenericTestClass t = (GenericTestClass)mocks.StrictMock(typeof(GenericTestClass)); - Expect.Call(t.Method("foo")).Return(42); - mocks.ReplayAll(); - Assert.Equal(42, t.Method("foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockGenericMethod() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.GenericMethod("foo")).Return(42); - mocks.ReplayAll(); - Assert.Equal(42, t.GenericMethod("foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockGenericMethod_WillErrorOnWrongType() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.GenericMethod("foo")).Return(42); - mocks.ReplayAll(); - - Assert.Throws( - @"TestClass.GenericMethod(""foo""); Expected #1, Actual #1. -TestClass.GenericMethod(""foo""); Expected #1, Actual #0.", - () => Assert.Equal(42, t.GenericMethod("foo"))); - } - - [Fact] - public void CanMockGenericMethodReturningGenericType() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.GenericMethodReturningGenericType("foo")).Return("bar"); - mocks.ReplayAll(); - Assert.Equal("bar", t.GenericMethodReturningGenericType("foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockGenericMethodWithGenericParam() - { - MockRepository mocks = new MockRepository(); - TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); - Expect.Call(t.GenericMethodWithGenericParam("foo")).Return("bar"); - mocks.ReplayAll(); - Assert.Equal("bar", t.GenericMethodWithGenericParam("foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockGenericMethodInGenericClass() - { - MockRepository mocks = new MockRepository(); - GenericTestClass t = mocks.StrictMock>(); - Expect.Call(t.GenericMethod("foo")).Return(42); - mocks.ReplayAll(); - Assert.Equal(42, t.GenericMethod("foo")); - mocks.VerifyAll(); - } - - [Fact] - public void CanMockAppDomain() - { - MockRepository mocks = new MockRepository(); - AppDomain appDomain = mocks.StrictMock(); - Expect.Call(appDomain.BaseDirectory).Return("/home/user/ayende"); - mocks.ReplayAll(); - Assert.Equal(appDomain.BaseDirectory, "/home/user/ayende" ); - mocks.VerifyAll(); - } - - [Fact] - public void NotCallingExpectedMethodWillCauseVerificationError() - { - MockRepository mocks = new MockRepository(); - AppDomain appDomain = mocks.StrictMock(); - Expect.Call(appDomain.BaseDirectory).Return("/home/user/ayende"); - mocks.ReplayAll(); - Assert.Throws(@"AppDomain.get_BaseDirectory(); Expected #1, Actual #0.", - () => mocks.VerifyAll()); - } - - [Fact] - public void CanMockMethodAcceptingTestClass() - { - MockRepository mocks = new MockRepository(); - TestClass t1 = mocks.StrictMock(); - TestClass t2 = mocks.StrictMock(); - t1.MethodAcceptingTestClass(t2); - mocks.ReplayAll(); - t1.MethodAcceptingTestClass(t2); - mocks.VerifyAll(); - } - - [Fact] - // can't use ExpectedException since expected message is dynamic - public void CanMockMethodAcceptingTestClass_WillErrorOnWrongParameter() - { - string t2Text = "@"; - string t3Text = "@"; - - try - { - - MockRepository mocks = new MockRepository(); - TestClass t1 = mocks.StrictMock(); - TestClass t2 = mocks.StrictMock(); - TestClass t3 = mocks.StrictMock(); - t2Text = t2.ToString(); - t3Text = t3.ToString(); - - t1.MethodAcceptingTestClass(t2); - mocks.ReplayAll(); - t1.MethodAcceptingTestClass(t3); - mocks.VerifyAll(); - - Assert.False(true, "Expected ExpectationViolationException"); - } - catch (ExpectationViolationException ex) - { - string msg = - String.Format("TestClass.MethodAcceptingTestClass({0}); Expected #0, Actual #1.\r\n" + - "TestClass.MethodAcceptingTestClass({1}); Expected #1, Actual #0.", - t3Text, - t2Text); - - Assert.Equal(msg, ex.Message); - } - } - - [Fact] - public void StrictMockGetTypeReturnsMockedType() - { - MockRepository mocks = new MockRepository(); - TestClass t = mocks.StrictMock(); - Assert.Same(typeof(TestClass), t.GetType()); - } - - [Fact] - public void StrictMockGetHashCodeWorks() - { - MockRepository mocks = new MockRepository(); - TestClass t = mocks.StrictMock(); - t.GetHashCode(); - } - - [Fact] - public void StrictMockToStringReturnsDescription() - { - MockRepository mocks = new MockRepository(); - TestClass t = mocks.StrictMock(); - int hashCode = t.GetHashCode(); - string toString = t.ToString(); - Assert.Equal(String.Format("RemotingMock_{0}", hashCode), toString); - } - - [Fact] - public void StrictMockEquality() - { - MockRepository mocks = new MockRepository(); - TestClass t = mocks.StrictMock(); - - Assert.False(t.Equals(null)); - Assert.False(t.Equals(42)); - Assert.False(t.Equals("foo")); - Assert.True(t.Equals(t)); - } - } -} +#region license + +// Copyright (c) 2007 Ivan Krivyakov (ivan@ikriv.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using Xunit; +using Rhino.Mocks.Exceptions; + +namespace Rhino.Mocks.Tests +{ + + public class StrictMockTests + { + public class TestClass : MarshalByRefObject + { + public TestClass(string unused) + { + throw new InvalidCastException("Real method should never be called"); + } + + public void Method() + { + throw new InvalidCastException("Real method should never be called"); + } + + public int MethodReturningInt() + { + throw new InvalidCastException("Real method should never be called"); + } + + public string MethodReturningString() + { + throw new InvalidCastException("Real method should never be called"); + } + + public string MethodGettingParameters(int intParam, string stringParam) + { + throw new InvalidCastException("Real method should never be called"); + } + + public void MethodAcceptingTestClass(TestClass other) + { + throw new InvalidCastException("Real method should never be called"); + } + + public int GenericMethod(string parameter) + { + throw new InvalidCastException("Real method should never be called"); + } + + public T GenericMethodReturningGenericType(string parameter) + { + throw new InvalidCastException("Real method should never be called"); + } + + public T GenericMethodWithGenericParam( T parameter ) + { + throw new InvalidCastException("Real method should never be called"); + } + + public string StringProperty + { + get + { + throw new InvalidCastException("Real method should never be called"); + } + set + { + throw new InvalidCastException("Real method should never be called"); + } + } + } + + public class GenericTestClass : MarshalByRefObject + { + public int Method(T parameter) + { + throw new InvalidCastException("Real method should never be called"); + } + + public U GenericMethod(T parameter) + { + throw new InvalidCastException("Real method should never be called"); + } + } + + [Fact] + public void CanMockVoidMethod() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + t.Method(); + mocks.ReplayAll(); + t.Method(); + mocks.VerifyAll(); + } + + [Fact] + public void ThrowOnUnexpectedVoidMethod() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + mocks.ReplayAll(); + + Assert.Throws( + "TestClass.Method(); Expected #0, Actual #1.", + () => t.Method()); + } + + [Fact] + public void CanMockMethodReturningInt() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.MethodReturningInt()).Return(42); + mocks.ReplayAll(); + Assert.Equal(42, t.MethodReturningInt()); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockMethodReturningString() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.MethodReturningString()).Return("foo"); + mocks.ReplayAll(); + Assert.Equal("foo", t.MethodReturningString()); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockMethodGettingParameters() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.MethodGettingParameters(42, "foo")).Return("bar"); + mocks.ReplayAll(); + Assert.Equal("bar", t.MethodGettingParameters(42, "foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanRejectIncorrectParameters() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.MethodGettingParameters(42, "foo")).Return("bar"); + mocks.ReplayAll(); + Assert.Throws( + "TestClass.MethodGettingParameters(19, \"foo\"); Expected #0, Actual #1.\r\nTestClass.MethodGettingParameters(42, \"foo\"); Expected #1, Actual #0.", + () => t.MethodGettingParameters(19, "foo")); + } + + [Fact] + public void CanMockPropertyGet() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.StringProperty).Return("foo"); + mocks.ReplayAll(); + Assert.Equal("foo", t.StringProperty); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockPropertySet() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + t.StringProperty = "foo"; + mocks.ReplayAll(); + t.StringProperty = "foo"; + mocks.VerifyAll(); + } + + [Fact] + public void CanRejectIncorrectPropertySet() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + t.StringProperty = "foo"; + mocks.ReplayAll(); + Assert.Throws( + "TestClass.set_StringProperty(\"bar\"); Expected #0, Actual #1.\r\nTestClass.set_StringProperty(\"foo\"); Expected #1, Actual #0.", + () => t.StringProperty = "bar"); + } + + [Fact] + public void CanMockGenericClass() + { + MockRepository mocks = new MockRepository(); + GenericTestClass t = (GenericTestClass)mocks.StrictMock(typeof(GenericTestClass)); + Expect.Call(t.Method("foo")).Return(42); + mocks.ReplayAll(); + Assert.Equal(42, t.Method("foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockGenericMethod() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.GenericMethod("foo")).Return(42); + mocks.ReplayAll(); + Assert.Equal(42, t.GenericMethod("foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockGenericMethod_WillErrorOnWrongType() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.GenericMethod("foo")).Return(42); + mocks.ReplayAll(); + + Assert.Throws( + @"TestClass.GenericMethod(""foo""); Expected #1, Actual #1. +TestClass.GenericMethod(""foo""); Expected #1, Actual #0.", + () => Assert.Equal(42, t.GenericMethod("foo"))); + } + + [Fact] + public void CanMockGenericMethodReturningGenericType() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.GenericMethodReturningGenericType("foo")).Return("bar"); + mocks.ReplayAll(); + Assert.Equal("bar", t.GenericMethodReturningGenericType("foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockGenericMethodWithGenericParam() + { + MockRepository mocks = new MockRepository(); + TestClass t = (TestClass)mocks.StrictMock(typeof(TestClass)); + Expect.Call(t.GenericMethodWithGenericParam("foo")).Return("bar"); + mocks.ReplayAll(); + Assert.Equal("bar", t.GenericMethodWithGenericParam("foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockGenericMethodInGenericClass() + { + MockRepository mocks = new MockRepository(); + GenericTestClass t = mocks.StrictMock>(); + Expect.Call(t.GenericMethod("foo")).Return(42); + mocks.ReplayAll(); + Assert.Equal(42, t.GenericMethod("foo")); + mocks.VerifyAll(); + } + + [Fact] + public void CanMockAppDomain() + { + MockRepository mocks = new MockRepository(); + AppDomain appDomain = mocks.StrictMock(); + Expect.Call(appDomain.BaseDirectory).Return("/home/user/ayende"); + mocks.ReplayAll(); + Assert.Equal(appDomain.BaseDirectory, "/home/user/ayende" ); + mocks.VerifyAll(); + } + + [Fact] + public void NotCallingExpectedMethodWillCauseVerificationError() + { + MockRepository mocks = new MockRepository(); + AppDomain appDomain = mocks.StrictMock(); + Expect.Call(appDomain.BaseDirectory).Return("/home/user/ayende"); + mocks.ReplayAll(); + Assert.Throws(@"AppDomain.get_BaseDirectory(); Expected #1, Actual #0.", + () => mocks.VerifyAll()); + } + + [Fact] + public void CanMockMethodAcceptingTestClass() + { + MockRepository mocks = new MockRepository(); + TestClass t1 = mocks.StrictMock(); + TestClass t2 = mocks.StrictMock(); + t1.MethodAcceptingTestClass(t2); + mocks.ReplayAll(); + t1.MethodAcceptingTestClass(t2); + mocks.VerifyAll(); + } + + [Fact] + // can't use ExpectedException since expected message is dynamic + public void CanMockMethodAcceptingTestClass_WillErrorOnWrongParameter() + { + string t2Text = "@"; + string t3Text = "@"; + + try + { + + MockRepository mocks = new MockRepository(); + TestClass t1 = mocks.StrictMock(); + TestClass t2 = mocks.StrictMock(); + TestClass t3 = mocks.StrictMock(); + t2Text = t2.ToString(); + t3Text = t3.ToString(); + + t1.MethodAcceptingTestClass(t2); + mocks.ReplayAll(); + t1.MethodAcceptingTestClass(t3); + mocks.VerifyAll(); + + Assert.False(true, "Expected ExpectationViolationException"); + } + catch (ExpectationViolationException ex) + { + string msg = + String.Format("TestClass.MethodAcceptingTestClass({0}); Expected #0, Actual #1.\r\n" + + "TestClass.MethodAcceptingTestClass({1}); Expected #1, Actual #0.", + t3Text, + t2Text); + + Assert.Equal(msg, ex.Message); + } + } + + [Fact] + public void StrictMockGetTypeReturnsMockedType() + { + MockRepository mocks = new MockRepository(); + TestClass t = mocks.StrictMock(); + Assert.Same(typeof(TestClass), t.GetType()); + } + + [Fact] + public void StrictMockGetHashCodeWorks() + { + MockRepository mocks = new MockRepository(); + TestClass t = mocks.StrictMock(); + t.GetHashCode(); + } + + [Fact] + public void StrictMockToStringReturnsDescription() + { + MockRepository mocks = new MockRepository(); + TestClass t = mocks.StrictMock(); + int hashCode = t.GetHashCode(); + string toString = t.ToString(); + Assert.Equal(String.Format("RemotingMock_{0}", hashCode), toString); + } + + [Fact] + public void StrictMockEquality() + { + MockRepository mocks = new MockRepository(); + TestClass t = mocks.StrictMock(); + + Assert.False(t.Equals(null)); + Assert.False(t.Equals(42)); + Assert.False(t.Equals("foo")); + Assert.True(t.Equals(t)); + } + } +} diff --git a/Rhino.Mocks.Tests/Rhino.Mocks.Tests.csproj b/Rhino.Mocks.Tests/Rhino.Mocks.Tests.csproj index 4041fa19..5decf81c 100644 --- a/Rhino.Mocks.Tests/Rhino.Mocks.Tests.csproj +++ b/Rhino.Mocks.Tests/Rhino.Mocks.Tests.csproj @@ -1,455 +1,455 @@ - - - Local - 9.0.30729 - 2.0 - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20} - Debug - AnyCPU - Rhino.Mocks.Tests - JScript - Grid - IE50 - false - Library - Rhino.Mocks.Tests - OnBuildSuccess - true - ..\ayende-open-source.snk - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - v3.5 - - - bin\debug\ - false - 285212672 - false - TRACE;DEBUG;DOTNET35 - true - 4096 - false - false - false - false - false - 4 - false - Full - 1607 - - - ..\..\Build\Tests\Release\ - false - 285212672 - false - TRACE;dotNet2 - false - 4096 - false - true - false - false - false - 4 - - - Program - C:\Program Files\MbUnit\MbUnit.GUI.exe - D:\OSS\rhino-tools\rhino-mocks\Rhino.Mocks.Tests\bin\debug\Rhino.Mocks.Tests.dll - - - Auto - AnyCPU - - - - False - ..\SharedLibs\Castle.Core.dll - - - False - ..\SharedLibs\Castle.DynamicProxy2.dll - - - False - ..\SharedLibs\Interop.ADODB.dll - - - False - ..\SharedLibs\Interop.MSHTML.dll - - - False - ..\SharedLibs\Microsoft.Practices.Unity.dll - - - False - ..\SharedLibs\Rhino.Mocks.CPP.Interfaces.dll - - - False - ..\SharedLibs\Scripting.dll - - - System - - - - 3.5 - - - System.Data - - - System.EnterpriseServices - - - 3.0 - - - System.Web - - - - System.XML - - - False - ..\SharedLibs\xunit.dll - - - False - ..\SharedLibs\xunit.extensions.dll - - - - - - Code - - - - Code - - - - Code - - - Code - - - Code - - - - Code - - - Code - - - Code - - - - - - - - - - - - - - - - - - Component - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - Code - - - Code - - - Code - - - Code - - - Code - - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - - - - Code - - - - Code - - - - - - - - - - - - - - - - - - Code - - - Code - - - - - - - - - - - - Code - - - Code - - - - - {3078B943-10A5-41FA-A68A-7C4FC98506A0} - Rhino.Mocks.Tests.Model - - - Rhino.Mocks - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8} - {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - - - - - - False - .NET Framework 2.0 %28x86%29 - true - - - False - .NET Framework 3.0 %28x86%29 - false - - - False - .NET Framework 3.5 - false - - - - - ayende-open-source.snk - - - + + + Local + 9.0.30729 + 2.0 + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20} + Debug + AnyCPU + Rhino.Mocks.Tests + JScript + Grid + IE50 + false + Library + Rhino.Mocks.Tests + OnBuildSuccess + true + ..\ayende-open-source.snk + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + v3.5 + + + bin\debug\ + false + 285212672 + false + TRACE;DEBUG;DOTNET35 + true + 4096 + false + false + false + false + false + 4 + false + Full + 1607 + + + ..\..\Build\Tests\Release\ + false + 285212672 + false + TRACE;dotNet2 + false + 4096 + false + true + false + false + false + 4 + + + Program + C:\Program Files\MbUnit\MbUnit.GUI.exe + D:\OSS\rhino-tools\rhino-mocks\Rhino.Mocks.Tests\bin\debug\Rhino.Mocks.Tests.dll + + + Auto + AnyCPU + + + + False + ..\SharedLibs\Castle.Core.dll + + + False + ..\SharedLibs\Castle.DynamicProxy2.dll + + + False + ..\SharedLibs\Interop.ADODB.dll + + + False + ..\SharedLibs\Interop.MSHTML.dll + + + False + ..\SharedLibs\Microsoft.Practices.Unity.dll + + + False + ..\SharedLibs\Rhino.Mocks.CPP.Interfaces.dll + + + False + ..\SharedLibs\Scripting.dll + + + System + + + + 3.5 + + + System.Data + + + System.EnterpriseServices + + + 3.0 + + + System.Web + + + + System.XML + + + False + ..\SharedLibs\xunit.dll + + + False + ..\SharedLibs\xunit.extensions.dll + + + + + + Code + + + + Code + + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + + + + + + + + + + + + + + + + Component + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + Code + + + + Code + + + + Code + + + + + + + + + + + + + + + + + + Code + + + Code + + + + + + + + + + + + Code + + + Code + + + + + {3078B943-10A5-41FA-A68A-7C4FC98506A0} + Rhino.Mocks.Tests.Model + + + Rhino.Mocks + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + + + + + + False + .NET Framework 2.0 %28x86%29 + true + + + False + .NET Framework 3.0 %28x86%29 + false + + + False + .NET Framework 3.5 + false + + + + + ayende-open-source.snk + + + \ No newline at end of file diff --git a/Rhino.Mocks.Tests/RhinoMockTests.cs b/Rhino.Mocks.Tests/RhinoMockTests.cs index cce22f19..7d6c5bc8 100644 --- a/Rhino.Mocks.Tests/RhinoMockTests.cs +++ b/Rhino.Mocks.Tests/RhinoMockTests.cs @@ -1,380 +1,380 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using System.Collections; -using System.ServiceModel; -using Xunit; -using Rhino.Mocks.Exceptions; -using Rhino.Mocks.Tests.Callbacks; - -namespace Rhino.Mocks.Tests -{ - - public class RhinoMockTests - { - private MockRepository mocks; - private IDemo demo; - - public RhinoMockTests() - { - mocks = new MockRepository(); - demo = this.mocks.StrictMock(typeof (IDemo)) as IDemo; - } - - [Fact] - public void CallsAreNotOrderDependant() - { - this.demo.ReturnStringNoArgs(); - LastCall.On(this.demo).Return(null); - this.demo.VoidStringArg("Hello"); - this.mocks.Replay(this.demo); - this.demo.VoidStringArg("Hello"); - this.demo.ReturnStringNoArgs(); - this.mocks.Verify(this.demo); - } - - [Fact] - public void OrderedCallsTrackingAsExpected() - { - RecordOrdered(mocks, demo); - - mocks.Replay(demo); - demo.ReturnStringNoArgs(); - demo.VoidNoArgs(); - demo.VoidNoArgs(); - demo.VoidStringArg("Hello"); - demo.VoidStringArg("World"); - mocks.Verify(demo); - } - - [Fact] - public void GetDocumentationMessageWhenExpectationNotMet() - { - RecordOrdered(mocks, demo); - mocks.Replay(demo); - - demo.ReturnStringNoArgs(); - demo.VoidNoArgs(); - - - Assert.Throws( - "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(); }' but was: 'IDemo.VoidStringArg(\"Hello\");'", - () => demo.VoidStringArg("Hello")); - - } - - [Fact] - public void WillDisplayDocumentationMessageIfNotCalled() - { - demo.VoidNoArgs(); - LastCall.On(demo) - .IgnoreArguments() - .Message("Called to prefar foo for bar"); - - mocks.Replay(demo); - - Assert.Throws( - "Message: Called to prefar foo for bar\nIDemo.VoidNoArgs(); Expected #1, Actual #0.", - () => mocks.Verify(demo)); - } - - [Fact] - public void WillDiplayDocumentationMessageIfCalledTooMuch() - { - demo.VoidNoArgs(); - LastCall.Message("Should be called only once"); - - mocks.ReplayAll(); - - demo.VoidNoArgs(); - ; - - Assert.Throws( - @"IDemo.VoidNoArgs(); Expected #1, Actual #2. -Message: Should be called only once", - () => demo.VoidNoArgs()); - } - - [Fact] - public void LastMockedObjectIsNullAfterDisposingMockRepository() - { - MockRepository mocks = new MockRepository(); - mocks.ReplayAll(); - mocks.VerifyAll(); - ; - - Assert.Throws( - "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", - () => LastCall.IgnoreArguments()); - } - - [Fact] - public void MixOrderedAndUnorderedBehaviour() - { - using (mocks.Ordered()) - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); - demo.VoidStringArg("Ayende"); - using (mocks.Unordered()) - { - demo.VoidStringArg("Rahien"); - demo.VoidThreeStringArgs("1", "2", "3"); - } - demo.StringArgString("Hello"); - LastCall.On(demo).Return("World"); - } - mocks.Replay(demo); - Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); - Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); - demo.VoidStringArg("Ayende"); - demo.VoidThreeStringArgs("1", "2", "3"); - demo.VoidStringArg("Rahien"); - Assert.Equal("World", demo.StringArgString("Hello")); - - mocks.Verify(demo); - } - - [Fact] - public void ChangingRecordersWhenReplayingDoesNotInterruptVerification() - { - demo.VoidStringArg("ayende"); - mocks.Replay(demo); - using (mocks.Ordered()) - { - demo.VoidStringArg("ayende"); - } - mocks.Verify(demo); - } - - [Fact] - public void CallingReplayInOrderringThrows() - { - demo.VoidStringArg("ayende"); - Assert.Throws("Can't start replaying because Ordered or Unordered properties were call and not yet disposed.", - () => - { - using (mocks.Ordered()) - { - mocks.Replay(demo); - } - }); - } - - [Fact] - public void UsingSeveralObjectAndMixingOrderAndUnorder() - { - IList second = mocks.StrictMock(typeof (IList)) as IList; - using (mocks.Ordered()) - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); - second.Clear(); - demo.VoidStringArg("Ayende"); - using (mocks.Unordered()) - { - int i = second.Count; - LastCall.On(second).Repeat.Twice().Return(3); - demo.VoidStringArg("Rahien"); - demo.VoidThreeStringArgs("1", "2", "3"); - } - demo.StringArgString("Hello"); - LastCall.On(demo).Return("World"); - second.IndexOf(null); - LastCall.On(second).Return(2); - } - - mocks.Replay(demo); - mocks.Replay(second); - - Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); - Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); - second.Clear(); - demo.VoidStringArg("Ayende"); - Assert.Equal(3, second.Count); - demo.VoidThreeStringArgs("1", "2", "3"); - Assert.Equal(3, second.Count); - demo.VoidStringArg("Rahien"); - Assert.Equal("World", demo.StringArgString("Hello")); - second.IndexOf(null); - mocks.Verify(demo); - } - - [Fact] - public void SeveralMocksUsingOrdered() - { - IList second = mocks.StrictMock(typeof (IList)) as IList; - using (mocks.Ordered()) - { - demo.EnumNoArgs(); - LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); - second.Clear(); - demo.VoidStringArg("Ayende"); - using (mocks.Unordered()) - { - int i = second.Count; - LastCall.On(second).Repeat.Twice().Return(3); - demo.VoidStringArg("Rahien"); - demo.VoidThreeStringArgs("1", "2", "3"); - } - demo.StringArgString("Hello"); - LastCall.On(demo).Return("World"); - second.IndexOf(null); - LastCall.On(second).Return(2); - } - - mocks.Replay(demo); - mocks.Replay(second); - - demo.EnumNoArgs(); - Assert.Throws( - "Unordered method call! The expected call is: 'Ordered: { IDemo.EnumNoArgs(); }' but was: 'IList.Clear();'", - () => second.Clear()); - } - - [Fact] - public void RecursiveExpectationsOnUnordered() - { - demo = (IDemo) mocks.StrictMock(typeof (IDemo)); - demo.VoidNoArgs(); - LastCall.On(demo).Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); - demo.VoidStringArg("Ayende"); - mocks.Replay(demo); - demo.VoidNoArgs(); - mocks.Verify(demo); - } - - [Fact] - public void RecursiveExpectationsOnOrdered() - { - demo = (IDemo) mocks.StrictMock(typeof (IDemo)); - using (mocks.Ordered()) - { - demo.VoidNoArgs(); - LastCall.On(demo).Callback(CallMethodOnDemo); - demo.VoidStringArg("Ayende"); - } - mocks.Replay(demo); - Assert.Throws( - "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(callback method: RhinoMockTests.CallMethodOnDemo); }' but was: 'IDemo.VoidStringArg(\"Ayende\");'", - () => demo.VoidNoArgs()); - } - - - [Fact] - public void GetArgsOfEpectedAndActualMethodCallOnException() - { - demo = (IDemo) mocks.StrictMock(typeof (IDemo)); - demo.VoidThreeStringArgs("a","b","c"); - mocks.Replay(demo); - - Assert.Throws( - "IDemo.VoidThreeStringArgs(\"c\", \"b\", \"a\"); Expected #0, Actual #1.\r\nIDemo.VoidThreeStringArgs(\"a\", \"b\", \"c\"); Expected #1, Actual #0.", - () => demo.VoidThreeStringArgs("c", "b", "a")); - } - - - [Fact] - public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() - { - demo = (IDemo) mocks.StrictMock(typeof (IDemo)); - demo.VoidThreeStringArgs("", "", ""); - using (mocks.Ordered()) - { - demo.VoidNoArgs(); - demo.VoidStringArg("Ayende"); - } - mocks.Replay(demo); - demo.VoidNoArgs(); - - Assert.Throws( - "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'", - () => demo.VoidThreeStringArgs("", "", "")); - } - - [Fact] - public void Overrideing_ToString() - { - MockRepository mocks = new MockRepository(); - ObjectThatOverrideToString oid = (ObjectThatOverrideToString) - mocks.StrictMock(typeof (ObjectThatOverrideToString)); - Expect.On(oid).Call(oid.ToString()).Return("bla"); - mocks.ReplayAll(); - Assert.Equal("bla", oid.ToString()); - mocks.VerifyAll(); - } - - [Fact] - public void CallbackThatThrows() - { - demo = (IDemo) mocks.StrictMock(typeof (IDemo)); - demo.VoidNoArgs(); - LastCall.Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); - mocks.ReplayAll(); - Assert.Throws(demo.VoidNoArgs); - } - - #region Private Methods - - private static void RecordOrdered(MockRepository mocks, IDemo demo) - { - using (mocks.Ordered()) - { - demo.ReturnStringNoArgs(); - LastCall.On(demo).Return(null); - demo.VoidNoArgs(); - LastCall.On(demo).Repeat.Twice(); - demo.VoidStringArg("Hello"); - demo.VoidStringArg("World"); - } - } - - #endregion - - private bool CallMethodOnDemo() - { - demo.VoidStringArg("Ayende"); - return true; - } - - private bool ThrowFromCallback() - { - throw new AddressAlreadyInUseException(); - } - - public class ObjectThatOverrideToString - { - public override string ToString() - { - return base.ToString (); - } - } - } +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using System.Collections; +using System.ServiceModel; +using Xunit; +using Rhino.Mocks.Exceptions; +using Rhino.Mocks.Tests.Callbacks; + +namespace Rhino.Mocks.Tests +{ + + public class RhinoMockTests + { + private MockRepository mocks; + private IDemo demo; + + public RhinoMockTests() + { + mocks = new MockRepository(); + demo = this.mocks.StrictMock(typeof (IDemo)) as IDemo; + } + + [Fact] + public void CallsAreNotOrderDependant() + { + this.demo.ReturnStringNoArgs(); + LastCall.On(this.demo).Return(null); + this.demo.VoidStringArg("Hello"); + this.mocks.Replay(this.demo); + this.demo.VoidStringArg("Hello"); + this.demo.ReturnStringNoArgs(); + this.mocks.Verify(this.demo); + } + + [Fact] + public void OrderedCallsTrackingAsExpected() + { + RecordOrdered(mocks, demo); + + mocks.Replay(demo); + demo.ReturnStringNoArgs(); + demo.VoidNoArgs(); + demo.VoidNoArgs(); + demo.VoidStringArg("Hello"); + demo.VoidStringArg("World"); + mocks.Verify(demo); + } + + [Fact] + public void GetDocumentationMessageWhenExpectationNotMet() + { + RecordOrdered(mocks, demo); + mocks.Replay(demo); + + demo.ReturnStringNoArgs(); + demo.VoidNoArgs(); + + + Assert.Throws( + "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(); }' but was: 'IDemo.VoidStringArg(\"Hello\");'", + () => demo.VoidStringArg("Hello")); + + } + + [Fact] + public void WillDisplayDocumentationMessageIfNotCalled() + { + demo.VoidNoArgs(); + LastCall.On(demo) + .IgnoreArguments() + .Message("Called to prefar foo for bar"); + + mocks.Replay(demo); + + Assert.Throws( + "Message: Called to prefar foo for bar\nIDemo.VoidNoArgs(); Expected #1, Actual #0.", + () => mocks.Verify(demo)); + } + + [Fact] + public void WillDiplayDocumentationMessageIfCalledTooMuch() + { + demo.VoidNoArgs(); + LastCall.Message("Should be called only once"); + + mocks.ReplayAll(); + + demo.VoidNoArgs(); + ; + + Assert.Throws( + @"IDemo.VoidNoArgs(); Expected #1, Actual #2. +Message: Should be called only once", + () => demo.VoidNoArgs()); + } + + [Fact] + public void LastMockedObjectIsNullAfterDisposingMockRepository() + { + MockRepository mocks = new MockRepository(); + mocks.ReplayAll(); + mocks.VerifyAll(); + ; + + Assert.Throws( + "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", + () => LastCall.IgnoreArguments()); + } + + [Fact] + public void MixOrderedAndUnorderedBehaviour() + { + using (mocks.Ordered()) + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); + demo.VoidStringArg("Ayende"); + using (mocks.Unordered()) + { + demo.VoidStringArg("Rahien"); + demo.VoidThreeStringArgs("1", "2", "3"); + } + demo.StringArgString("Hello"); + LastCall.On(demo).Return("World"); + } + mocks.Replay(demo); + Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); + Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); + demo.VoidStringArg("Ayende"); + demo.VoidThreeStringArgs("1", "2", "3"); + demo.VoidStringArg("Rahien"); + Assert.Equal("World", demo.StringArgString("Hello")); + + mocks.Verify(demo); + } + + [Fact] + public void ChangingRecordersWhenReplayingDoesNotInterruptVerification() + { + demo.VoidStringArg("ayende"); + mocks.Replay(demo); + using (mocks.Ordered()) + { + demo.VoidStringArg("ayende"); + } + mocks.Verify(demo); + } + + [Fact] + public void CallingReplayInOrderringThrows() + { + demo.VoidStringArg("ayende"); + Assert.Throws("Can't start replaying because Ordered or Unordered properties were call and not yet disposed.", + () => + { + using (mocks.Ordered()) + { + mocks.Replay(demo); + } + }); + } + + [Fact] + public void UsingSeveralObjectAndMixingOrderAndUnorder() + { + IList second = mocks.StrictMock(typeof (IList)) as IList; + using (mocks.Ordered()) + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); + second.Clear(); + demo.VoidStringArg("Ayende"); + using (mocks.Unordered()) + { + int i = second.Count; + LastCall.On(second).Repeat.Twice().Return(3); + demo.VoidStringArg("Rahien"); + demo.VoidThreeStringArgs("1", "2", "3"); + } + demo.StringArgString("Hello"); + LastCall.On(demo).Return("World"); + second.IndexOf(null); + LastCall.On(second).Return(2); + } + + mocks.Replay(demo); + mocks.Replay(second); + + Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); + Assert.Equal(EnumDemo.Dozen, demo.EnumNoArgs()); + second.Clear(); + demo.VoidStringArg("Ayende"); + Assert.Equal(3, second.Count); + demo.VoidThreeStringArgs("1", "2", "3"); + Assert.Equal(3, second.Count); + demo.VoidStringArg("Rahien"); + Assert.Equal("World", demo.StringArgString("Hello")); + second.IndexOf(null); + mocks.Verify(demo); + } + + [Fact] + public void SeveralMocksUsingOrdered() + { + IList second = mocks.StrictMock(typeof (IList)) as IList; + using (mocks.Ordered()) + { + demo.EnumNoArgs(); + LastCall.On(demo).Return(EnumDemo.Dozen).Repeat.Twice(); + second.Clear(); + demo.VoidStringArg("Ayende"); + using (mocks.Unordered()) + { + int i = second.Count; + LastCall.On(second).Repeat.Twice().Return(3); + demo.VoidStringArg("Rahien"); + demo.VoidThreeStringArgs("1", "2", "3"); + } + demo.StringArgString("Hello"); + LastCall.On(demo).Return("World"); + second.IndexOf(null); + LastCall.On(second).Return(2); + } + + mocks.Replay(demo); + mocks.Replay(second); + + demo.EnumNoArgs(); + Assert.Throws( + "Unordered method call! The expected call is: 'Ordered: { IDemo.EnumNoArgs(); }' but was: 'IList.Clear();'", + () => second.Clear()); + } + + [Fact] + public void RecursiveExpectationsOnUnordered() + { + demo = (IDemo) mocks.StrictMock(typeof (IDemo)); + demo.VoidNoArgs(); + LastCall.On(demo).Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); + demo.VoidStringArg("Ayende"); + mocks.Replay(demo); + demo.VoidNoArgs(); + mocks.Verify(demo); + } + + [Fact] + public void RecursiveExpectationsOnOrdered() + { + demo = (IDemo) mocks.StrictMock(typeof (IDemo)); + using (mocks.Ordered()) + { + demo.VoidNoArgs(); + LastCall.On(demo).Callback(CallMethodOnDemo); + demo.VoidStringArg("Ayende"); + } + mocks.Replay(demo); + Assert.Throws( + "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(callback method: RhinoMockTests.CallMethodOnDemo); }' but was: 'IDemo.VoidStringArg(\"Ayende\");'", + () => demo.VoidNoArgs()); + } + + + [Fact] + public void GetArgsOfEpectedAndActualMethodCallOnException() + { + demo = (IDemo) mocks.StrictMock(typeof (IDemo)); + demo.VoidThreeStringArgs("a","b","c"); + mocks.Replay(demo); + + Assert.Throws( + "IDemo.VoidThreeStringArgs(\"c\", \"b\", \"a\"); Expected #0, Actual #1.\r\nIDemo.VoidThreeStringArgs(\"a\", \"b\", \"c\"); Expected #1, Actual #0.", + () => demo.VoidThreeStringArgs("c", "b", "a")); + } + + + [Fact] + public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() + { + demo = (IDemo) mocks.StrictMock(typeof (IDemo)); + demo.VoidThreeStringArgs("", "", ""); + using (mocks.Ordered()) + { + demo.VoidNoArgs(); + demo.VoidStringArg("Ayende"); + } + mocks.Replay(demo); + demo.VoidNoArgs(); + + Assert.Throws( + "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'", + () => demo.VoidThreeStringArgs("", "", "")); + } + + [Fact] + public void Overrideing_ToString() + { + MockRepository mocks = new MockRepository(); + ObjectThatOverrideToString oid = (ObjectThatOverrideToString) + mocks.StrictMock(typeof (ObjectThatOverrideToString)); + Expect.On(oid).Call(oid.ToString()).Return("bla"); + mocks.ReplayAll(); + Assert.Equal("bla", oid.ToString()); + mocks.VerifyAll(); + } + + [Fact] + public void CallbackThatThrows() + { + demo = (IDemo) mocks.StrictMock(typeof (IDemo)); + demo.VoidNoArgs(); + LastCall.Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); + mocks.ReplayAll(); + Assert.Throws(demo.VoidNoArgs); + } + + #region Private Methods + + private static void RecordOrdered(MockRepository mocks, IDemo demo) + { + using (mocks.Ordered()) + { + demo.ReturnStringNoArgs(); + LastCall.On(demo).Return(null); + demo.VoidNoArgs(); + LastCall.On(demo).Repeat.Twice(); + demo.VoidStringArg("Hello"); + demo.VoidStringArg("World"); + } + } + + #endregion + + private bool CallMethodOnDemo() + { + demo.VoidStringArg("Ayende"); + return true; + } + + private bool ThrowFromCallback() + { + throw new AddressAlreadyInUseException(); + } + + public class ObjectThatOverrideToString + { + public override string ToString() + { + return base.ToString (); + } + } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/SetupResultTests.cs b/Rhino.Mocks.Tests/SetupResultTests.cs index 0019b0e8..ce2b7a32 100644 --- a/Rhino.Mocks.Tests/SetupResultTests.cs +++ b/Rhino.Mocks.Tests/SetupResultTests.cs @@ -1,149 +1,149 @@ -#region license -// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Ayende Rahien nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - - -using System; -using Xunit; -using Rhino.Mocks.Exceptions; - -namespace Rhino.Mocks.Tests -{ - - public class SetupResultTests - { - private MockRepository mocks; - private IDemo demo; - - public SetupResultTests() - { - mocks = new MockRepository(); - demo = mocks.StrictMock(typeof (IDemo)) as IDemo; - } - - [Fact] - public void CanSetupResultForMethodAndIgnoreArgs() - { - SetupResult.For(demo.StringArgString(null)).Return("Ayende").IgnoreArguments(); - mocks.ReplayAll(); - Assert.Equal("Ayende", demo.StringArgString("a")); - Assert.Equal("Ayende", demo.StringArgString("b")); - mocks.VerifyAll(); - - } - - [Fact] - public void CanSetupResult() - { - SetupResult.For(demo.Prop).Return("Ayende"); - mocks.ReplayAll(); - Assert.Equal("Ayende", demo.Prop); - mocks.VerifyAll(); - - } - - [Fact] - public void SetupResultForNoCall() - { - Assert.Throws( - "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", - () => SetupResult.For(null)); - } - - [Fact] - public void SetupResultCanRepeatAsManyTimeAsItWant() - { - SetupResult.For(demo.Prop).Return("Ayende"); - mocks.ReplayAll(); - for (int i = 0; i < 30; i++) - { - Assert.Equal("Ayende", demo.Prop); - } - mocks.VerifyAll(); - - } - - [Fact] - public void SetupResultUsingOn() - { - SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); - mocks.ReplayAll(); - for (int i = 0; i < 30; i++) - { - Assert.Equal("Ayende", demo.Prop); - } - mocks.VerifyAll(); - - } - - [Fact] - public void SetupResultUsingOrdered() - { - SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); - using (mocks.Ordered()) - { - demo.VoidNoArgs(); - LastCall.On(demo).Repeat.Twice(); - } - mocks.ReplayAll(); - demo.VoidNoArgs(); - for (int i = 0; i < 30; i++) - { - Assert.Equal("Ayende", demo.Prop); - } - demo.VoidNoArgs(); - mocks.VerifyAll(); - - } - - [Fact] - public void SetupResultForTheSameMethodTwiceCauseExcetion() - { - SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); - Assert.Throws( "The result for IDemo.get_Prop(); has already been setup.", () => SetupResult.On(demo).Call(demo.Prop).Return("Ayende")); - } - - [Fact] - public void ExpectNever() - { - demo.ReturnStringNoArgs(); - LastCall.Repeat.Never(); - mocks.ReplayAll(); - Assert.Throws("IDemo.ReturnIntNoArgs(); Expected #0, Actual #1.", () => demo.ReturnIntNoArgs()); - } - - [Fact] - public void ExpectNeverSetupTwiceThrows() - { - demo.ReturnStringNoArgs(); - LastCall.Repeat.Never(); - demo.ReturnStringNoArgs(); - Assert.Throws("The result for IDemo.ReturnStringNoArgs(); has already been setup.", () => LastCall.Repeat.Never()); - - } - } +#region license +// Copyright (c) 2005 - 2007 Ayende Rahien (ayende@ayende.com) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Ayende Rahien nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + + +using System; +using Xunit; +using Rhino.Mocks.Exceptions; + +namespace Rhino.Mocks.Tests +{ + + public class SetupResultTests + { + private MockRepository mocks; + private IDemo demo; + + public SetupResultTests() + { + mocks = new MockRepository(); + demo = mocks.StrictMock(typeof (IDemo)) as IDemo; + } + + [Fact] + public void CanSetupResultForMethodAndIgnoreArgs() + { + SetupResult.For(demo.StringArgString(null)).Return("Ayende").IgnoreArguments(); + mocks.ReplayAll(); + Assert.Equal("Ayende", demo.StringArgString("a")); + Assert.Equal("Ayende", demo.StringArgString("b")); + mocks.VerifyAll(); + + } + + [Fact] + public void CanSetupResult() + { + SetupResult.For(demo.Prop).Return("Ayende"); + mocks.ReplayAll(); + Assert.Equal("Ayende", demo.Prop); + mocks.VerifyAll(); + + } + + [Fact] + public void SetupResultForNoCall() + { + Assert.Throws( + "Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).", + () => SetupResult.For(null)); + } + + [Fact] + public void SetupResultCanRepeatAsManyTimeAsItWant() + { + SetupResult.For(demo.Prop).Return("Ayende"); + mocks.ReplayAll(); + for (int i = 0; i < 30; i++) + { + Assert.Equal("Ayende", demo.Prop); + } + mocks.VerifyAll(); + + } + + [Fact] + public void SetupResultUsingOn() + { + SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); + mocks.ReplayAll(); + for (int i = 0; i < 30; i++) + { + Assert.Equal("Ayende", demo.Prop); + } + mocks.VerifyAll(); + + } + + [Fact] + public void SetupResultUsingOrdered() + { + SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); + using (mocks.Ordered()) + { + demo.VoidNoArgs(); + LastCall.On(demo).Repeat.Twice(); + } + mocks.ReplayAll(); + demo.VoidNoArgs(); + for (int i = 0; i < 30; i++) + { + Assert.Equal("Ayende", demo.Prop); + } + demo.VoidNoArgs(); + mocks.VerifyAll(); + + } + + [Fact] + public void SetupResultForTheSameMethodTwiceCauseExcetion() + { + SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); + Assert.Throws( "The result for IDemo.get_Prop(); has already been setup.", () => SetupResult.On(demo).Call(demo.Prop).Return("Ayende")); + } + + [Fact] + public void ExpectNever() + { + demo.ReturnStringNoArgs(); + LastCall.Repeat.Never(); + mocks.ReplayAll(); + Assert.Throws("IDemo.ReturnIntNoArgs(); Expected #0, Actual #1.", () => demo.ReturnIntNoArgs()); + } + + [Fact] + public void ExpectNeverSetupTwiceThrows() + { + demo.ReturnStringNoArgs(); + LastCall.Repeat.Never(); + demo.ReturnStringNoArgs(); + Assert.Throws("The result for IDemo.ReturnStringNoArgs(); has already been setup.", () => LastCall.Repeat.Never()); + + } + } } \ No newline at end of file diff --git a/Rhino.Mocks.Tests/TraceWriterWithStackTraceExpectationWriterFixture.cs b/Rhino.Mocks.Tests/TraceWriterWithStackTraceExpectationWriterFixture.cs index a0909b8c..9616bc86 100644 --- a/Rhino.Mocks.Tests/TraceWriterWithStackTraceExpectationWriterFixture.cs +++ b/Rhino.Mocks.Tests/TraceWriterWithStackTraceExpectationWriterFixture.cs @@ -23,7 +23,7 @@ public void WillPrintLogInfoWithStackTrace() mock.VoidNoArgs(); mocks.VerifyAll(); - Assert.Contains("WillPrintLogInfoWithStackTrace", + Assert.Contains("WillPrintLogInfoWithStackTrace", writer.GetStringBuilder().ToString()); } } diff --git a/Rhino.Mocks.Tests/VerifyTests.cs b/Rhino.Mocks.Tests/VerifyTests.cs index 6e182214..3bb001ce 100644 --- a/Rhino.Mocks.Tests/VerifyTests.cs +++ b/Rhino.Mocks.Tests/VerifyTests.cs @@ -57,7 +57,7 @@ public void MockParameterToStringShouldBeIgnoredIfItIsInVerifyState() { demo.VoidConcreteDemo(demoParam); mocks.ReplayAll(); - mocks.Verify(demoParam); + mocks.Verify(demoParam); Assert.Throws(() => mocks.Verify(demo)); } } diff --git a/Rhino.Mocks.Tests/WithTestFixture.cs b/Rhino.Mocks.Tests/WithTestFixture.cs index 8ff8f602..51350a8f 100644 --- a/Rhino.Mocks.Tests/WithTestFixture.cs +++ b/Rhino.Mocks.Tests/WithTestFixture.cs @@ -71,30 +71,30 @@ public void CannotUseMockerOutsideOfWithMocks() [Fact] public void UsingTheWithMocksConstruct_ThrowsIfExpectationIsMissed() - { - Assert.Throws("IDemo.ReturnIntNoArgs(); Expected #1, Actual #0.", - () => - - With.Mocks(delegate - { - IDemo demo = Mocker.Current.StrictMock(); - Expect.Call(demo.ReturnIntNoArgs()).Return(5); - Mocker.Current.ReplayAll(); + { + Assert.Throws("IDemo.ReturnIntNoArgs(); Expected #1, Actual #0.", + () => + + With.Mocks(delegate + { + IDemo demo = Mocker.Current.StrictMock(); + Expect.Call(demo.ReturnIntNoArgs()).Return(5); + Mocker.Current.ReplayAll(); })); } [Fact] public void UsingTheWithMocksConstruct_ThrowsIfReplayAllNotCalled() { - Assert.Throws( + Assert.Throws( "This action is invalid when the mock object {Rhino.Mocks.Tests.IDemo} is in record state.", - () => - { - With.Mocks(delegate - { - IDemo demo = Mocker.Current.StrictMock(); - Expect.Call(demo.ReturnIntNoArgs()).Return(5); - }); + () => + { + With.Mocks(delegate + { + IDemo demo = Mocker.Current.StrictMock(); + Expect.Call(demo.ReturnIntNoArgs()).Return(5); + }); }); } @@ -102,15 +102,15 @@ public void UsingTheWithMocksConstruct_ThrowsIfReplayAllNotCalled() [Fact] public void UsingTheWithMocksConstruct_GiveCorrectExceptionWhenMocking() { - Assert.Throws("foo", () => - { - With.Mocks(delegate - { - IDemo demo = Mocker.Current.StrictMock(); - Expect.Call(demo.ReturnIntNoArgs()).Return(5); - Mocker.Current.ReplayAll(); - throw new IndexOutOfRangeException("foo"); - }); + Assert.Throws("foo", () => + { + With.Mocks(delegate + { + IDemo demo = Mocker.Current.StrictMock(); + Expect.Call(demo.ReturnIntNoArgs()).Return(5); + Mocker.Current.ReplayAll(); + throw new IndexOutOfRangeException("foo"); + }); }); } diff --git a/Rhino.Mocks.sln b/Rhino.Mocks.sln index 45a53a79..f59b9696 100644 --- a/Rhino.Mocks.sln +++ b/Rhino.Mocks.sln @@ -1,68 +1,68 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.Tests", "Rhino.Mocks.Tests\Rhino.Mocks.Tests.csproj", "{C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks", "Rhino.Mocks\Rhino.Mocks.csproj", "{1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.Tests.Model", "Rhino.Mocks.Tests.Model\Rhino.Mocks.Tests.Model.csproj", "{3078B943-10A5-41FA-A68A-7C4FC98506A0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.GettingStarted", "Rhino.Mocks.GettingStarted\Rhino.Mocks.GettingStarted.csproj", "{59F8A3E2-80C5-4250-909A-16741DF81B23}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|Win32 = Debug|Win32 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Any CPU.Build.0 = Release|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Win32.ActiveCfg = Release|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Win32.ActiveCfg = Debug|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Any CPU.Build.0 = Release|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Win32.ActiveCfg = Release|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Win32.ActiveCfg = Debug|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Any CPU.Build.0 = Release|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Win32.ActiveCfg = Release|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Win32.ActiveCfg = Debug|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Any CPU.Build.0 = Release|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Win32.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(TextTemplating) = postSolution - TextTemplating = 1 - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.Tests", "Rhino.Mocks.Tests\Rhino.Mocks.Tests.csproj", "{C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks", "Rhino.Mocks\Rhino.Mocks.csproj", "{1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.Tests.Model", "Rhino.Mocks.Tests.Model\Rhino.Mocks.Tests.Model.csproj", "{3078B943-10A5-41FA-A68A-7C4FC98506A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.Mocks.GettingStarted", "Rhino.Mocks.GettingStarted\Rhino.Mocks.GettingStarted.csproj", "{59F8A3E2-80C5-4250-909A-16741DF81B23}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Debug|Win32.ActiveCfg = Debug|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Any CPU.Build.0 = Release|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {C63839EC-BEF3-4DCD-BE23-B6DA21E8BE20}.Release|Win32.ActiveCfg = Release|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Debug|Win32.ActiveCfg = Debug|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Any CPU.Build.0 = Release|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {1E8FECC7-9E9B-4275-A938-D956F5E5D4F8}.Release|Win32.ActiveCfg = Release|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Debug|Win32.ActiveCfg = Debug|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Any CPU.Build.0 = Release|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {3078B943-10A5-41FA-A68A-7C4FC98506A0}.Release|Win32.ActiveCfg = Release|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Debug|Win32.ActiveCfg = Debug|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Any CPU.Build.0 = Release|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {59F8A3E2-80C5-4250-909A-16741DF81B23}.Release|Win32.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(TextTemplating) = postSolution + TextTemplating = 1 + EndGlobalSection +EndGlobal diff --git a/Rhino.Mocks/Rhino.Mocks.csproj.user b/Rhino.Mocks/Rhino.Mocks.csproj.user index e1e6e1c0..5a2e8d60 100644 --- a/Rhino.Mocks/Rhino.Mocks.csproj.user +++ b/Rhino.Mocks/Rhino.Mocks.csproj.user @@ -1,57 +1,57 @@ - - - 7.10.3077 - Debug - AnyCPU - D:\Code\rhino-mocks\vendor\;D:\Code\rhino-mocks\vendor\net-1.1\;C:\Code\rhino-mocks\vendor\net-1.1\ - - - - - 0 - ProjectFiles - 0 - - - false - false - false - false - false - - - Project - - - - - - - - - - - false - - - false - false - false - false - false - - - Project - - - - - - - - - - - false - + + + 7.10.3077 + Debug + AnyCPU + D:\Code\rhino-mocks\vendor\;D:\Code\rhino-mocks\vendor\net-1.1\;C:\Code\rhino-mocks\vendor\net-1.1\ + + + + + 0 + ProjectFiles + 0 + + + false + false + false + false + false + + + Project + + + + + + + + + + + false + + + false + false + false + false + false + + + Project + + + + + + + + + + + false + \ No newline at end of file diff --git a/SharedLibs/xunit.xml b/SharedLibs/xunit.xml index 0aada6c7..f7668194 100644 --- a/SharedLibs/xunit.xml +++ b/SharedLibs/xunit.xml @@ -1,2132 +1,2132 @@ - - - - xunit - - - - - Contains various static methods that are used to verify that conditions are met during the - process of running tests. - - - - - Initializes a new instance of the class. - - - - - Verifies that a collection contains a given object. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - Thrown when the object is not present in the collection - - - - Verifies that a collection contains a given object, using a comparer. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is not present in the collection - - - - Verifies that a string contains a given sub-string, using the current culture. - - The sub-string expected to be in the string - The string to be inspected - Thrown when the sub-string is not present inside the string - - - - Verifies that a string contains a given sub-string, using the given comparison type. - - The sub-string expected to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is not present inside the string - - - - Verifies that a collection does not contain a given object. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - Thrown when the object is present inside the container - - - - Verifies that a collection does not contain a given object, using a comparer. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is present inside the container - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - Thrown when the sub-string is present inside the string - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is present inside the given string - - - - Verifies that a block of code does not throw any exceptions. - - A delegate to the code to be tested - - - - Verifies that a collection is empty. - - The collection to be inspected - Thrown when the collection is null - Thrown when the collection is not empty - - - - Verifies that two objects are equal, using a default comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - Thrown when the objects are not equal - - - - Verifies that two objects are equal, using a custom comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - The comparer used to compare the two objects - Thrown when the objects are not equal - - - Do not call this method. - - - - Verifies that the condition is false. - - The condition to be tested - Thrown if the condition is not false - - - - Verifies that the condition is false. - - The condition to be tested - The message to show when the condition is not false - Thrown if the condition is not false - - - - Verifies that a value is within a given range. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is not in the given range - - - - Verifies that a value is within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is not in the given range - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that a collection is not empty. - - The collection to be inspected - Thrown when a null collection is passed - Thrown when the collection is empty - - - - Verifies that two objects are not equal, using a default comparer. - - The type of the objects to be compared - The expected object - The actual object - Thrown when the objects are equal - - - - Verifies that two objects are not equal, using a custom comparer. - - The type of the objects to be compared - The expected object - The actual object - The comparer used to examine the objects - Thrown when the objects are equal - - - - Verifies that a value is not within a given range, using the default comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is in the given range - - - - Verifies that a value is not within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is in the given range - - - - Verifies that an object reference is not null. - - The object to be validated - Thrown when the object is not null - - - - Verifies that two objects are not the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are the same instance - - - - Verifies that an object reference is null. - - The object to be inspected - Thrown when the object reference is not null - - - - Verifies that two objects are the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are not the same instance - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that an expression is true. - - The condition to be inspected - Thrown when the condition is false - - - - Verifies that an expression is true. - - The condition to be inspected - The message to be shown when the condition is false - Thrown when the condition is false - - - - Used by the Throws and DoesNotThrow methods. - - - - - Captures standard output and standard error, and inserts the values into the - as it traverses the chain. - - - - - Base class used by commands which delegate to inner commands. - - - - - Interface which represents the ability to invoke of a test method. - - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Creates the start XML to be sent to the callback when the test is about to start - running. - - Return the of the start node, or null if the test - is known that it will not be running. - - - - Gets the display name of the test method. - - - - - Determines if the test runner infrastructure should create a new instance of the - test class before running the test. - - - - - Creates a new instance of the class. - - The inner command to delegate to. - - - - - - - - - - - - - - - - - - - Initializes a new instance of the class. - - The inner command - - - - - - - Base class for exceptions that have actual and expected values - - - - - The base assert exception class - - - - - Initializes a new instance of the class. - - - - - Initializes a new instance of the class. - - The user message to be displayed - - - - Initializes a new instance of the class. - - The user message to be displayed - The inner exception - - - - Initializes a new instance of the class. - - The user message to be displayed - The stack trace to be displayed - - - - Filters the stack trace to remove all lines that occur within the testing framework. - - The original stack trace - The filtered stack trace - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Gets the user message - - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - Set to true to skip the check for difference position - - - - Gets the actual value. - - - - - Gets the expected value. - - - - - Gets a message that describes the current exception. Includes the expected and actual values. - - The error message that explains the reason for the exception, or an empty string(""). - 1 - - - - Exception thrown when a collection unexpectedly does not contain the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. - Version-resilient runners should link against xunit.runner.utility.dll and use - ExecutorWrapper instead. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Exception thrown when the value is unexpectedly not of the given type or a derived type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Allows the user to record actions for a test. - - - - - Records any exception which is thrown by the given code. - - The code which may thrown an exception. - Returns the exception that was thrown by the code; null, otherwise. - - - - Exception that is thrown when one or more exceptions are thrown from - the After method of a . - - - - - Initializes a new instance of the class. - - The exceptions. - - - - Initializes a new instance of the class. - - The exceptions. - - - - Gets the list of exceptions thrown in the After method. - - - - - Gets a message that describes the current exception. - - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - - - - Implementation of which executes the - instances attached to a test method. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Wraps any exceptions thrown by the command execution. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Guard class, used for guard clauses and argument validation - - - - - - - - - - - - - - Base class which contains XML manipulation helper methods - - - - - Interface that represents a single test result. - - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - The amount of time spent in execution - - - - - Adds the test execution time to the XML node. - - The XML node. - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - The amount of time spent in execution - - - - - Utility methods for dealing with exceptions. - - - - - Gets the message for the exception, including any inner exception messages. - - The exception - The formatted message - - - - Gets the stack trace for the exception, including any inner exceptions. - - The exception - The formatted stack trace - - - - Rethrows an exception object without losing the existing stack trace information - - The exception to re-throw. - - For more information on this technique, see - http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx - - - - - XML utility methods - - - - - Adds an attribute to an XML node. - - The XML node. - The attribute name. - The attribute value. - - - - Adds a CDATA section to an XML node. - - The XML node. - The text for the CDATA section. - - - - Adds a child element to an XML node. - - The parent XML node. - The child element name. - The new child XML element. - - - - Exception that is thrown when a call to Debug.Assert() fails. - - - - - Creates a new instance of the class. - - The original assert message - - - - Creates a new instance of the class. - - The original assert message - The original assert detailed message - - - - Gets the original assert detailed message. - - - - - Gets the original assert message. - - - - - Gets a message that describes the current exception. - - - - - Exception thrown when a collection unexpectedly contains the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Exception thrown when code unexpectedly throws an exception. - - - - - Creates a new instance of the class. - - Actual exception - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a collection is unexpectedly not empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly not equal. - - - - - Creates a new instance of the class. - - The expected object value - The actual object value - - - - Exception thrown when a value is unexpectedly true. - - - - - Creates a new instance of the class. - - The user message to be display, or null for the default message - - - - Exception thrown when a value is unexpectedly not in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Exception thrown when the value is unexpectedly of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Exception thrown when the value is unexpectedly not of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Used to decorate xUnit.net test classes that utilize fixture classes. - An instance of the fixture data is initialized just before the first - test in the class is run, and if it implements IDisposable, is disposed - after the last test in the class is run. - - The type of the fixture - - - - Called on the test class just before each test method is run, - passing the fixture data so that it can be used for the test. - All test runs share the same instance of fixture data. - - The fixture data - - - - Exception thrown when a value is unexpectedly in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Base attribute which indicates a test method interception (allows code to be run before and - after the test is run). - - - - - This method is called after the test method is executed. - - The method under test - - - - This method is called before the test method is executed. - - The method under test - - - - Exception thrown when a collection is unexpectedly empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly equal. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object is unexpectedly null. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpected the same instance. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object reference is unexpectedly not null. - - - - - Creates a new instance of the class. - - - - - - Command that automatically creates the instance of the test class - and disposes it (if it implements ). - - - - - Creates a new instance of the object. - - The command that is bring wrapped - The method under test - - - - Executes the test method. Creates a new instance of the class - under tests and passes it to the inner command. Also catches - any exceptions and converts them into s. - - The instance of the test class - Returns information about the test run - - - - A command wrapper which catches Trace.Assert and Debug.Assert failures and turns - them into assertion exceptions. - - - - - Creates a new instance of the class. - - The command that will be wrapped. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Command used to wrap a which has associated - fixture data. - - - - - Creates a new instance of the class. - - The inner command - The fixtures to be set on the test class - - - - Sets the fixtures on the test class by calling SetFixture, then - calls the inner command. - - The instance of the test class - Returns information about the test run - - - - A timer class used to figure out how long tests take to run. On most .NET implementations - this will use the class because it's a high - resolution timer; however, on Silverlight/CoreCLR, it will use - (which will provide lower resolution results). - - - - - Creates a new instance of the class. - - - - - Starts timing. - - - - - Stops timing. - - - - - Gets how long the timer ran, in milliseconds. In order for this to be valid, - both and must have been called. - - - - - Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). - - - - - Creates a new instance of the class. - - The trait name - The trait value - - - - Gets the trait name. - - - - - Gets the trait value. - - - - - Runner that executes an synchronously. - - - - - Execute the . - - The test class command to execute - The methods to execute; if null or empty, all methods will be executed - The start run callback - The end run result callback - A with the results of the test run - - - - Factory for objects, based on the type under test. - - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Represents an xUnit.net test class - - - - - Interface which describes the ability to executes all the tests in a test class. - - - - - Allows the test class command to choose the next test to be run from the list of - tests that have not yet been run, thereby allowing it to choose the run order. - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the type that is being tested - - - - - Creates a new instance of the class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The type under test - - - - Chooses the next test to run, randomly, using the . - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the randomizer used to determine the order in which tests are run. - - - - - Sets the type that is being tested - - - - - Implementation of that represents a skipped test. - - - - - Represents an xUnit.net test command. - - - - - The method under test. - - - - - Initializes a new instance of the class. - - The method under test. - - - - Initializes a new instance of the class. - - The method under test. - The display name of the test. - - - - - - - - - - - - - Gets the name of the method under test. - - - - - Gets the name of the type under test. - - - - - - - - Creates a new instance of the class. - - The method that is being skipped - The display name for the test. If null, the fully qualified - type name is used. - - - - - - - - - - - - - Factory for creating objects. - - - - - Make instances of objects for the given class and method. - - The class command - The method under test - The set of objects - - - - A command wrapper which times the running of a command. - - - - - Creates a new instance of the class. - - The command that will be timed. - - - - Executes the inner test method, gathering the amount of time it takes to run. - - Returns information about the test run - - - - Wraps a command which should fail if it runs longer than the given timeout value. - - - - - Creates a new instance of the class. - - The command to be run - The timout, in milliseconds - The method under test - - - - Executes the test method, failing if it takes too long. - - Returns information about the test run - - - - Gets the timeout value, in milliseconds. - - - - - Attributes used to decorate a test fixture that is run with an alternate test runner. - The test runner must implement the interface. - - - - - Creates a new instance of the class. - - The class which implements ITestClassCommand and acts as the runner - for the test fixture. - - - - Gets the test class command. - - - - - Exception thrown when two object references are unexpectedly not the same instance. - - - - - Creates a new instance of the class. - - The expected object reference - The actual object reference - - - - Contains the test results from an assembly. - - - - - Contains multiple test results, representing them as a composite test result. - - - - - Adds a test result to the composite test result list. - - - - - - Gets the test results. - - - - - Creates a new instance of the class. - - The filename of the assembly - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the directory where the assembly resides. - - - - - Gets the number of failed results. - - - - - Gets the fully qualified filename of the assembly. - - - - - Gets the number of passed results. - - - - - Gets the number of skipped results. - - - - - Contains the test results from a test class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The simple name of the type under test - The fully qualified name of the type under test - The namespace of the type under test - - - - Sets the exception thrown by the test fixture. - - The thrown exception - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the fully qualified test fixture exception type, when an exception has occurred. - - - - - Gets the number of tests which failed. - - - - - Gets the fully qualified name of the type under test. - - - - - Gets the test fixture exception message, when an exception has occurred. - - - - - Gets the simple name of the type under test. - - - - - Gets the namespace of the type under test. - - - - - Gets the number of tests which passed. - - - - - Gets the number of tests which were skipped. - - - - - Gets the test fixture exception stack trace, when an exception has occurred. - - - - - Represents a failed test result. - - - - - Represents the results from running a test method - - - - - Initializes a new instance of the class. The traits for - the test method are discovered using reflection. - - The method under test. - The display name for the test. If null, the fully qualified - type name is used. - - - - Initializes a new instance of the class. - - The name of the method under test. - The type of the method under test. - The display name for the test. If null, the fully qualified - type name is used. - The traits. - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets or sets the display name of the method under test. This is the value that's shown - during failures and in the resulting output XML. - - - - - Gets the name of the method under test. - - - - - Gets or sets the standard output/standard error from the test that was captured - while the test was running. - - - - - Gets the traits attached to the test method. - - - - - Gets the name of the type under test. - - - - - Creates a new instance of the class. - - The method under test - The exception throw by the test - The display name for the test. If null, the fully qualified - type name is used. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name of the test - The custom properties attached to the test method - The full type name of the exception throw - The exception message - The exception stack trace - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the exception type thrown by the test method. - - - - - Gets the exception message thrown by the test method. - - - - - Gets the stack trace of the exception thrown by the test method. - - - - - Represents a passing test result. - - - - - Create a new instance of the class. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - - - - Create a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The custom properties attached to the test method - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Represents a skipped test result. - - - - - Creates a new instance of the class. Uses reflection to discover - the skip reason. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The traits attached to the method under test - The skip reason - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the skip reason. - - - - - Represents information about an attribute. - - - - - Gets the instance of the attribute, if available. - - The type of the attribute - The instance of the attribute, if available. - - - - Gets an initialized property value of the attribute. - - The type of the property - The name of the property - The property value - - - - Represents information about a method. - - - - - Gets all the custom attributes for the method that are of the given type. - - The type of the attribute - The matching attributes that decorate the method - - - - Determines if the method has at least one instance of the given attribute type. - - The type of the attribute - True if the method has at least one instance of the given attribute type; false, otherwise - - - - Gets the fully qualified type name of the type that this method belongs to. - - - - - Gets a value indicating whether the method is abstract. - - - - - Gets a value indicating whether the method is static. - - - - - Gets the underlying for the method, if available. - - - - - Gets the name of the method. - - - - - Gets the fully qualified type name of the return type. - - - - - Represents information about a type. - - - - - Gets all the custom attributes for the type that are of the given attribute type. - - The type of the attribute - The matching attributes that decorate the type - - - - Gets all the methods - - - - - - Determines if the type has at least one instance of the given attribute type. - - The type of the attribute - True if the type has at least one instance of the given attribute type; false, otherwise - - - - Determines if the type implements the given interface. - - The type of the interface - True if the type implements the given interface; false, otherwise - - - - Gets a value indicating whether the type is abstract. - - - - - Gets a value indicating whether the type is sealed. - - - - - Gets the underlying object, if available. - - - - - Utility class which inspects methods for test information - - - - - Gets the skip reason from a test method. - - The method to be inspected - The skip reason - - - - Gets the test commands for a test method. - - The method to be inspected - The objects for the test method - - - - Gets the timeout value for a test method. - - The method to be inspected - The timeout, in milliseconds - - - - Gets the traits on a test method. - - The method to be inspected - A dictionary of the traits - - - - Determines whether a test method has a timeout. - - The method to be inspected - True if the method has a timeout; false, otherwise - - - - Determines whether a test method has traits. - - The method to be inspected - True if the method has traits; false, otherwise - - - - Determines whether a test method should be skipped. - - The method to be inspected - True if the method should be skipped; false, otherwise - - - - Determines whether a method is a test method. A test method must be decorated - with the (or derived class) and must not be abstract. - - The method to be inspected - True if the method is a test method; false, otherwise - - - - Wrapper to implement and using reflection. - - - - - Converts an into an using reflection. - - - - - - - Converts a into an using reflection. - - The method to wrap - The wrapper - - - - Converts a into an using reflection. - - The type to wrap - The wrapper - - - - Utility class which inspects types for test information - - - - - Determines if a type contains any test methods - - The type to be inspected - True if the class contains any test methods; false, otherwise - - - - Retrieves the type to run the test class with from the , if present. - - The type to be inspected - The type of the test class runner, if present; null, otherwise - - - - Retrieves a list of the test methods from the test class. - - The type to be inspected - The test methods - - - - Determines if the test class has a applied to it. - - The type to be inspected - True if the test class has a run with attribute; false, otherwise - - - - Determines if the type implements . - - The type to be inspected - True if the type implements ; false, otherwise - - - - Determines whether the specified type is abstract. - - The type. - - true if the specified type is abstract; otherwise, false. - - - - - Determines whether the specified type is static. - - The type. - - true if the specified type is static; otherwise, false. - - - - - Determines if a class is a test class. - - The type to be inspected - True if the type is a test class; false, otherwise - - - - Attribute that is applied to a method to indicate that it is a fact that should be run - by the test runner. It can also be extended to support a customized definition of a - test method. - - - - - Creates instances of which represent individual intended - invocations of the test method. - - The method under test - An enumerator through the desired test method invocations - - - - Enumerates the test commands represented by this test method. Derived classes should - override this method to return instances of , one per execution - of a test method. - - The test method - The test commands which will execute the test runs for the given method - - - - Gets the name of the test to be used when the test is skipped. Defaults to - null, which will cause the fully qualified test name to be used. - - - - - Marks the test so that it will not be run, and gets or sets the skip reason - - - - - Marks the test as failing if it does not finish running within the given time - period, in milliseconds; set to 0 or less to indicate the method has no timeout - - - - - Exception thrown when code unexpectedly fails to throw an exception. - - - - - Creates a new instance of the class. Call this constructor - when no exception was thrown. - - The type of the exception that was expected - - - - Creates a new instance of the class. Call this constructor - when an exception of the wrong type was thrown. - - The type of the exception that was expected - The actual exception that was thrown - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a test method exceeds the given timeout value - - - - - Creates a new instance of the class. - - The timeout value, in milliseconds - - - - Exception thrown when a value is unexpectedly false. - - - - - Creates a new instance of the class. - - The user message to be displayed, or null for the default message - - - + + + + xunit + + + + + Contains various static methods that are used to verify that conditions are met during the + process of running tests. + + + + + Initializes a new instance of the class. + + + + + Verifies that a collection contains a given object. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + Thrown when the object is not present in the collection + + + + Verifies that a collection contains a given object, using a comparer. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is not present in the collection + + + + Verifies that a string contains a given sub-string, using the current culture. + + The sub-string expected to be in the string + The string to be inspected + Thrown when the sub-string is not present inside the string + + + + Verifies that a string contains a given sub-string, using the given comparison type. + + The sub-string expected to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is not present inside the string + + + + Verifies that a collection does not contain a given object. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + Thrown when the object is present inside the container + + + + Verifies that a collection does not contain a given object, using a comparer. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is present inside the container + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + Thrown when the sub-string is present inside the string + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is present inside the given string + + + + Verifies that a block of code does not throw any exceptions. + + A delegate to the code to be tested + + + + Verifies that a collection is empty. + + The collection to be inspected + Thrown when the collection is null + Thrown when the collection is not empty + + + + Verifies that two objects are equal, using a default comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + Thrown when the objects are not equal + + + + Verifies that two objects are equal, using a custom comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + The comparer used to compare the two objects + Thrown when the objects are not equal + + + Do not call this method. + + + + Verifies that the condition is false. + + The condition to be tested + Thrown if the condition is not false + + + + Verifies that the condition is false. + + The condition to be tested + The message to show when the condition is not false + Thrown if the condition is not false + + + + Verifies that a value is within a given range. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is not in the given range + + + + Verifies that a value is within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is not in the given range + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that a collection is not empty. + + The collection to be inspected + Thrown when a null collection is passed + Thrown when the collection is empty + + + + Verifies that two objects are not equal, using a default comparer. + + The type of the objects to be compared + The expected object + The actual object + Thrown when the objects are equal + + + + Verifies that two objects are not equal, using a custom comparer. + + The type of the objects to be compared + The expected object + The actual object + The comparer used to examine the objects + Thrown when the objects are equal + + + + Verifies that a value is not within a given range, using the default comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is in the given range + + + + Verifies that a value is not within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is in the given range + + + + Verifies that an object reference is not null. + + The object to be validated + Thrown when the object is not null + + + + Verifies that two objects are not the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are the same instance + + + + Verifies that an object reference is null. + + The object to be inspected + Thrown when the object reference is not null + + + + Verifies that two objects are the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are not the same instance + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that an expression is true. + + The condition to be inspected + Thrown when the condition is false + + + + Verifies that an expression is true. + + The condition to be inspected + The message to be shown when the condition is false + Thrown when the condition is false + + + + Used by the Throws and DoesNotThrow methods. + + + + + Captures standard output and standard error, and inserts the values into the + as it traverses the chain. + + + + + Base class used by commands which delegate to inner commands. + + + + + Interface which represents the ability to invoke of a test method. + + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Creates the start XML to be sent to the callback when the test is about to start + running. + + Return the of the start node, or null if the test + is known that it will not be running. + + + + Gets the display name of the test method. + + + + + Determines if the test runner infrastructure should create a new instance of the + test class before running the test. + + + + + Creates a new instance of the class. + + The inner command to delegate to. + + + + + + + + + + + + + + + + + + + Initializes a new instance of the class. + + The inner command + + + + + + + Base class for exceptions that have actual and expected values + + + + + The base assert exception class + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class. + + The user message to be displayed + + + + Initializes a new instance of the class. + + The user message to be displayed + The inner exception + + + + Initializes a new instance of the class. + + The user message to be displayed + The stack trace to be displayed + + + + Filters the stack trace to remove all lines that occur within the testing framework. + + The original stack trace + The filtered stack trace + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Gets the user message + + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + Set to true to skip the check for difference position + + + + Gets the actual value. + + + + + Gets the expected value. + + + + + Gets a message that describes the current exception. Includes the expected and actual values. + + The error message that explains the reason for the exception, or an empty string(""). + 1 + + + + Exception thrown when a collection unexpectedly does not contain the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. + Version-resilient runners should link against xunit.runner.utility.dll and use + ExecutorWrapper instead. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Exception thrown when the value is unexpectedly not of the given type or a derived type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Allows the user to record actions for a test. + + + + + Records any exception which is thrown by the given code. + + The code which may thrown an exception. + Returns the exception that was thrown by the code; null, otherwise. + + + + Exception that is thrown when one or more exceptions are thrown from + the After method of a . + + + + + Initializes a new instance of the class. + + The exceptions. + + + + Initializes a new instance of the class. + + The exceptions. + + + + Gets the list of exceptions thrown in the After method. + + + + + Gets a message that describes the current exception. + + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + + + + Implementation of which executes the + instances attached to a test method. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Wraps any exceptions thrown by the command execution. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Guard class, used for guard clauses and argument validation + + + + + + + + + + + + + + Base class which contains XML manipulation helper methods + + + + + Interface that represents a single test result. + + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + The amount of time spent in execution + + + + + Adds the test execution time to the XML node. + + The XML node. + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + The amount of time spent in execution + + + + + Utility methods for dealing with exceptions. + + + + + Gets the message for the exception, including any inner exception messages. + + The exception + The formatted message + + + + Gets the stack trace for the exception, including any inner exceptions. + + The exception + The formatted stack trace + + + + Rethrows an exception object without losing the existing stack trace information + + The exception to re-throw. + + For more information on this technique, see + http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx + + + + + XML utility methods + + + + + Adds an attribute to an XML node. + + The XML node. + The attribute name. + The attribute value. + + + + Adds a CDATA section to an XML node. + + The XML node. + The text for the CDATA section. + + + + Adds a child element to an XML node. + + The parent XML node. + The child element name. + The new child XML element. + + + + Exception that is thrown when a call to Debug.Assert() fails. + + + + + Creates a new instance of the class. + + The original assert message + + + + Creates a new instance of the class. + + The original assert message + The original assert detailed message + + + + Gets the original assert detailed message. + + + + + Gets the original assert message. + + + + + Gets a message that describes the current exception. + + + + + Exception thrown when a collection unexpectedly contains the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Exception thrown when code unexpectedly throws an exception. + + + + + Creates a new instance of the class. + + Actual exception + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a collection is unexpectedly not empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly not equal. + + + + + Creates a new instance of the class. + + The expected object value + The actual object value + + + + Exception thrown when a value is unexpectedly true. + + + + + Creates a new instance of the class. + + The user message to be display, or null for the default message + + + + Exception thrown when a value is unexpectedly not in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Exception thrown when the value is unexpectedly of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Exception thrown when the value is unexpectedly not of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Used to decorate xUnit.net test classes that utilize fixture classes. + An instance of the fixture data is initialized just before the first + test in the class is run, and if it implements IDisposable, is disposed + after the last test in the class is run. + + The type of the fixture + + + + Called on the test class just before each test method is run, + passing the fixture data so that it can be used for the test. + All test runs share the same instance of fixture data. + + The fixture data + + + + Exception thrown when a value is unexpectedly in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Base attribute which indicates a test method interception (allows code to be run before and + after the test is run). + + + + + This method is called after the test method is executed. + + The method under test + + + + This method is called before the test method is executed. + + The method under test + + + + Exception thrown when a collection is unexpectedly empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly equal. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object is unexpectedly null. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpected the same instance. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object reference is unexpectedly not null. + + + + + Creates a new instance of the class. + + + + + + Command that automatically creates the instance of the test class + and disposes it (if it implements ). + + + + + Creates a new instance of the object. + + The command that is bring wrapped + The method under test + + + + Executes the test method. Creates a new instance of the class + under tests and passes it to the inner command. Also catches + any exceptions and converts them into s. + + The instance of the test class + Returns information about the test run + + + + A command wrapper which catches Trace.Assert and Debug.Assert failures and turns + them into assertion exceptions. + + + + + Creates a new instance of the class. + + The command that will be wrapped. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Command used to wrap a which has associated + fixture data. + + + + + Creates a new instance of the class. + + The inner command + The fixtures to be set on the test class + + + + Sets the fixtures on the test class by calling SetFixture, then + calls the inner command. + + The instance of the test class + Returns information about the test run + + + + A timer class used to figure out how long tests take to run. On most .NET implementations + this will use the class because it's a high + resolution timer; however, on Silverlight/CoreCLR, it will use + (which will provide lower resolution results). + + + + + Creates a new instance of the class. + + + + + Starts timing. + + + + + Stops timing. + + + + + Gets how long the timer ran, in milliseconds. In order for this to be valid, + both and must have been called. + + + + + Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). + + + + + Creates a new instance of the class. + + The trait name + The trait value + + + + Gets the trait name. + + + + + Gets the trait value. + + + + + Runner that executes an synchronously. + + + + + Execute the . + + The test class command to execute + The methods to execute; if null or empty, all methods will be executed + The start run callback + The end run result callback + A with the results of the test run + + + + Factory for objects, based on the type under test. + + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Represents an xUnit.net test class + + + + + Interface which describes the ability to executes all the tests in a test class. + + + + + Allows the test class command to choose the next test to be run from the list of + tests that have not yet been run, thereby allowing it to choose the run order. + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the type that is being tested + + + + + Creates a new instance of the class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The type under test + + + + Chooses the next test to run, randomly, using the . + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the randomizer used to determine the order in which tests are run. + + + + + Sets the type that is being tested + + + + + Implementation of that represents a skipped test. + + + + + Represents an xUnit.net test command. + + + + + The method under test. + + + + + Initializes a new instance of the class. + + The method under test. + + + + Initializes a new instance of the class. + + The method under test. + The display name of the test. + + + + + + + + + + + + + Gets the name of the method under test. + + + + + Gets the name of the type under test. + + + + + + + + Creates a new instance of the class. + + The method that is being skipped + The display name for the test. If null, the fully qualified + type name is used. + + + + + + + + + + + + + Factory for creating objects. + + + + + Make instances of objects for the given class and method. + + The class command + The method under test + The set of objects + + + + A command wrapper which times the running of a command. + + + + + Creates a new instance of the class. + + The command that will be timed. + + + + Executes the inner test method, gathering the amount of time it takes to run. + + Returns information about the test run + + + + Wraps a command which should fail if it runs longer than the given timeout value. + + + + + Creates a new instance of the class. + + The command to be run + The timout, in milliseconds + The method under test + + + + Executes the test method, failing if it takes too long. + + Returns information about the test run + + + + Gets the timeout value, in milliseconds. + + + + + Attributes used to decorate a test fixture that is run with an alternate test runner. + The test runner must implement the interface. + + + + + Creates a new instance of the class. + + The class which implements ITestClassCommand and acts as the runner + for the test fixture. + + + + Gets the test class command. + + + + + Exception thrown when two object references are unexpectedly not the same instance. + + + + + Creates a new instance of the class. + + The expected object reference + The actual object reference + + + + Contains the test results from an assembly. + + + + + Contains multiple test results, representing them as a composite test result. + + + + + Adds a test result to the composite test result list. + + + + + + Gets the test results. + + + + + Creates a new instance of the class. + + The filename of the assembly + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the directory where the assembly resides. + + + + + Gets the number of failed results. + + + + + Gets the fully qualified filename of the assembly. + + + + + Gets the number of passed results. + + + + + Gets the number of skipped results. + + + + + Contains the test results from a test class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The simple name of the type under test + The fully qualified name of the type under test + The namespace of the type under test + + + + Sets the exception thrown by the test fixture. + + The thrown exception + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the fully qualified test fixture exception type, when an exception has occurred. + + + + + Gets the number of tests which failed. + + + + + Gets the fully qualified name of the type under test. + + + + + Gets the test fixture exception message, when an exception has occurred. + + + + + Gets the simple name of the type under test. + + + + + Gets the namespace of the type under test. + + + + + Gets the number of tests which passed. + + + + + Gets the number of tests which were skipped. + + + + + Gets the test fixture exception stack trace, when an exception has occurred. + + + + + Represents a failed test result. + + + + + Represents the results from running a test method + + + + + Initializes a new instance of the class. The traits for + the test method are discovered using reflection. + + The method under test. + The display name for the test. If null, the fully qualified + type name is used. + + + + Initializes a new instance of the class. + + The name of the method under test. + The type of the method under test. + The display name for the test. If null, the fully qualified + type name is used. + The traits. + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets or sets the display name of the method under test. This is the value that's shown + during failures and in the resulting output XML. + + + + + Gets the name of the method under test. + + + + + Gets or sets the standard output/standard error from the test that was captured + while the test was running. + + + + + Gets the traits attached to the test method. + + + + + Gets the name of the type under test. + + + + + Creates a new instance of the class. + + The method under test + The exception throw by the test + The display name for the test. If null, the fully qualified + type name is used. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name of the test + The custom properties attached to the test method + The full type name of the exception throw + The exception message + The exception stack trace + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the exception type thrown by the test method. + + + + + Gets the exception message thrown by the test method. + + + + + Gets the stack trace of the exception thrown by the test method. + + + + + Represents a passing test result. + + + + + Create a new instance of the class. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + + + + Create a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The custom properties attached to the test method + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Represents a skipped test result. + + + + + Creates a new instance of the class. Uses reflection to discover + the skip reason. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The traits attached to the method under test + The skip reason + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the skip reason. + + + + + Represents information about an attribute. + + + + + Gets the instance of the attribute, if available. + + The type of the attribute + The instance of the attribute, if available. + + + + Gets an initialized property value of the attribute. + + The type of the property + The name of the property + The property value + + + + Represents information about a method. + + + + + Gets all the custom attributes for the method that are of the given type. + + The type of the attribute + The matching attributes that decorate the method + + + + Determines if the method has at least one instance of the given attribute type. + + The type of the attribute + True if the method has at least one instance of the given attribute type; false, otherwise + + + + Gets the fully qualified type name of the type that this method belongs to. + + + + + Gets a value indicating whether the method is abstract. + + + + + Gets a value indicating whether the method is static. + + + + + Gets the underlying for the method, if available. + + + + + Gets the name of the method. + + + + + Gets the fully qualified type name of the return type. + + + + + Represents information about a type. + + + + + Gets all the custom attributes for the type that are of the given attribute type. + + The type of the attribute + The matching attributes that decorate the type + + + + Gets all the methods + + + + + + Determines if the type has at least one instance of the given attribute type. + + The type of the attribute + True if the type has at least one instance of the given attribute type; false, otherwise + + + + Determines if the type implements the given interface. + + The type of the interface + True if the type implements the given interface; false, otherwise + + + + Gets a value indicating whether the type is abstract. + + + + + Gets a value indicating whether the type is sealed. + + + + + Gets the underlying object, if available. + + + + + Utility class which inspects methods for test information + + + + + Gets the skip reason from a test method. + + The method to be inspected + The skip reason + + + + Gets the test commands for a test method. + + The method to be inspected + The objects for the test method + + + + Gets the timeout value for a test method. + + The method to be inspected + The timeout, in milliseconds + + + + Gets the traits on a test method. + + The method to be inspected + A dictionary of the traits + + + + Determines whether a test method has a timeout. + + The method to be inspected + True if the method has a timeout; false, otherwise + + + + Determines whether a test method has traits. + + The method to be inspected + True if the method has traits; false, otherwise + + + + Determines whether a test method should be skipped. + + The method to be inspected + True if the method should be skipped; false, otherwise + + + + Determines whether a method is a test method. A test method must be decorated + with the (or derived class) and must not be abstract. + + The method to be inspected + True if the method is a test method; false, otherwise + + + + Wrapper to implement and using reflection. + + + + + Converts an into an using reflection. + + + + + + + Converts a into an using reflection. + + The method to wrap + The wrapper + + + + Converts a into an using reflection. + + The type to wrap + The wrapper + + + + Utility class which inspects types for test information + + + + + Determines if a type contains any test methods + + The type to be inspected + True if the class contains any test methods; false, otherwise + + + + Retrieves the type to run the test class with from the , if present. + + The type to be inspected + The type of the test class runner, if present; null, otherwise + + + + Retrieves a list of the test methods from the test class. + + The type to be inspected + The test methods + + + + Determines if the test class has a applied to it. + + The type to be inspected + True if the test class has a run with attribute; false, otherwise + + + + Determines if the type implements . + + The type to be inspected + True if the type implements ; false, otherwise + + + + Determines whether the specified type is abstract. + + The type. + + true if the specified type is abstract; otherwise, false. + + + + + Determines whether the specified type is static. + + The type. + + true if the specified type is static; otherwise, false. + + + + + Determines if a class is a test class. + + The type to be inspected + True if the type is a test class; false, otherwise + + + + Attribute that is applied to a method to indicate that it is a fact that should be run + by the test runner. It can also be extended to support a customized definition of a + test method. + + + + + Creates instances of which represent individual intended + invocations of the test method. + + The method under test + An enumerator through the desired test method invocations + + + + Enumerates the test commands represented by this test method. Derived classes should + override this method to return instances of , one per execution + of a test method. + + The test method + The test commands which will execute the test runs for the given method + + + + Gets the name of the test to be used when the test is skipped. Defaults to + null, which will cause the fully qualified test name to be used. + + + + + Marks the test so that it will not be run, and gets or sets the skip reason + + + + + Marks the test as failing if it does not finish running within the given time + period, in milliseconds; set to 0 or less to indicate the method has no timeout + + + + + Exception thrown when code unexpectedly fails to throw an exception. + + + + + Creates a new instance of the class. Call this constructor + when no exception was thrown. + + The type of the exception that was expected + + + + Creates a new instance of the class. Call this constructor + when an exception of the wrong type was thrown. + + The type of the exception that was expected + The actual exception that was thrown + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a test method exceeds the given timeout value + + + + + Creates a new instance of the class. + + The timeout value, in milliseconds + + + + Exception thrown when a value is unexpectedly false. + + + + + Creates a new instance of the class. + + The user message to be displayed, or null for the default message + + + diff --git a/Tools/xUnit/xunit.console.exe.config b/Tools/xUnit/xunit.console.exe.config index e73fc9d2..a253b460 100644 --- a/Tools/xUnit/xunit.console.exe.config +++ b/Tools/xUnit/xunit.console.exe.config @@ -1,21 +1,21 @@ - - - - -
- - - - - - - - - + + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/Tools/xUnit/xunit.extensions.xml b/Tools/xUnit/xunit.extensions.xml index 9cbe7153..db97c523 100644 --- a/Tools/xUnit/xunit.extensions.xml +++ b/Tools/xUnit/xunit.extensions.xml @@ -1,705 +1,705 @@ - - - - xunit.extensions - - - - - A wrapper for Assert which is used by . - - - - - Verifies that a collection contains a given object. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - Thrown when the object is not present in the collection - - - - Verifies that a collection contains a given object, using a comparer. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is not present in the collection - - - - Verifies that a string contains a given sub-string, using the current culture. - - The sub-string expected to be in the string - The string to be inspected - Thrown when the sub-string is not present inside the string - - - - Verifies that a string contains a given sub-string, using the given comparison type. - - The sub-string expected to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is not present inside the string - - - - Verifies that a collection does not contain a given object. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - Thrown when the object is present inside the container - - - - Verifies that a collection does not contain a given object, using a comparer. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is present inside the container - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - Thrown when the sub-string is present inside the string - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is present inside the given string - - - - Verifies that a block of code does not throw any exceptions. - - A delegate to the code to be tested - - - - Verifies that a collection is empty. - - The collection to be inspected - Thrown when the collection is null - Thrown when the collection is not empty - - - - Verifies that two objects are equal, using a default comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - Thrown when the objects are not equal - - - - Verifies that two objects are equal, using a custom comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - The comparer used to compare the two objects - Thrown when the objects are not equal - - - Do not call this method. Call Assert.Equal() instead. - - - - Verifies that the condition is false. - - The condition to be tested - Thrown if the condition is not false - - - - Verifies that the condition is false. - - The condition to be tested - The message to show when the condition is not false - Thrown if the condition is not false - - - - Serves as a hash function for a particular type. - - A hash code for the current . - - - - Verifies that a value is within a given range. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is not in the given range - - - - Verifies that a value is within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is not in the given range - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that a collection is not empty. - - The collection to be inspected - Thrown when a null collection is passed - Thrown when the collection is empty - - - - Verifies that two objects are not equal, using a default comparer. - - The type of the objects to be compared - The expected object - The actual object - Thrown when the objects are equal - - - - Verifies that two objects are not equal, using a custom comparer. - - The type of the objects to be compared - The expected object - The actual object - The comparer used to examine the objects - Thrown when the objects are equal - - - - Verifies that a value is not within a given range, using the default comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is in the given range - - - - Verifies that a value is not within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is in the given range - - - - Verifies that an object reference is not null. - - The object to be validated - Thrown when the object is not null - - - - Verifies that two objects are not the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are the same instance - - - - Verifies that an object reference is null. - - The object to be inspected - Thrown when the object reference is not null - - - - Verifies that two objects are the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are not the same instance - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that an expression is true. - - The condition to be inspected - Thrown when the condition is false - - - - Verifies that an expression is true. - - The condition to be inspected - The message to be shown when the condition is false - Thrown when the condition is false - - - - A class which can be derived from for test classes, which bring an overridable version - of Assert (using the class. - - - - - Gets a class which provides assertions. - - - - - Apply this attribute to your test method to replace the - with another role. - - - - - Replaces the identity of the current thread with . - - The role's name - - - - Restores the original . - - The method under test - - - - Stores the current and replaces it with - a new role identified in constructor. - - The method under test - - - - Apply this attribute to your test method to automatically create a - that is rolled back when the test is - finished. - - - - - Rolls back the transaction. - - - - - Creates the transaction. - - - - - Gets or sets the isolation level of the transaction. - Default value is .Unspecified. - - - - - Gets or sets the scope option for the transaction. - Default value is .Required. - - - - - Gets or sets the timeout of the transaction, in milliseconds. - By default, the transaction will not timeout. - - - - - Provides a data source for a data theory, with the data coming from a class - which must implement IEnumerable<object[]>. - - - - - Abstract attribute which represents a data source for a data theory. - Data source providers derive from this attribute and implement GetData - to return the data for the theory. - - - - - Returns the data to be used to test the theory. - - - The parameter is provided so that the - test data can be converted to the destination parameter type when necessary. - Generally, data should NOT be automatically converted, UNLESS the source data - format does not have rich types (for example, all numbers in Excel spreadsheets - are returned as even if they are integers). Derivers of - this class should NOT throw exceptions for mismatched types or mismatched number - of parameters; the test framework will throw these exceptions at the correct - time. - - The method that is being tested - The types of the parameters for the test method - The theory data - - - - Initializes a new instance of the class. - - The class that provides the data. - - - - - - - Represents an implementation of which uses an - instance of to get the data for a - decorated test method. - - - - - - - - Converts a parameter to its destination parameter type, if necessary. - - The parameter value - The destination parameter type (null if not known) - The converted parameter value - - - - Gets the data adapter to be used to retrieve the test data. - - - - - Provides a data source for a data theory, with the data coming from inline values. - - - - - Initializes a new instance of the class. - - The data values to pass to the theory - - - - Returns the data to be used to test the theory. - - The method that is being tested - The types of the parameters for the test method - The theory data, in table form - - - - Provides a data source for a data theory, with the data coming from an OLEDB connection. - - - - - Creates a new instance of . - - The OLEDB connection string to the data - The SELECT statement used to return the data for the theory - - - - - - - Provides a data source for a data theory, with the data coming from a public static property on the test class. - The property must return IEnumerable<object[]> with the test data. - - - - - Creates a new instance of / - - The name of the public static property on the test class that will provide the test data - - - - Returns the data to be used to test the theory. - - The method that is being tested - The types of the parameters for the test method - The theory data, in table form - - - - Provides a data source for a data theory, with the data coming a Microsoft SQL Server. - - - - - Creates a new instance of , using a trusted connection. - - The server name of the Microsoft SQL Server - The database name - The SQL SELECT statement to return the data for the data theory - - - - Creates a new instance of , using the provided username and password. - - The server name of the Microsoft SQL Server - The database name - The username for the server - The password for the server - The SQL SELECT statement to return the data for the data theory - - - - Provides a data source for a data theory, with the data coming a Microsoft Excel (.xls) spreadsheet. - - - - - Creates a new instance of . - - The filename of the XLS spreadsheet file; if the filename provided - is relative, then it is relative to the location of xunit.extensions.dll. - The SELECT statement that returns the data for the theory - - - - - - - A wrapper around the static operations on which allows time - to be frozen using the . The clock begins in the - thawed state; that is, calls to , , and - return current (non-frozen) values. - - - - - Freezes the clock with the current time. - Until is called, all calls to , , and - will return the exact same values. - - - - - Freezes the clock with the given date and time, considered to be local time. - Until is called, all calls to , , and - will return the exact same values. - - The local date and time to freeze to - - - - Freezes the clock with the given date and time, considered to be Coordinated Universal Time (UTC). - Until is called, all calls to , , and - will return the exact same values. - - The UTC date and time to freeze to - - - - Thaws the clock so that , , and - return normal values. - - - - - Gets a object that is set to the current date and time on this computer, - expressed as the local time. - - - - - Gets the current date. - - - - - Gets a object that is set to the current date and time on this computer, - expressed as the Coordinated Universal Time (UTC). - - - - - Apply this attribute to your test method to freeze the time represented by the - class. - - - - - Freeze the clock with the current date and time. - - - - - Freeze the clock with the given date, considered to be local time. - - The frozen year - The frozen month - The frozen day - - - - Freeze the clock with the given date and time, considered to be in local time. - - The frozen year - The frozen month - The frozen day - The frozen hour - The frozen minute - The frozen second - - - - Freeze the clock with the given date and time, with the given kind of time. - - The frozen year - The frozen month - The frozen day - The frozen hour - The frozen minute - The frozen second - The frozen time kind - - - - Thaws the clock. - - The method under test - - - - Freezes the clock. - - The method under test - - - - Marks a test method as being a data theory. Data theories are tests which are fed - various bits of data from a data source, mapping to parameters on the test method. - If the data source contains multiple rows, then the test method is executed - multiple times (once with each data row). - - - - - Creates instances of which represent individual intended - invocations of the test method, one per data row in the data source. - - The method under test - An enumerator through the desired test method invocations - - - - Represents a single invocation of a data theory test method. - - - - - Creates a new instance of . - - The method under test - The parameters to be passed to the test method - - - - - - - Gets the parameter values that are passed to the test method. - - - - - Apply to a test method to trace the method begin and end. - - - - - This method is called before the test method is executed. - - The method under test - - - - This method is called after the test method is executed. - - The method under test - - - + + + + xunit.extensions + + + + + A wrapper for Assert which is used by . + + + + + Verifies that a collection contains a given object. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + Thrown when the object is not present in the collection + + + + Verifies that a collection contains a given object, using a comparer. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is not present in the collection + + + + Verifies that a string contains a given sub-string, using the current culture. + + The sub-string expected to be in the string + The string to be inspected + Thrown when the sub-string is not present inside the string + + + + Verifies that a string contains a given sub-string, using the given comparison type. + + The sub-string expected to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is not present inside the string + + + + Verifies that a collection does not contain a given object. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + Thrown when the object is present inside the container + + + + Verifies that a collection does not contain a given object, using a comparer. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is present inside the container + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + Thrown when the sub-string is present inside the string + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is present inside the given string + + + + Verifies that a block of code does not throw any exceptions. + + A delegate to the code to be tested + + + + Verifies that a collection is empty. + + The collection to be inspected + Thrown when the collection is null + Thrown when the collection is not empty + + + + Verifies that two objects are equal, using a default comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + Thrown when the objects are not equal + + + + Verifies that two objects are equal, using a custom comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + The comparer used to compare the two objects + Thrown when the objects are not equal + + + Do not call this method. Call Assert.Equal() instead. + + + + Verifies that the condition is false. + + The condition to be tested + Thrown if the condition is not false + + + + Verifies that the condition is false. + + The condition to be tested + The message to show when the condition is not false + Thrown if the condition is not false + + + + Serves as a hash function for a particular type. + + A hash code for the current . + + + + Verifies that a value is within a given range. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is not in the given range + + + + Verifies that a value is within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is not in the given range + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that a collection is not empty. + + The collection to be inspected + Thrown when a null collection is passed + Thrown when the collection is empty + + + + Verifies that two objects are not equal, using a default comparer. + + The type of the objects to be compared + The expected object + The actual object + Thrown when the objects are equal + + + + Verifies that two objects are not equal, using a custom comparer. + + The type of the objects to be compared + The expected object + The actual object + The comparer used to examine the objects + Thrown when the objects are equal + + + + Verifies that a value is not within a given range, using the default comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is in the given range + + + + Verifies that a value is not within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is in the given range + + + + Verifies that an object reference is not null. + + The object to be validated + Thrown when the object is not null + + + + Verifies that two objects are not the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are the same instance + + + + Verifies that an object reference is null. + + The object to be inspected + Thrown when the object reference is not null + + + + Verifies that two objects are the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are not the same instance + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that an expression is true. + + The condition to be inspected + Thrown when the condition is false + + + + Verifies that an expression is true. + + The condition to be inspected + The message to be shown when the condition is false + Thrown when the condition is false + + + + A class which can be derived from for test classes, which bring an overridable version + of Assert (using the class. + + + + + Gets a class which provides assertions. + + + + + Apply this attribute to your test method to replace the + with another role. + + + + + Replaces the identity of the current thread with . + + The role's name + + + + Restores the original . + + The method under test + + + + Stores the current and replaces it with + a new role identified in constructor. + + The method under test + + + + Apply this attribute to your test method to automatically create a + that is rolled back when the test is + finished. + + + + + Rolls back the transaction. + + + + + Creates the transaction. + + + + + Gets or sets the isolation level of the transaction. + Default value is .Unspecified. + + + + + Gets or sets the scope option for the transaction. + Default value is .Required. + + + + + Gets or sets the timeout of the transaction, in milliseconds. + By default, the transaction will not timeout. + + + + + Provides a data source for a data theory, with the data coming from a class + which must implement IEnumerable<object[]>. + + + + + Abstract attribute which represents a data source for a data theory. + Data source providers derive from this attribute and implement GetData + to return the data for the theory. + + + + + Returns the data to be used to test the theory. + + + The parameter is provided so that the + test data can be converted to the destination parameter type when necessary. + Generally, data should NOT be automatically converted, UNLESS the source data + format does not have rich types (for example, all numbers in Excel spreadsheets + are returned as even if they are integers). Derivers of + this class should NOT throw exceptions for mismatched types or mismatched number + of parameters; the test framework will throw these exceptions at the correct + time. + + The method that is being tested + The types of the parameters for the test method + The theory data + + + + Initializes a new instance of the class. + + The class that provides the data. + + + + + + + Represents an implementation of which uses an + instance of to get the data for a + decorated test method. + + + + + + + + Converts a parameter to its destination parameter type, if necessary. + + The parameter value + The destination parameter type (null if not known) + The converted parameter value + + + + Gets the data adapter to be used to retrieve the test data. + + + + + Provides a data source for a data theory, with the data coming from inline values. + + + + + Initializes a new instance of the class. + + The data values to pass to the theory + + + + Returns the data to be used to test the theory. + + The method that is being tested + The types of the parameters for the test method + The theory data, in table form + + + + Provides a data source for a data theory, with the data coming from an OLEDB connection. + + + + + Creates a new instance of . + + The OLEDB connection string to the data + The SELECT statement used to return the data for the theory + + + + + + + Provides a data source for a data theory, with the data coming from a public static property on the test class. + The property must return IEnumerable<object[]> with the test data. + + + + + Creates a new instance of / + + The name of the public static property on the test class that will provide the test data + + + + Returns the data to be used to test the theory. + + The method that is being tested + The types of the parameters for the test method + The theory data, in table form + + + + Provides a data source for a data theory, with the data coming a Microsoft SQL Server. + + + + + Creates a new instance of , using a trusted connection. + + The server name of the Microsoft SQL Server + The database name + The SQL SELECT statement to return the data for the data theory + + + + Creates a new instance of , using the provided username and password. + + The server name of the Microsoft SQL Server + The database name + The username for the server + The password for the server + The SQL SELECT statement to return the data for the data theory + + + + Provides a data source for a data theory, with the data coming a Microsoft Excel (.xls) spreadsheet. + + + + + Creates a new instance of . + + The filename of the XLS spreadsheet file; if the filename provided + is relative, then it is relative to the location of xunit.extensions.dll. + The SELECT statement that returns the data for the theory + + + + + + + A wrapper around the static operations on which allows time + to be frozen using the . The clock begins in the + thawed state; that is, calls to , , and + return current (non-frozen) values. + + + + + Freezes the clock with the current time. + Until is called, all calls to , , and + will return the exact same values. + + + + + Freezes the clock with the given date and time, considered to be local time. + Until is called, all calls to , , and + will return the exact same values. + + The local date and time to freeze to + + + + Freezes the clock with the given date and time, considered to be Coordinated Universal Time (UTC). + Until is called, all calls to , , and + will return the exact same values. + + The UTC date and time to freeze to + + + + Thaws the clock so that , , and + return normal values. + + + + + Gets a object that is set to the current date and time on this computer, + expressed as the local time. + + + + + Gets the current date. + + + + + Gets a object that is set to the current date and time on this computer, + expressed as the Coordinated Universal Time (UTC). + + + + + Apply this attribute to your test method to freeze the time represented by the + class. + + + + + Freeze the clock with the current date and time. + + + + + Freeze the clock with the given date, considered to be local time. + + The frozen year + The frozen month + The frozen day + + + + Freeze the clock with the given date and time, considered to be in local time. + + The frozen year + The frozen month + The frozen day + The frozen hour + The frozen minute + The frozen second + + + + Freeze the clock with the given date and time, with the given kind of time. + + The frozen year + The frozen month + The frozen day + The frozen hour + The frozen minute + The frozen second + The frozen time kind + + + + Thaws the clock. + + The method under test + + + + Freezes the clock. + + The method under test + + + + Marks a test method as being a data theory. Data theories are tests which are fed + various bits of data from a data source, mapping to parameters on the test method. + If the data source contains multiple rows, then the test method is executed + multiple times (once with each data row). + + + + + Creates instances of which represent individual intended + invocations of the test method, one per data row in the data source. + + The method under test + An enumerator through the desired test method invocations + + + + Represents a single invocation of a data theory test method. + + + + + Creates a new instance of . + + The method under test + The parameters to be passed to the test method + + + + + + + Gets the parameter values that are passed to the test method. + + + + + Apply to a test method to trace the method begin and end. + + + + + This method is called before the test method is executed. + + The method under test + + + + This method is called after the test method is executed. + + The method under test + + + diff --git a/Tools/xUnit/xunit.runner.utility.xml b/Tools/xUnit/xunit.runner.utility.xml index ed1f2d44..90212e35 100644 --- a/Tools/xUnit/xunit.runner.utility.xml +++ b/Tools/xUnit/xunit.runner.utility.xml @@ -1,407 +1,407 @@ - - - - xunit.runner.utility - - - - - Wraps calls to the Executor. Used by runners to perform version-resilient test - enumeration and execution. - - - - - Wraps calls to the Executor. Used by runners to perform version-resilient test - enumeration and execution. - - - - - Enumerates the tests in an assembly. - - The fully-formed assembly node of the XML - - - - Gets a count of the tests in the assembly. - - Returns the number of tests, if known; returns -1 if not known. May not represent - an exact count, but should be a best effort guess by the framework. - - - - Runs all the tests in an assembly. - - The callback which is called as each test/class/assembly is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed assembly node for the assembly that was just run. - - - - Runs all the tests in the given class. - - The type. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class that was just run. - - - - Runs a single test in a class. - - The type to run. - The method to run. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class of the test that was just run. - - - - Runs several tests in a single class. - - The type. - The methods to run. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class of the tests that were just run. - - - - Gets the full pathname to the assembly under test. - - - - - Gets the version of xunit.dll used by the test assembly. - - - - - Initializes a new instance of the class. - - The assembly filename. - The config filename. If null, the default config filename will be used. - Set to true to enable shadow copying; false, otherwise. - - - - Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Represents a logger used by and . - - - - - Called when the assembly has finished running. - - The assembly filename. - The total number of tests run. - The number of failed tests. - The number of skipped tests. - The time taken to run, in seconds. - - - - Called when the assembly has started running. - - The assembly filename. - The version of xunit.dll. - - - - Called when a class failure is encountered (i.e., when a fixture from - IUseFixture throws an exception during construction or . - - The full type name of the class. - The full type name of the exception. - The exception message. - The exception stack trace. - - - - - Called when an exception is thrown (i.e., a catastrophic failure of the testing system). - - The assembly filename. - The exception that was thrown. - - - - Called when a test fails. - - The description name of the test. - The full type name of the test class. - The name of the method. - The time spent running the test, in seconds. - The full type name of the exception. - The exception message. - The exception stack trace. - - - - Called when a test has finished running, regardless of what the result was. - - The description name of the test. - The full type name of the test class. - The name of the method. - The time spent running the test, in seconds. - The output of the test during its run. - Return true to continue running tests; return false to stop the test run. - - - - Called when a test has passed. - - The description name of the test. - The full type name of the test class. - The name of the method. - The time spent running the test, in seconds. - - - - Called when a test was finished. - - The description name of the test. - The full type name of the test class. - The name of the method. - The skip reason. - - - - Called when a test has started running. - - The description name of the test. - The full type name of the test class. - The name of the method. - Return true to continue running tests; return false to stop the test run. - - - - Called when a transform is being run against the assembly XML. - - The transform's output type, if known; null if not. - The filename the transform is writing to, if known; - null if the results are not being written to file. - - - - The result of a test run via . - - - - - All tests passed, with no class-level failures - - - - - At least one test failed, or there was a class-level failure - - - - - There were no tests to run - - - - - Represents a transformation of the resulting assembly XML into some output format. - - - - - Transforms the given assembly XML into the destination format. - - The assembly XML. - - - - Gets the output filename, if known; returns null if the output isn't done to file. - - - - - Gets the type of the output. - - - - - Runs tests in an assembly, and transforms the XML results into calls to - the provided . - - - - - Initializes a new instance of the class. - - The executor wrapper. - The logger. - - - - Executes the tests in the assembly. - - Returns true if there were no failures; return false otherwise. - - - - Executes the tetss in the assembly, and then executes the transforms with the - resulting assembly XML. - - The transforms to execute. - Returns true if there were no failures; return false otherwise. - - - - Runs the class. - - The type. - - - - - Runs a single test in a test class. - - The full name of the class. - The name of the method. - - - - Runs the list of tests in a test class. - - The full name of the class. - The names of the methods to run. - - - - An implementation of which writes the - XML to a file without any transformation applied. - - - - - Initializes a new instance of the class. - - The output filename. - - - - - - - - - - - - - An implementation of which writes the - XML to a file after applying the XSL stylesheet in the given stream. - - - - - Initializes a new instance of the class. - - The stream with the XSL stylesheet. - The output filename. - The output type. - - - - - - - - - - - - - Parses the XML nodes from the version resilient runner facility and converts - them into calls against the provided . - - - - - Logs a result XML node. Maybe be any kind of XML node. - - The node to be logged. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the assembly node by calling . - - The assembly node. - The logger. - - - - Logs the class node by calling (if the class failed). - The exception type was added in xUnit.net 1.1, so when the test assembly is linked against - xUnit.net versions prior to 1.1, the exception type will be null. - - The class node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the start node by calling . The start node was added - in xUnit.net 1.1, so it will only be present when the test assembly is linked against xunit.dll - version 1.1 or later. - - The start node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the test node by calling . It will also call - , , or - as appropriate. - - The test node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - + + + + xunit.runner.utility + + + + + Wraps calls to the Executor. Used by runners to perform version-resilient test + enumeration and execution. + + + + + Wraps calls to the Executor. Used by runners to perform version-resilient test + enumeration and execution. + + + + + Enumerates the tests in an assembly. + + The fully-formed assembly node of the XML + + + + Gets a count of the tests in the assembly. + + Returns the number of tests, if known; returns -1 if not known. May not represent + an exact count, but should be a best effort guess by the framework. + + + + Runs all the tests in an assembly. + + The callback which is called as each test/class/assembly is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed assembly node for the assembly that was just run. + + + + Runs all the tests in the given class. + + The type. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class that was just run. + + + + Runs a single test in a class. + + The type to run. + The method to run. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class of the test that was just run. + + + + Runs several tests in a single class. + + The type. + The methods to run. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class of the tests that were just run. + + + + Gets the full pathname to the assembly under test. + + + + + Gets the version of xunit.dll used by the test assembly. + + + + + Initializes a new instance of the class. + + The assembly filename. + The config filename. If null, the default config filename will be used. + Set to true to enable shadow copying; false, otherwise. + + + + Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Represents a logger used by and . + + + + + Called when the assembly has finished running. + + The assembly filename. + The total number of tests run. + The number of failed tests. + The number of skipped tests. + The time taken to run, in seconds. + + + + Called when the assembly has started running. + + The assembly filename. + The version of xunit.dll. + + + + Called when a class failure is encountered (i.e., when a fixture from + IUseFixture throws an exception during construction or . + + The full type name of the class. + The full type name of the exception. + The exception message. + The exception stack trace. + + + + + Called when an exception is thrown (i.e., a catastrophic failure of the testing system). + + The assembly filename. + The exception that was thrown. + + + + Called when a test fails. + + The description name of the test. + The full type name of the test class. + The name of the method. + The time spent running the test, in seconds. + The full type name of the exception. + The exception message. + The exception stack trace. + + + + Called when a test has finished running, regardless of what the result was. + + The description name of the test. + The full type name of the test class. + The name of the method. + The time spent running the test, in seconds. + The output of the test during its run. + Return true to continue running tests; return false to stop the test run. + + + + Called when a test has passed. + + The description name of the test. + The full type name of the test class. + The name of the method. + The time spent running the test, in seconds. + + + + Called when a test was finished. + + The description name of the test. + The full type name of the test class. + The name of the method. + The skip reason. + + + + Called when a test has started running. + + The description name of the test. + The full type name of the test class. + The name of the method. + Return true to continue running tests; return false to stop the test run. + + + + Called when a transform is being run against the assembly XML. + + The transform's output type, if known; null if not. + The filename the transform is writing to, if known; + null if the results are not being written to file. + + + + The result of a test run via . + + + + + All tests passed, with no class-level failures + + + + + At least one test failed, or there was a class-level failure + + + + + There were no tests to run + + + + + Represents a transformation of the resulting assembly XML into some output format. + + + + + Transforms the given assembly XML into the destination format. + + The assembly XML. + + + + Gets the output filename, if known; returns null if the output isn't done to file. + + + + + Gets the type of the output. + + + + + Runs tests in an assembly, and transforms the XML results into calls to + the provided . + + + + + Initializes a new instance of the class. + + The executor wrapper. + The logger. + + + + Executes the tests in the assembly. + + Returns true if there were no failures; return false otherwise. + + + + Executes the tetss in the assembly, and then executes the transforms with the + resulting assembly XML. + + The transforms to execute. + Returns true if there were no failures; return false otherwise. + + + + Runs the class. + + The type. + + + + + Runs a single test in a test class. + + The full name of the class. + The name of the method. + + + + Runs the list of tests in a test class. + + The full name of the class. + The names of the methods to run. + + + + An implementation of which writes the + XML to a file without any transformation applied. + + + + + Initializes a new instance of the class. + + The output filename. + + + + + + + + + + + + + An implementation of which writes the + XML to a file after applying the XSL stylesheet in the given stream. + + + + + Initializes a new instance of the class. + + The stream with the XSL stylesheet. + The output filename. + The output type. + + + + + + + + + + + + + Parses the XML nodes from the version resilient runner facility and converts + them into calls against the provided . + + + + + Logs a result XML node. Maybe be any kind of XML node. + + The node to be logged. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the assembly node by calling . + + The assembly node. + The logger. + + + + Logs the class node by calling (if the class failed). + The exception type was added in xUnit.net 1.1, so when the test assembly is linked against + xUnit.net versions prior to 1.1, the exception type will be null. + + The class node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the start node by calling . The start node was added + in xUnit.net 1.1, so it will only be present when the test assembly is linked against xunit.dll + version 1.1 or later. + + The start node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the test node by calling . It will also call + , , or + as appropriate. + + The test node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + diff --git a/Tools/xUnit/xunit.xml b/Tools/xUnit/xunit.xml index 0aada6c7..f7668194 100644 --- a/Tools/xUnit/xunit.xml +++ b/Tools/xUnit/xunit.xml @@ -1,2132 +1,2132 @@ - - - - xunit - - - - - Contains various static methods that are used to verify that conditions are met during the - process of running tests. - - - - - Initializes a new instance of the class. - - - - - Verifies that a collection contains a given object. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - Thrown when the object is not present in the collection - - - - Verifies that a collection contains a given object, using a comparer. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is not present in the collection - - - - Verifies that a string contains a given sub-string, using the current culture. - - The sub-string expected to be in the string - The string to be inspected - Thrown when the sub-string is not present inside the string - - - - Verifies that a string contains a given sub-string, using the given comparison type. - - The sub-string expected to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is not present inside the string - - - - Verifies that a collection does not contain a given object. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - Thrown when the object is present inside the container - - - - Verifies that a collection does not contain a given object, using a comparer. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is present inside the container - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - Thrown when the sub-string is present inside the string - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is present inside the given string - - - - Verifies that a block of code does not throw any exceptions. - - A delegate to the code to be tested - - - - Verifies that a collection is empty. - - The collection to be inspected - Thrown when the collection is null - Thrown when the collection is not empty - - - - Verifies that two objects are equal, using a default comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - Thrown when the objects are not equal - - - - Verifies that two objects are equal, using a custom comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - The comparer used to compare the two objects - Thrown when the objects are not equal - - - Do not call this method. - - - - Verifies that the condition is false. - - The condition to be tested - Thrown if the condition is not false - - - - Verifies that the condition is false. - - The condition to be tested - The message to show when the condition is not false - Thrown if the condition is not false - - - - Verifies that a value is within a given range. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is not in the given range - - - - Verifies that a value is within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is not in the given range - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that a collection is not empty. - - The collection to be inspected - Thrown when a null collection is passed - Thrown when the collection is empty - - - - Verifies that two objects are not equal, using a default comparer. - - The type of the objects to be compared - The expected object - The actual object - Thrown when the objects are equal - - - - Verifies that two objects are not equal, using a custom comparer. - - The type of the objects to be compared - The expected object - The actual object - The comparer used to examine the objects - Thrown when the objects are equal - - - - Verifies that a value is not within a given range, using the default comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is in the given range - - - - Verifies that a value is not within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is in the given range - - - - Verifies that an object reference is not null. - - The object to be validated - Thrown when the object is not null - - - - Verifies that two objects are not the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are the same instance - - - - Verifies that an object reference is null. - - The object to be inspected - Thrown when the object reference is not null - - - - Verifies that two objects are the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are not the same instance - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that an expression is true. - - The condition to be inspected - Thrown when the condition is false - - - - Verifies that an expression is true. - - The condition to be inspected - The message to be shown when the condition is false - Thrown when the condition is false - - - - Used by the Throws and DoesNotThrow methods. - - - - - Captures standard output and standard error, and inserts the values into the - as it traverses the chain. - - - - - Base class used by commands which delegate to inner commands. - - - - - Interface which represents the ability to invoke of a test method. - - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Creates the start XML to be sent to the callback when the test is about to start - running. - - Return the of the start node, or null if the test - is known that it will not be running. - - - - Gets the display name of the test method. - - - - - Determines if the test runner infrastructure should create a new instance of the - test class before running the test. - - - - - Creates a new instance of the class. - - The inner command to delegate to. - - - - - - - - - - - - - - - - - - - Initializes a new instance of the class. - - The inner command - - - - - - - Base class for exceptions that have actual and expected values - - - - - The base assert exception class - - - - - Initializes a new instance of the class. - - - - - Initializes a new instance of the class. - - The user message to be displayed - - - - Initializes a new instance of the class. - - The user message to be displayed - The inner exception - - - - Initializes a new instance of the class. - - The user message to be displayed - The stack trace to be displayed - - - - Filters the stack trace to remove all lines that occur within the testing framework. - - The original stack trace - The filtered stack trace - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Gets the user message - - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - Set to true to skip the check for difference position - - - - Gets the actual value. - - - - - Gets the expected value. - - - - - Gets a message that describes the current exception. Includes the expected and actual values. - - The error message that explains the reason for the exception, or an empty string(""). - 1 - - - - Exception thrown when a collection unexpectedly does not contain the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. - Version-resilient runners should link against xunit.runner.utility.dll and use - ExecutorWrapper instead. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Exception thrown when the value is unexpectedly not of the given type or a derived type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Allows the user to record actions for a test. - - - - - Records any exception which is thrown by the given code. - - The code which may thrown an exception. - Returns the exception that was thrown by the code; null, otherwise. - - - - Exception that is thrown when one or more exceptions are thrown from - the After method of a . - - - - - Initializes a new instance of the class. - - The exceptions. - - - - Initializes a new instance of the class. - - The exceptions. - - - - Gets the list of exceptions thrown in the After method. - - - - - Gets a message that describes the current exception. - - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - - - - Implementation of which executes the - instances attached to a test method. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Wraps any exceptions thrown by the command execution. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Guard class, used for guard clauses and argument validation - - - - - - - - - - - - - - Base class which contains XML manipulation helper methods - - - - - Interface that represents a single test result. - - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - The amount of time spent in execution - - - - - Adds the test execution time to the XML node. - - The XML node. - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - The amount of time spent in execution - - - - - Utility methods for dealing with exceptions. - - - - - Gets the message for the exception, including any inner exception messages. - - The exception - The formatted message - - - - Gets the stack trace for the exception, including any inner exceptions. - - The exception - The formatted stack trace - - - - Rethrows an exception object without losing the existing stack trace information - - The exception to re-throw. - - For more information on this technique, see - http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx - - - - - XML utility methods - - - - - Adds an attribute to an XML node. - - The XML node. - The attribute name. - The attribute value. - - - - Adds a CDATA section to an XML node. - - The XML node. - The text for the CDATA section. - - - - Adds a child element to an XML node. - - The parent XML node. - The child element name. - The new child XML element. - - - - Exception that is thrown when a call to Debug.Assert() fails. - - - - - Creates a new instance of the class. - - The original assert message - - - - Creates a new instance of the class. - - The original assert message - The original assert detailed message - - - - Gets the original assert detailed message. - - - - - Gets the original assert message. - - - - - Gets a message that describes the current exception. - - - - - Exception thrown when a collection unexpectedly contains the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Exception thrown when code unexpectedly throws an exception. - - - - - Creates a new instance of the class. - - Actual exception - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a collection is unexpectedly not empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly not equal. - - - - - Creates a new instance of the class. - - The expected object value - The actual object value - - - - Exception thrown when a value is unexpectedly true. - - - - - Creates a new instance of the class. - - The user message to be display, or null for the default message - - - - Exception thrown when a value is unexpectedly not in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Exception thrown when the value is unexpectedly of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Exception thrown when the value is unexpectedly not of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Used to decorate xUnit.net test classes that utilize fixture classes. - An instance of the fixture data is initialized just before the first - test in the class is run, and if it implements IDisposable, is disposed - after the last test in the class is run. - - The type of the fixture - - - - Called on the test class just before each test method is run, - passing the fixture data so that it can be used for the test. - All test runs share the same instance of fixture data. - - The fixture data - - - - Exception thrown when a value is unexpectedly in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Base attribute which indicates a test method interception (allows code to be run before and - after the test is run). - - - - - This method is called after the test method is executed. - - The method under test - - - - This method is called before the test method is executed. - - The method under test - - - - Exception thrown when a collection is unexpectedly empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly equal. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object is unexpectedly null. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpected the same instance. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object reference is unexpectedly not null. - - - - - Creates a new instance of the class. - - - - - - Command that automatically creates the instance of the test class - and disposes it (if it implements ). - - - - - Creates a new instance of the object. - - The command that is bring wrapped - The method under test - - - - Executes the test method. Creates a new instance of the class - under tests and passes it to the inner command. Also catches - any exceptions and converts them into s. - - The instance of the test class - Returns information about the test run - - - - A command wrapper which catches Trace.Assert and Debug.Assert failures and turns - them into assertion exceptions. - - - - - Creates a new instance of the class. - - The command that will be wrapped. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Command used to wrap a which has associated - fixture data. - - - - - Creates a new instance of the class. - - The inner command - The fixtures to be set on the test class - - - - Sets the fixtures on the test class by calling SetFixture, then - calls the inner command. - - The instance of the test class - Returns information about the test run - - - - A timer class used to figure out how long tests take to run. On most .NET implementations - this will use the class because it's a high - resolution timer; however, on Silverlight/CoreCLR, it will use - (which will provide lower resolution results). - - - - - Creates a new instance of the class. - - - - - Starts timing. - - - - - Stops timing. - - - - - Gets how long the timer ran, in milliseconds. In order for this to be valid, - both and must have been called. - - - - - Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). - - - - - Creates a new instance of the class. - - The trait name - The trait value - - - - Gets the trait name. - - - - - Gets the trait value. - - - - - Runner that executes an synchronously. - - - - - Execute the . - - The test class command to execute - The methods to execute; if null or empty, all methods will be executed - The start run callback - The end run result callback - A with the results of the test run - - - - Factory for objects, based on the type under test. - - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Represents an xUnit.net test class - - - - - Interface which describes the ability to executes all the tests in a test class. - - - - - Allows the test class command to choose the next test to be run from the list of - tests that have not yet been run, thereby allowing it to choose the run order. - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the type that is being tested - - - - - Creates a new instance of the class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The type under test - - - - Chooses the next test to run, randomly, using the . - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the randomizer used to determine the order in which tests are run. - - - - - Sets the type that is being tested - - - - - Implementation of that represents a skipped test. - - - - - Represents an xUnit.net test command. - - - - - The method under test. - - - - - Initializes a new instance of the class. - - The method under test. - - - - Initializes a new instance of the class. - - The method under test. - The display name of the test. - - - - - - - - - - - - - Gets the name of the method under test. - - - - - Gets the name of the type under test. - - - - - - - - Creates a new instance of the class. - - The method that is being skipped - The display name for the test. If null, the fully qualified - type name is used. - - - - - - - - - - - - - Factory for creating objects. - - - - - Make instances of objects for the given class and method. - - The class command - The method under test - The set of objects - - - - A command wrapper which times the running of a command. - - - - - Creates a new instance of the class. - - The command that will be timed. - - - - Executes the inner test method, gathering the amount of time it takes to run. - - Returns information about the test run - - - - Wraps a command which should fail if it runs longer than the given timeout value. - - - - - Creates a new instance of the class. - - The command to be run - The timout, in milliseconds - The method under test - - - - Executes the test method, failing if it takes too long. - - Returns information about the test run - - - - Gets the timeout value, in milliseconds. - - - - - Attributes used to decorate a test fixture that is run with an alternate test runner. - The test runner must implement the interface. - - - - - Creates a new instance of the class. - - The class which implements ITestClassCommand and acts as the runner - for the test fixture. - - - - Gets the test class command. - - - - - Exception thrown when two object references are unexpectedly not the same instance. - - - - - Creates a new instance of the class. - - The expected object reference - The actual object reference - - - - Contains the test results from an assembly. - - - - - Contains multiple test results, representing them as a composite test result. - - - - - Adds a test result to the composite test result list. - - - - - - Gets the test results. - - - - - Creates a new instance of the class. - - The filename of the assembly - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the directory where the assembly resides. - - - - - Gets the number of failed results. - - - - - Gets the fully qualified filename of the assembly. - - - - - Gets the number of passed results. - - - - - Gets the number of skipped results. - - - - - Contains the test results from a test class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The simple name of the type under test - The fully qualified name of the type under test - The namespace of the type under test - - - - Sets the exception thrown by the test fixture. - - The thrown exception - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the fully qualified test fixture exception type, when an exception has occurred. - - - - - Gets the number of tests which failed. - - - - - Gets the fully qualified name of the type under test. - - - - - Gets the test fixture exception message, when an exception has occurred. - - - - - Gets the simple name of the type under test. - - - - - Gets the namespace of the type under test. - - - - - Gets the number of tests which passed. - - - - - Gets the number of tests which were skipped. - - - - - Gets the test fixture exception stack trace, when an exception has occurred. - - - - - Represents a failed test result. - - - - - Represents the results from running a test method - - - - - Initializes a new instance of the class. The traits for - the test method are discovered using reflection. - - The method under test. - The display name for the test. If null, the fully qualified - type name is used. - - - - Initializes a new instance of the class. - - The name of the method under test. - The type of the method under test. - The display name for the test. If null, the fully qualified - type name is used. - The traits. - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets or sets the display name of the method under test. This is the value that's shown - during failures and in the resulting output XML. - - - - - Gets the name of the method under test. - - - - - Gets or sets the standard output/standard error from the test that was captured - while the test was running. - - - - - Gets the traits attached to the test method. - - - - - Gets the name of the type under test. - - - - - Creates a new instance of the class. - - The method under test - The exception throw by the test - The display name for the test. If null, the fully qualified - type name is used. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name of the test - The custom properties attached to the test method - The full type name of the exception throw - The exception message - The exception stack trace - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the exception type thrown by the test method. - - - - - Gets the exception message thrown by the test method. - - - - - Gets the stack trace of the exception thrown by the test method. - - - - - Represents a passing test result. - - - - - Create a new instance of the class. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - - - - Create a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The custom properties attached to the test method - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Represents a skipped test result. - - - - - Creates a new instance of the class. Uses reflection to discover - the skip reason. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The traits attached to the method under test - The skip reason - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the skip reason. - - - - - Represents information about an attribute. - - - - - Gets the instance of the attribute, if available. - - The type of the attribute - The instance of the attribute, if available. - - - - Gets an initialized property value of the attribute. - - The type of the property - The name of the property - The property value - - - - Represents information about a method. - - - - - Gets all the custom attributes for the method that are of the given type. - - The type of the attribute - The matching attributes that decorate the method - - - - Determines if the method has at least one instance of the given attribute type. - - The type of the attribute - True if the method has at least one instance of the given attribute type; false, otherwise - - - - Gets the fully qualified type name of the type that this method belongs to. - - - - - Gets a value indicating whether the method is abstract. - - - - - Gets a value indicating whether the method is static. - - - - - Gets the underlying for the method, if available. - - - - - Gets the name of the method. - - - - - Gets the fully qualified type name of the return type. - - - - - Represents information about a type. - - - - - Gets all the custom attributes for the type that are of the given attribute type. - - The type of the attribute - The matching attributes that decorate the type - - - - Gets all the methods - - - - - - Determines if the type has at least one instance of the given attribute type. - - The type of the attribute - True if the type has at least one instance of the given attribute type; false, otherwise - - - - Determines if the type implements the given interface. - - The type of the interface - True if the type implements the given interface; false, otherwise - - - - Gets a value indicating whether the type is abstract. - - - - - Gets a value indicating whether the type is sealed. - - - - - Gets the underlying object, if available. - - - - - Utility class which inspects methods for test information - - - - - Gets the skip reason from a test method. - - The method to be inspected - The skip reason - - - - Gets the test commands for a test method. - - The method to be inspected - The objects for the test method - - - - Gets the timeout value for a test method. - - The method to be inspected - The timeout, in milliseconds - - - - Gets the traits on a test method. - - The method to be inspected - A dictionary of the traits - - - - Determines whether a test method has a timeout. - - The method to be inspected - True if the method has a timeout; false, otherwise - - - - Determines whether a test method has traits. - - The method to be inspected - True if the method has traits; false, otherwise - - - - Determines whether a test method should be skipped. - - The method to be inspected - True if the method should be skipped; false, otherwise - - - - Determines whether a method is a test method. A test method must be decorated - with the (or derived class) and must not be abstract. - - The method to be inspected - True if the method is a test method; false, otherwise - - - - Wrapper to implement and using reflection. - - - - - Converts an into an using reflection. - - - - - - - Converts a into an using reflection. - - The method to wrap - The wrapper - - - - Converts a into an using reflection. - - The type to wrap - The wrapper - - - - Utility class which inspects types for test information - - - - - Determines if a type contains any test methods - - The type to be inspected - True if the class contains any test methods; false, otherwise - - - - Retrieves the type to run the test class with from the , if present. - - The type to be inspected - The type of the test class runner, if present; null, otherwise - - - - Retrieves a list of the test methods from the test class. - - The type to be inspected - The test methods - - - - Determines if the test class has a applied to it. - - The type to be inspected - True if the test class has a run with attribute; false, otherwise - - - - Determines if the type implements . - - The type to be inspected - True if the type implements ; false, otherwise - - - - Determines whether the specified type is abstract. - - The type. - - true if the specified type is abstract; otherwise, false. - - - - - Determines whether the specified type is static. - - The type. - - true if the specified type is static; otherwise, false. - - - - - Determines if a class is a test class. - - The type to be inspected - True if the type is a test class; false, otherwise - - - - Attribute that is applied to a method to indicate that it is a fact that should be run - by the test runner. It can also be extended to support a customized definition of a - test method. - - - - - Creates instances of which represent individual intended - invocations of the test method. - - The method under test - An enumerator through the desired test method invocations - - - - Enumerates the test commands represented by this test method. Derived classes should - override this method to return instances of , one per execution - of a test method. - - The test method - The test commands which will execute the test runs for the given method - - - - Gets the name of the test to be used when the test is skipped. Defaults to - null, which will cause the fully qualified test name to be used. - - - - - Marks the test so that it will not be run, and gets or sets the skip reason - - - - - Marks the test as failing if it does not finish running within the given time - period, in milliseconds; set to 0 or less to indicate the method has no timeout - - - - - Exception thrown when code unexpectedly fails to throw an exception. - - - - - Creates a new instance of the class. Call this constructor - when no exception was thrown. - - The type of the exception that was expected - - - - Creates a new instance of the class. Call this constructor - when an exception of the wrong type was thrown. - - The type of the exception that was expected - The actual exception that was thrown - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a test method exceeds the given timeout value - - - - - Creates a new instance of the class. - - The timeout value, in milliseconds - - - - Exception thrown when a value is unexpectedly false. - - - - - Creates a new instance of the class. - - The user message to be displayed, or null for the default message - - - + + + + xunit + + + + + Contains various static methods that are used to verify that conditions are met during the + process of running tests. + + + + + Initializes a new instance of the class. + + + + + Verifies that a collection contains a given object. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + Thrown when the object is not present in the collection + + + + Verifies that a collection contains a given object, using a comparer. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is not present in the collection + + + + Verifies that a string contains a given sub-string, using the current culture. + + The sub-string expected to be in the string + The string to be inspected + Thrown when the sub-string is not present inside the string + + + + Verifies that a string contains a given sub-string, using the given comparison type. + + The sub-string expected to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is not present inside the string + + + + Verifies that a collection does not contain a given object. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + Thrown when the object is present inside the container + + + + Verifies that a collection does not contain a given object, using a comparer. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is present inside the container + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + Thrown when the sub-string is present inside the string + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is present inside the given string + + + + Verifies that a block of code does not throw any exceptions. + + A delegate to the code to be tested + + + + Verifies that a collection is empty. + + The collection to be inspected + Thrown when the collection is null + Thrown when the collection is not empty + + + + Verifies that two objects are equal, using a default comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + Thrown when the objects are not equal + + + + Verifies that two objects are equal, using a custom comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + The comparer used to compare the two objects + Thrown when the objects are not equal + + + Do not call this method. + + + + Verifies that the condition is false. + + The condition to be tested + Thrown if the condition is not false + + + + Verifies that the condition is false. + + The condition to be tested + The message to show when the condition is not false + Thrown if the condition is not false + + + + Verifies that a value is within a given range. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is not in the given range + + + + Verifies that a value is within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is not in the given range + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that a collection is not empty. + + The collection to be inspected + Thrown when a null collection is passed + Thrown when the collection is empty + + + + Verifies that two objects are not equal, using a default comparer. + + The type of the objects to be compared + The expected object + The actual object + Thrown when the objects are equal + + + + Verifies that two objects are not equal, using a custom comparer. + + The type of the objects to be compared + The expected object + The actual object + The comparer used to examine the objects + Thrown when the objects are equal + + + + Verifies that a value is not within a given range, using the default comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is in the given range + + + + Verifies that a value is not within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is in the given range + + + + Verifies that an object reference is not null. + + The object to be validated + Thrown when the object is not null + + + + Verifies that two objects are not the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are the same instance + + + + Verifies that an object reference is null. + + The object to be inspected + Thrown when the object reference is not null + + + + Verifies that two objects are the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are not the same instance + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that an expression is true. + + The condition to be inspected + Thrown when the condition is false + + + + Verifies that an expression is true. + + The condition to be inspected + The message to be shown when the condition is false + Thrown when the condition is false + + + + Used by the Throws and DoesNotThrow methods. + + + + + Captures standard output and standard error, and inserts the values into the + as it traverses the chain. + + + + + Base class used by commands which delegate to inner commands. + + + + + Interface which represents the ability to invoke of a test method. + + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Creates the start XML to be sent to the callback when the test is about to start + running. + + Return the of the start node, or null if the test + is known that it will not be running. + + + + Gets the display name of the test method. + + + + + Determines if the test runner infrastructure should create a new instance of the + test class before running the test. + + + + + Creates a new instance of the class. + + The inner command to delegate to. + + + + + + + + + + + + + + + + + + + Initializes a new instance of the class. + + The inner command + + + + + + + Base class for exceptions that have actual and expected values + + + + + The base assert exception class + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class. + + The user message to be displayed + + + + Initializes a new instance of the class. + + The user message to be displayed + The inner exception + + + + Initializes a new instance of the class. + + The user message to be displayed + The stack trace to be displayed + + + + Filters the stack trace to remove all lines that occur within the testing framework. + + The original stack trace + The filtered stack trace + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Gets the user message + + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + Set to true to skip the check for difference position + + + + Gets the actual value. + + + + + Gets the expected value. + + + + + Gets a message that describes the current exception. Includes the expected and actual values. + + The error message that explains the reason for the exception, or an empty string(""). + 1 + + + + Exception thrown when a collection unexpectedly does not contain the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. + Version-resilient runners should link against xunit.runner.utility.dll and use + ExecutorWrapper instead. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Exception thrown when the value is unexpectedly not of the given type or a derived type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Allows the user to record actions for a test. + + + + + Records any exception which is thrown by the given code. + + The code which may thrown an exception. + Returns the exception that was thrown by the code; null, otherwise. + + + + Exception that is thrown when one or more exceptions are thrown from + the After method of a . + + + + + Initializes a new instance of the class. + + The exceptions. + + + + Initializes a new instance of the class. + + The exceptions. + + + + Gets the list of exceptions thrown in the After method. + + + + + Gets a message that describes the current exception. + + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + + + + Implementation of which executes the + instances attached to a test method. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Wraps any exceptions thrown by the command execution. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Guard class, used for guard clauses and argument validation + + + + + + + + + + + + + + Base class which contains XML manipulation helper methods + + + + + Interface that represents a single test result. + + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + The amount of time spent in execution + + + + + Adds the test execution time to the XML node. + + The XML node. + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + The amount of time spent in execution + + + + + Utility methods for dealing with exceptions. + + + + + Gets the message for the exception, including any inner exception messages. + + The exception + The formatted message + + + + Gets the stack trace for the exception, including any inner exceptions. + + The exception + The formatted stack trace + + + + Rethrows an exception object without losing the existing stack trace information + + The exception to re-throw. + + For more information on this technique, see + http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx + + + + + XML utility methods + + + + + Adds an attribute to an XML node. + + The XML node. + The attribute name. + The attribute value. + + + + Adds a CDATA section to an XML node. + + The XML node. + The text for the CDATA section. + + + + Adds a child element to an XML node. + + The parent XML node. + The child element name. + The new child XML element. + + + + Exception that is thrown when a call to Debug.Assert() fails. + + + + + Creates a new instance of the class. + + The original assert message + + + + Creates a new instance of the class. + + The original assert message + The original assert detailed message + + + + Gets the original assert detailed message. + + + + + Gets the original assert message. + + + + + Gets a message that describes the current exception. + + + + + Exception thrown when a collection unexpectedly contains the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Exception thrown when code unexpectedly throws an exception. + + + + + Creates a new instance of the class. + + Actual exception + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a collection is unexpectedly not empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly not equal. + + + + + Creates a new instance of the class. + + The expected object value + The actual object value + + + + Exception thrown when a value is unexpectedly true. + + + + + Creates a new instance of the class. + + The user message to be display, or null for the default message + + + + Exception thrown when a value is unexpectedly not in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Exception thrown when the value is unexpectedly of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Exception thrown when the value is unexpectedly not of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Used to decorate xUnit.net test classes that utilize fixture classes. + An instance of the fixture data is initialized just before the first + test in the class is run, and if it implements IDisposable, is disposed + after the last test in the class is run. + + The type of the fixture + + + + Called on the test class just before each test method is run, + passing the fixture data so that it can be used for the test. + All test runs share the same instance of fixture data. + + The fixture data + + + + Exception thrown when a value is unexpectedly in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Base attribute which indicates a test method interception (allows code to be run before and + after the test is run). + + + + + This method is called after the test method is executed. + + The method under test + + + + This method is called before the test method is executed. + + The method under test + + + + Exception thrown when a collection is unexpectedly empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly equal. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object is unexpectedly null. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpected the same instance. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object reference is unexpectedly not null. + + + + + Creates a new instance of the class. + + + + + + Command that automatically creates the instance of the test class + and disposes it (if it implements ). + + + + + Creates a new instance of the object. + + The command that is bring wrapped + The method under test + + + + Executes the test method. Creates a new instance of the class + under tests and passes it to the inner command. Also catches + any exceptions and converts them into s. + + The instance of the test class + Returns information about the test run + + + + A command wrapper which catches Trace.Assert and Debug.Assert failures and turns + them into assertion exceptions. + + + + + Creates a new instance of the class. + + The command that will be wrapped. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Command used to wrap a which has associated + fixture data. + + + + + Creates a new instance of the class. + + The inner command + The fixtures to be set on the test class + + + + Sets the fixtures on the test class by calling SetFixture, then + calls the inner command. + + The instance of the test class + Returns information about the test run + + + + A timer class used to figure out how long tests take to run. On most .NET implementations + this will use the class because it's a high + resolution timer; however, on Silverlight/CoreCLR, it will use + (which will provide lower resolution results). + + + + + Creates a new instance of the class. + + + + + Starts timing. + + + + + Stops timing. + + + + + Gets how long the timer ran, in milliseconds. In order for this to be valid, + both and must have been called. + + + + + Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). + + + + + Creates a new instance of the class. + + The trait name + The trait value + + + + Gets the trait name. + + + + + Gets the trait value. + + + + + Runner that executes an synchronously. + + + + + Execute the . + + The test class command to execute + The methods to execute; if null or empty, all methods will be executed + The start run callback + The end run result callback + A with the results of the test run + + + + Factory for objects, based on the type under test. + + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Represents an xUnit.net test class + + + + + Interface which describes the ability to executes all the tests in a test class. + + + + + Allows the test class command to choose the next test to be run from the list of + tests that have not yet been run, thereby allowing it to choose the run order. + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the type that is being tested + + + + + Creates a new instance of the class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The type under test + + + + Chooses the next test to run, randomly, using the . + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the randomizer used to determine the order in which tests are run. + + + + + Sets the type that is being tested + + + + + Implementation of that represents a skipped test. + + + + + Represents an xUnit.net test command. + + + + + The method under test. + + + + + Initializes a new instance of the class. + + The method under test. + + + + Initializes a new instance of the class. + + The method under test. + The display name of the test. + + + + + + + + + + + + + Gets the name of the method under test. + + + + + Gets the name of the type under test. + + + + + + + + Creates a new instance of the class. + + The method that is being skipped + The display name for the test. If null, the fully qualified + type name is used. + + + + + + + + + + + + + Factory for creating objects. + + + + + Make instances of objects for the given class and method. + + The class command + The method under test + The set of objects + + + + A command wrapper which times the running of a command. + + + + + Creates a new instance of the class. + + The command that will be timed. + + + + Executes the inner test method, gathering the amount of time it takes to run. + + Returns information about the test run + + + + Wraps a command which should fail if it runs longer than the given timeout value. + + + + + Creates a new instance of the class. + + The command to be run + The timout, in milliseconds + The method under test + + + + Executes the test method, failing if it takes too long. + + Returns information about the test run + + + + Gets the timeout value, in milliseconds. + + + + + Attributes used to decorate a test fixture that is run with an alternate test runner. + The test runner must implement the interface. + + + + + Creates a new instance of the class. + + The class which implements ITestClassCommand and acts as the runner + for the test fixture. + + + + Gets the test class command. + + + + + Exception thrown when two object references are unexpectedly not the same instance. + + + + + Creates a new instance of the class. + + The expected object reference + The actual object reference + + + + Contains the test results from an assembly. + + + + + Contains multiple test results, representing them as a composite test result. + + + + + Adds a test result to the composite test result list. + + + + + + Gets the test results. + + + + + Creates a new instance of the class. + + The filename of the assembly + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the directory where the assembly resides. + + + + + Gets the number of failed results. + + + + + Gets the fully qualified filename of the assembly. + + + + + Gets the number of passed results. + + + + + Gets the number of skipped results. + + + + + Contains the test results from a test class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The simple name of the type under test + The fully qualified name of the type under test + The namespace of the type under test + + + + Sets the exception thrown by the test fixture. + + The thrown exception + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the fully qualified test fixture exception type, when an exception has occurred. + + + + + Gets the number of tests which failed. + + + + + Gets the fully qualified name of the type under test. + + + + + Gets the test fixture exception message, when an exception has occurred. + + + + + Gets the simple name of the type under test. + + + + + Gets the namespace of the type under test. + + + + + Gets the number of tests which passed. + + + + + Gets the number of tests which were skipped. + + + + + Gets the test fixture exception stack trace, when an exception has occurred. + + + + + Represents a failed test result. + + + + + Represents the results from running a test method + + + + + Initializes a new instance of the class. The traits for + the test method are discovered using reflection. + + The method under test. + The display name for the test. If null, the fully qualified + type name is used. + + + + Initializes a new instance of the class. + + The name of the method under test. + The type of the method under test. + The display name for the test. If null, the fully qualified + type name is used. + The traits. + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets or sets the display name of the method under test. This is the value that's shown + during failures and in the resulting output XML. + + + + + Gets the name of the method under test. + + + + + Gets or sets the standard output/standard error from the test that was captured + while the test was running. + + + + + Gets the traits attached to the test method. + + + + + Gets the name of the type under test. + + + + + Creates a new instance of the class. + + The method under test + The exception throw by the test + The display name for the test. If null, the fully qualified + type name is used. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name of the test + The custom properties attached to the test method + The full type name of the exception throw + The exception message + The exception stack trace + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the exception type thrown by the test method. + + + + + Gets the exception message thrown by the test method. + + + + + Gets the stack trace of the exception thrown by the test method. + + + + + Represents a passing test result. + + + + + Create a new instance of the class. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + + + + Create a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The custom properties attached to the test method + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Represents a skipped test result. + + + + + Creates a new instance of the class. Uses reflection to discover + the skip reason. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The traits attached to the method under test + The skip reason + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the skip reason. + + + + + Represents information about an attribute. + + + + + Gets the instance of the attribute, if available. + + The type of the attribute + The instance of the attribute, if available. + + + + Gets an initialized property value of the attribute. + + The type of the property + The name of the property + The property value + + + + Represents information about a method. + + + + + Gets all the custom attributes for the method that are of the given type. + + The type of the attribute + The matching attributes that decorate the method + + + + Determines if the method has at least one instance of the given attribute type. + + The type of the attribute + True if the method has at least one instance of the given attribute type; false, otherwise + + + + Gets the fully qualified type name of the type that this method belongs to. + + + + + Gets a value indicating whether the method is abstract. + + + + + Gets a value indicating whether the method is static. + + + + + Gets the underlying for the method, if available. + + + + + Gets the name of the method. + + + + + Gets the fully qualified type name of the return type. + + + + + Represents information about a type. + + + + + Gets all the custom attributes for the type that are of the given attribute type. + + The type of the attribute + The matching attributes that decorate the type + + + + Gets all the methods + + + + + + Determines if the type has at least one instance of the given attribute type. + + The type of the attribute + True if the type has at least one instance of the given attribute type; false, otherwise + + + + Determines if the type implements the given interface. + + The type of the interface + True if the type implements the given interface; false, otherwise + + + + Gets a value indicating whether the type is abstract. + + + + + Gets a value indicating whether the type is sealed. + + + + + Gets the underlying object, if available. + + + + + Utility class which inspects methods for test information + + + + + Gets the skip reason from a test method. + + The method to be inspected + The skip reason + + + + Gets the test commands for a test method. + + The method to be inspected + The objects for the test method + + + + Gets the timeout value for a test method. + + The method to be inspected + The timeout, in milliseconds + + + + Gets the traits on a test method. + + The method to be inspected + A dictionary of the traits + + + + Determines whether a test method has a timeout. + + The method to be inspected + True if the method has a timeout; false, otherwise + + + + Determines whether a test method has traits. + + The method to be inspected + True if the method has traits; false, otherwise + + + + Determines whether a test method should be skipped. + + The method to be inspected + True if the method should be skipped; false, otherwise + + + + Determines whether a method is a test method. A test method must be decorated + with the (or derived class) and must not be abstract. + + The method to be inspected + True if the method is a test method; false, otherwise + + + + Wrapper to implement and using reflection. + + + + + Converts an into an using reflection. + + + + + + + Converts a into an using reflection. + + The method to wrap + The wrapper + + + + Converts a into an using reflection. + + The type to wrap + The wrapper + + + + Utility class which inspects types for test information + + + + + Determines if a type contains any test methods + + The type to be inspected + True if the class contains any test methods; false, otherwise + + + + Retrieves the type to run the test class with from the , if present. + + The type to be inspected + The type of the test class runner, if present; null, otherwise + + + + Retrieves a list of the test methods from the test class. + + The type to be inspected + The test methods + + + + Determines if the test class has a applied to it. + + The type to be inspected + True if the test class has a run with attribute; false, otherwise + + + + Determines if the type implements . + + The type to be inspected + True if the type implements ; false, otherwise + + + + Determines whether the specified type is abstract. + + The type. + + true if the specified type is abstract; otherwise, false. + + + + + Determines whether the specified type is static. + + The type. + + true if the specified type is static; otherwise, false. + + + + + Determines if a class is a test class. + + The type to be inspected + True if the type is a test class; false, otherwise + + + + Attribute that is applied to a method to indicate that it is a fact that should be run + by the test runner. It can also be extended to support a customized definition of a + test method. + + + + + Creates instances of which represent individual intended + invocations of the test method. + + The method under test + An enumerator through the desired test method invocations + + + + Enumerates the test commands represented by this test method. Derived classes should + override this method to return instances of , one per execution + of a test method. + + The test method + The test commands which will execute the test runs for the given method + + + + Gets the name of the test to be used when the test is skipped. Defaults to + null, which will cause the fully qualified test name to be used. + + + + + Marks the test so that it will not be run, and gets or sets the skip reason + + + + + Marks the test as failing if it does not finish running within the given time + period, in milliseconds; set to 0 or less to indicate the method has no timeout + + + + + Exception thrown when code unexpectedly fails to throw an exception. + + + + + Creates a new instance of the class. Call this constructor + when no exception was thrown. + + The type of the exception that was expected + + + + Creates a new instance of the class. Call this constructor + when an exception of the wrong type was thrown. + + The type of the exception that was expected + The actual exception that was thrown + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a test method exceeds the given timeout value + + + + + Creates a new instance of the class. + + The timeout value, in milliseconds + + + + Exception thrown when a value is unexpectedly false. + + + + + Creates a new instance of the class. + + The user message to be displayed, or null for the default message + + +