Skip to content

Instantly share code, notes, and snippets.

@jacobduijzer
Created April 4, 2019 19:23
Show Gist options
  • Select an option

  • Save jacobduijzer/7e47025b667fdfdd5292fdcdb51ae650 to your computer and use it in GitHub Desktop.

Select an option

Save jacobduijzer/7e47025b667fdfdd5292fdcdb51ae650 to your computer and use it in GitHub Desktop.
Full example code for MockSequence
namespace Spielerei.App.SomeHandler
{
public class SomeNewDataHandler
{
private readonly ISomeService _someService;
public SomeNewDataHandler(ISomeService someService) =>
_someService = someService;
public void Handle()
{
_someService.DoThingOne();
_someService.DoThingTwo();
}
}
public interface ISomeService
{
void DoThingOne();
void DoThingTwo();
}
public class SomeService : ISomeService
{
public void DoThingOne()
{
// Do Thing One
}
public void DoThingTwo()
{
// Do Thing Two
}
}
}
using Moq;
using Spielerei.App.SomeHandler;
using Xunit;
namespace Spielerei.Tests.SomeHandler
{
public class SomeNewDataHandlerShould
{
private readonly Mock<ISomeService> _mockSomeService;
public SomeNewDataHandlerShould()
{
var mockSequence = new MockSequence();
_mockSomeService = new Mock<ISomeService>(MockBehavior.Strict);
_mockSomeService
.InSequence(mockSequence)
.Setup(x => x.DoThingOne())
.Verifiable();
_mockSomeService
.InSequence(mockSequence)
.Setup(x => x.DoThingTwo())
.Verifiable();
}
[Fact]
public void RunInSequence() =>
new SomeNewDataHandler(_mockSomeService.Object).Handle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment