Skip to content

Instantly share code, notes, and snippets.

@jltrem
Last active August 29, 2015 14:05
Show Gist options
  • Save jltrem/c5d94b637d2d8e0da88f to your computer and use it in GitHub Desktop.
Save jltrem/c5d94b637d2d8e0da88f to your computer and use it in GitHub Desktop.
checking that a method was called with xunit & moq
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