Created
March 1, 2016 01:55
-
-
Save battleguard/f66109c1d8f3fa19f906 to your computer and use it in GitHub Desktop.
Showing how to mock a dependency
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 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