Skip to content

Instantly share code, notes, and snippets.

@battleguard
Created March 1, 2016 01:55
Show Gist options
  • Save battleguard/f66109c1d8f3fa19f906 to your computer and use it in GitHub Desktop.
Save battleguard/f66109c1d8f3fa19f906 to your computer and use it in GitHub Desktop.
Showing how to mock a dependency
using System;
using Moq;
using Xunit;
public class BigMethodClass
{
private readonly IBitmapOperations _bitmapOperations;
public BigMethodClass( IBitmapOperations bitmapOperations )
{
_bitmapOperations = bitmapOperations;
}
public int BigMethod()
{
_bitmapOperations.DoBitMapStuff();
// other methods;
return 1; //return whatever part your testing
}
}
public interface IBitmapOperations
{
void DoBitMapStuff();
}
public class BigMethodClassTests
{
[Fact]
public void TestBigMethodReturns1()
{
const int expected = 1;
var bitmapOperationMoq = new Mock<IBitmapOperations>();
var testing = new BigMethodClass( bitmapOperationMoq.Object );
var actual = testing.BigMethod();
Assert.Equal( expected: expected, actual: actual );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment