Last active
August 29, 2015 14:05
-
-
Save jltrem/c5d94b637d2d8e0da88f to your computer and use it in GitHub Desktop.
checking that a method was called with xunit & moq
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; | |
using Xunit; | |
using Moq; | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
} | |
public interface IScratch | |
{ | |
void ScratchMe(); | |
} | |
public class Scratcher | |
{ | |
private readonly IScratch _scratch; | |
public Scratcher(IScratch scratch) | |
{ | |
_scratch = scratch; | |
} | |
public void DoIt() | |
{ | |
_scratch.ScratchMe(); | |
} | |
} | |
[Fact] | |
public void TestMethodWasCalled() | |
{ | |
var scratch = new Mock<IScratch>(); | |
var scratcher = new Scratcher(scratch.Object); | |
scratcher.DoIt(); | |
scratch.Verify(x => x.ScratchMe(), Times.AtLeastOnce); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment