Update of /cvsroot/nmock/nmock2/src/NMock2.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24181/src/NMock2.Test Added Files: NMock2.Test.csproj NamedObject.cs AssertDescription.cs VerifyTest.cs .cvsignore AssemblyInfo.cs MockeryTest.cs Log Message: first upload of nmock2 --- NEW FILE: VerifyTest.cs --- using NMock2.Internal; using NUnit.Framework; namespace NMock2.Test { [TestFixture] public class VerifyTest { [Test] public void VerifyThatPassesIfMatcherMatchesValue() { object value = new NamedObject("value"); Verify.That(value, Is.Same(value)); } [Test] public void VerifyThatFailsIfMatcherDoesNotMatchValue() { object expected = new NamedObject("expected"); object actual = new NamedObject("actual"); Matcher matcher = Is.Same(expected); try { Verify.That(actual, matcher); } catch (ExpectationException e) { Assert.AreEqual( System.Environment.NewLine + "Expected: "+matcher.ToString()+System.Environment.NewLine + "Actual: <"+actual.ToString()+">", e.Message); return; } Assert.Fail("Verify.That should have failed"); } [Test] public void CanPrependCustomMessageToDescriptionOfFailure() { object expected = new NamedObject("expected"); object actual = new NamedObject("actual"); Matcher matcher = Is.Same(expected); try { Verify.That(actual, matcher, "message {0} {1}", "0", 1); } catch (ExpectationException e) { Assert.AreEqual( "message 0 1" + System.Environment.NewLine + "Expected: "+matcher.ToString()+ System.Environment.NewLine + "Actual: <"+actual.ToString()+">", e.Message); return; } Assert.Fail("Verify.That should have failed"); } } } --- NEW FILE: NamedObject.cs --- using System; namespace NMock2.Test { public class NamedObject : ICloneable { private readonly string id; private readonly int cloneId; public NamedObject(string id) : this(id, 0) { } public NamedObject(string id, int cloneId) { this.id = id; this.cloneId = cloneId; } public override string ToString() { return id + (cloneId > 0 ? " (clone " + cloneId + ")" : ""); } public object Clone() { return new NamedObject(id, cloneId+1); } } } --- NEW FILE: AssertDescription.cs --- using System; using System.IO; using NUnit.Framework; using NMock2.Internal; namespace NMock2.Test { public abstract class AssertDescription { public static void IsEqual(ISelfDescribing selfDescribing, string expectedDescription) { Assert.AreEqual(expectedDescription, DescriptionOf(selfDescribing), "description"); } private static string DescriptionOf(ISelfDescribing selfDescribing) { TextWriter writer = new DescriptionWriter(); selfDescribing.DescribeTo(writer); return writer.ToString(); } public static void IsComposed(ISelfDescribing selfDescribing, string format, params ISelfDescribing[] components) { string[] componentDescriptions = new string[components.Length]; for (int i = 0; i < components.Length; i++) { componentDescriptions[i] = DescriptionOf(components[i]); } AssertDescription.IsEqual(selfDescribing, String.Format(format, componentDescriptions)); } } } --- NEW FILE: MockeryTest.cs --- using System; using System.IO; using System.Reflection; using NUnit.Framework; using NMock2.Internal; using NMock2.Monitoring; namespace NMock2.Test { [TestFixture] public class MockeryTest { public interface IMockedType { void DoStuff(); } public interface InterfaceWithoutIPrefix { } public interface ARSEIInterfaceWithAdditionalPrefixBeforeI { } public interface INTERFACE_WITH_UPPER_CLASS_NAME { } private Mockery mockery; [SetUp] public void SetUp() { mockery = new Mockery(); } [Test] public void CreatesMocksThatCanBeCastToMockedType() { object mock = mockery.NewMock(typeof (IMockedType)); Assert.IsTrue(mock is IMockedType, "should be instance of mocked type"); } [Test] public void CreatesMocksThatCanBeCastToIMockObject() { object mock = mockery.NewMock(typeof (IMockedType)); Assert.IsTrue(mock is IMockObject, "should be instance of IMock"); } [Test] public void MockReturnsNameFromToString() { object mock = mockery.NewMock(typeof (IMockedType), "mock"); Assert.AreEqual("mock", mock.ToString()); } [Test] public void GivesMocksDefaultNameIfNoNameSpecified() { Assert.AreEqual("mockedType", mockery.NewMock(typeof (IMockedType)).ToString()); Assert.AreEqual("interfaceWithoutIPrefix", mockery.NewMock(typeof (InterfaceWithoutIPrefix)).ToString()); Assert.AreEqual("interfaceWithAdditionalPrefixBeforeI", mockery.NewMock(typeof (ARSEIInterfaceWithAdditionalPrefixBeforeI)).ToString()); Assert.AreEqual("interface_with_upper_class_name", mockery.NewMock(typeof (INTERFACE_WITH_UPPER_CLASS_NAME)).ToString()); } [Test] public void CreatedMockComparesReferenceIdentityWithEqualsMethod() { object mock1 = mockery.NewMock(typeof (IMockedType), "mock1"); object mock2 = mockery.NewMock(typeof (IMockedType), "mock2"); Assert.IsTrue(mock1.Equals(mock1), "same object should be equal"); Assert.IsFalse(mock1.Equals(mock2), "different objects should not be equal"); } [Test] public void CreatedMockReturnsNameFromToString() { object mock1 = mockery.NewMock(typeof (IMockedType), "mock1"); object mock2 = mockery.NewMock(typeof (IMockedType), "mock2"); Assert.AreEqual("mock1", mock1.ToString(), "mock1.ToString()"); Assert.AreEqual("mock2", mock2.ToString(), "mock2.ToString()"); } [Test] public void DispatchesInvocationBySearchingForMatchingExpectationInOrderOfAddition() { IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); e2.Previous = e1; e1.ExpectedInvokedObject = e2.ExpectedInvokedObject = mock; e1.ExpectedInvokedMethod = e2.ExpectedInvokedMethod = typeof(IMockedType).GetMethod("DoStuff", new Type[0]); e1.Matches_Result = false; e2.Matches_Result = true; mock.DoStuff(); Assert.IsTrue(e1.Matches_HasBeenCalled, "should have tried to match e1"); Assert.IsFalse(e1.Perform_HasBeenCalled, "should not have performed e1"); Assert.IsTrue(e2.Matches_HasBeenCalled, "should have tried to match e2"); Assert.IsTrue(e2.Perform_HasBeenCalled, "should have performed e2"); } [Test] public void StopsSearchingForMatchingExpectationAsSoonAsOneMatches() { IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); e2.Previous = e1; e1.ExpectedInvokedObject = e2.ExpectedInvokedObject = mock; e1.ExpectedInvokedMethod = e2.ExpectedInvokedMethod = typeof(IMockedType).GetMethod("DoStuff", new Type[0]); e1.Matches_Result = true; mock.DoStuff(); Assert.IsTrue(e1.Matches_HasBeenCalled, "should have tried to match e1"); Assert.IsTrue(e1.Perform_HasBeenCalled, "should have performed e1"); Assert.IsFalse(e2.Matches_HasBeenCalled, "should not have tried to match e2"); Assert.IsFalse(e2.Perform_HasBeenCalled, "should not have performed e2"); } [Test] public void FailsTestIfNoExpectationsMatch() { IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); e1.Matches_Result = false; e2.Matches_Result = false; try { mock.DoStuff(); } catch(ExpectationException) { return; } Assert.Fail("expected ExpectationException"); } [Test] public void VerifiesThatAllExpectationsHaveBeenMet() { bool assertionFailed; IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); e1.HasBeenMet = true; e2.HasBeenMet = true; mockery.VerifyAllExpectationsHaveBeenMet(); e1.HasBeenMet = true; e2.HasBeenMet = false; try { assertionFailed = false; mockery.VerifyAllExpectationsHaveBeenMet(); } catch (ExpectationException) { assertionFailed = true; } Assert.IsTrue(assertionFailed, "should have failed when e2 was not met"); e1.HasBeenMet = false; e2.HasBeenMet = true; try { assertionFailed = false; mockery.VerifyAllExpectationsHaveBeenMet(); } catch (ExpectationException) { assertionFailed = true; } Assert.IsTrue(assertionFailed, "should have failed when e1 was not met"); } [Test] public void AssertionExceptionThrownWhenSomeExpectationsHaveNotBeenMetContainsDescriptionOfUnMetExpectations() { IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); MockExpectation e3 = new MockExpectation(); e1.Description = "e1"; e1.HasBeenMet = false; e1.IsActive = true; e2.Description = "e2"; e2.HasBeenMet = true; e2.IsActive = true; e3.Description = "e3"; e3.HasBeenMet = false; e3.IsActive = true; mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); mockObjectControl.AddExpectation(e3); try { mockery.VerifyAllExpectationsHaveBeenMet(); } catch (ExpectationException e) { string newLine = System.Environment.NewLine; Assert.AreEqual( "not all expected invocations were performed" + newLine + "Expected:" + newLine + " e1" + newLine + " e3" + newLine, e.Message); } } [Test] public void AssertionExceptionThrownWhenNoExpectationsMatchContainsDescriptionOfActiveExpectations() { IMockedType mock = (IMockedType)mockery.NewMock(typeof(IMockedType),"mock"); IMockObject mockObjectControl = (IMockObject) mock; MockExpectation e1 = new MockExpectation(); MockExpectation e2 = new MockExpectation(); MockExpectation e3 = new MockExpectation(); e1.Description = "e1"; e1.IsActive = true; e1.Matches_Result = false; e2.IsActive = false; e2.Matches_Result = false; e3.Description = "e3"; e3.IsActive = true; e3.Matches_Result = false; mockObjectControl.AddExpectation(e1); mockObjectControl.AddExpectation(e2); mockObjectControl.AddExpectation(e3); try { mock.DoStuff(); } catch (ExpectationException e) { string newLine = System.Environment.NewLine; Assert.AreEqual( "unexpected invocation of mock.DoStuff()" + newLine + "Expected:" + newLine + " e1" + newLine + " e3" + newLine, e.Message); } } } class MockExpectation : IExpectation { public object ExpectedInvokedObject = null; public MethodInfo ExpectedInvokedMethod = null; public MockExpectation Previous; public bool Matches_Result = false; public bool Matches_HasBeenCalled = false; public bool Matches(Invocation invocation) { CheckInvocation(invocation); Assert.IsTrue(Previous == null || Previous.Matches_HasBeenCalled, "called out of order"); Matches_HasBeenCalled = true; return Matches_Result; } public bool Perform_HasBeenCalled = false; public void Perform(Invocation invocation) { CheckInvocation(invocation); Assert.IsTrue(Matches_HasBeenCalled, "Matches should have been called"); Perform_HasBeenCalled = true; } public string Description = ""; public void DescribeActiveExpectationsTo(TextWriter writer) { writer.Write(Description); } public void DescribeUnmetExpectationsTo(TextWriter writer) { writer.Write(Description); } private bool isActive_Value = false; public bool IsActive { get { return isActive_Value; } set { isActive_Value = value; } } private bool hasBeenMet_Value = false; public bool HasBeenMet { get { return hasBeenMet_Value; } set { hasBeenMet_Value = value; } } private void CheckInvocation(Invocation invocation) { Assert.IsTrue(ExpectedInvokedObject == null || ExpectedInvokedObject == invocation.Receiver, "should have received invocation on expected object"); Assert.IsTrue(ExpectedInvokedMethod == null || ExpectedInvokedMethod == invocation.Method, "should have received invocation of expected method"); } } } --- NEW FILE: NMock2.Test.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{CC6D39F7-1387-401D-9303-088D39459F36}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "NMock2.Test" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "NMock2.Test" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "..\..\build\NMock2.Test\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "..\..\build\NMock2.Test\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\..\lib\nunit.framework.dll" /> <Reference Name = "NMock2" Project = "{CEE959FE-C3AF-4B51-8F1A-CCB32BAA1E98}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> </References> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssertDescription.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MockeryTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NamedObject.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "VerifyTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\ResultSynthesizerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\ReturnActionTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\ReturnCloneActionTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\SetIndexedParameterActionTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\SetNamedParameterActionTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Actions\ThrowActionTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Internal\BuildableExpectationTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Internal\DescriptionWriterTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\AlwaysMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\AndMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\ArgumentsMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\ComparisonMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\DescriptionOverrideTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\EqualMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\MatcherWithDescription.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\MethodNameMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\MockMatcher.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\NotMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\NullMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\OrMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\PropertyMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\SameMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\StringContainsMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Matchers\ToStringMatcherTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\InvocationSemanticsTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\InvocationTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\InvokerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\MethodInfoStub.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\MockInvokable.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\MultiInterfaceFactoryTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\ParameterInfoStub.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\ParameterListTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\ProxiedObjectIdentityTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Monitoring\ProxyInvokableAdapterTest.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: .cvsignore --- obj NMock2.Test.csproj.user --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] |