-
-
Save jimmymain/0b6b6398fa710b3c9e73a7d060cfd86c to your computer and use it in GitHub Desktop.
NSubstitute and Async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using NSubstitute; | |
using NUnit.Framework; | |
namespace ClassLibrary1 | |
{ | |
public interface ICalculationServiceAsync | |
{ | |
Task Calculate(); | |
} | |
public class SystemUnderTest | |
{ | |
private readonly ICalculationServiceAsync _service; | |
public SystemUnderTest(ICalculationServiceAsync service) | |
{ | |
_service = service; | |
} | |
public async void DoSomethingAsync() | |
{ | |
await _service.Calculate(); | |
} | |
} | |
[TestFixture] | |
public class AsyncTest | |
{ | |
[Test] | |
public void Can_await_on_async_mocks() | |
{ | |
var mockService = Substitute.For<ICalculationServiceAsync>(); | |
var sut = new SystemUnderTest(mockService); | |
sut.DoSomethingAsync(); | |
mockService.Calculate().ReceivedCalls(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment