|
From: <joe...@us...> - 2003-02-27 22:45:54
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv30577/test/NMock
Added Files:
FastErrorHandlingTest.cs
Log Message:
Added support for faster error handling (thanks to Jeremy Stell Smith for the failing test, Jim Arnold for implementing it and to Paul Hammant and Martin Fowler for keeping us company)
--- NEW FILE: FastErrorHandlingTest.cs ---
using NUnit.Framework;
using System;
namespace NMock
{
/// <summary>
/// looking at the code, I think fixing this for one case (SetupResult or Expect)
/// should fix it in all places (at least that's the intent)
///
/// I didn't use ExpectException because I wanted to specify the error message
/// </summary>
[TestFixture]
public class FastErrorHandlingTest : Assertion
{
public class Empty
{
}
public class Full
{
public virtual string Foo()
{
return "foo";
}
public string Bar(string s)
{
return "bar";
}
}
private IMock empty;
private IMock full;
[SetUp]
public void SetUp()
{
empty = new DynamicMock(typeof(Empty));
full = new DynamicMock(typeof(Full));
}
[Test]
public void SetupResultWithNoMethod()
{
try
{
empty.Expect("Foo");
Fail();
}
catch (MissingMethodException e)
{
AssertEquals("method <Foo> not defined", e.Message);
}
}
[Test]
public void SetupResultWithWrongType()
{
try
{
full.SetupResult("Foo", true);
Fail();
}
catch (ArgumentException e)
{
AssertEquals("method <Foo> returns a System.String", e.Message);
}
}
/// <summary>
/// this is HUGE, I keep trying to mock non-virtual methods and wasting tons
/// of time trying to figure
/// out why my tests are working :)
/// </summary>
[Test]
public void MethodNotVirtual()
{
try
{
full.Expect("Bar");
Fail();
}
catch(ArgumentException e)
{
AssertEquals("method <Bar> is not virtual", e.Message);
}
}
[Test]
[ExpectedException(typeof(ArgumentException))]
[Ignore("Borked... tired want to commit and go home")]
public void ArgExceptionThrowOnExpectAndReturn()
{
full.ExpectAndReturn("xxx", null);
}
}
}
|