Resolve issue 237 by wrapping method callsin try finally.

This commit is contained in:
Matthew Malkin 2016-07-04 11:42:59 +01:00
Родитель 2414954ebe
Коммит e8cf9c178b
4 изменённых файлов: 121 добавлений и 4 удалений

Просмотреть файл

@ -0,0 +1,81 @@
using System;
using NUnit.Framework;
namespace NSubstitute.Acceptance.Specs.FieldReports
{
public class Issue237_ReceivedInOrderErrorHandling
{
public interface IAmAnInterface
{
void MethodA(int a, int b);
void MethodB(int a, int b);
int MethodC();
}
[Test]
[ExpectedException(typeof(Exception))]
public void AnExceptionIsReceivedWhenExpected()
{
Received.InOrder(() =>
{
throw new Exception("An Exception!");
});
}
[Test]
public void MethodCallsAreReceivedInOrder()
{
IAmAnInterface _interface = Substitute.For<IAmAnInterface>();
_interface.MethodA(1, 2);
_interface.MethodB(1, 2);
Received.InOrder(() =>
{
_interface.MethodA(1, 2);
_interface.MethodB(1, 2);
});
}
[Test]
public void MethodCallsAreReceivedInOrder2()
{
IAmAnInterface _interface = Substitute.For<IAmAnInterface>();
_interface.MethodA(1, 2);
_interface.MethodB(1, 2);
Received.InOrder(() =>
{
_interface.MethodA(1, 2);
_interface.MethodB(1, 2);
});
}
[Test]
public void AfterTheFailingTestIsRunWhenTheSuccessfulTestIsRunTheSuccessfulTestShouldSucceed()
{
try
{
AnExceptionIsReceivedWhenExpected();
}
catch (Exception)
{
// suppress exception from first test
}
MethodCallsAreReceivedInOrder();
}
[Test]
public void AfterTheFailingTestIsRunIShouldBeAbleToConfigureASubstitute()
{
try
{
AnExceptionIsReceivedWhenExpected();
}
catch (Exception)
{
// suppress failure of test A
}
var foo = Substitute.For<IAmAnInterface>();
foo.MethodC().Returns(1);
}
}
}

Просмотреть файл

@ -102,6 +102,7 @@
<Compile Include="FieldReports\Issue129_AmbiguousArgsWithOutRef.cs" />
<Compile Include="FieldReports\Issue149_ArgMatcherInReturns.cs" />
<Compile Include="FieldReports\Issue170_MultidimensionalArray.cs" />
<Compile Include="FieldReports\Issue237_ReceivedInOrderErrorHandling.cs" />
<Compile Include="FieldReports\Issue211_ReceivedInOrderParamsFormatting.cs" />
<Compile Include="FieldReports\Issue75_DoesNotWorkWithMembersThatUseDynamic.cs" />
<Compile Include="FieldReports\Issue_RaiseEventOnNonSubstitute.cs" />

Просмотреть файл

@ -167,7 +167,6 @@ namespace NSubstitute.Acceptance.Specs
});
}
[Test]
public void Check_auto_subbed_props()
{
@ -259,6 +258,36 @@ namespace NSubstitute.Acceptance.Specs
});
}
[Test]
public void Pass_when_exception_in_first_sequenced_call_is_caught_and_second_call_is_exact()
{
try
{
Received.InOrder(() =>
{
throw new Exception("An Exception!");
});
}
catch (Exception)
{
//suppress error
}
_foo.Start(2);
_bar.Begin();
_foo.Finish();
_bar.End();
Received.InOrder(() =>
{
_foo.Start(2);
_bar.Begin();
_foo.Finish();
_bar.End();
});
}
[SetUp]
public void SetUp()
{

Просмотреть файл

@ -115,8 +115,14 @@ namespace NSubstitute.Core
{
var query = new Query();
_currentQuery.Value = query;
try
{
calls();
}
finally
{
_currentQuery.Value = null;
}
return query.Result();
}
}