Created
April 4, 2019 19:23
-
-
Save jacobduijzer/7e47025b667fdfdd5292fdcdb51ae650 to your computer and use it in GitHub Desktop.
Full example code for MockSequence
This file contains hidden or 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
| 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 | |
| } | |
| } | |
| } |
This file contains hidden or 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 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