Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unit test class after integrating IPathWrapper with the ReallyHardToTest class
using NUnit.Framework;
using Moq;
[TestFixture]
public class ReallyHardToTestTests{
Mock<IPathWrapper> mockPathWrapper;
// We will fix this soon...
SomeOtherDependency otherDependency;
ReallyHardToTest systemUnderTest;
[SetUp]
public void SetUp(){
mockPathWrapper = new Mock<IPathWrapper>(MockBehavior.Strict);
otherDependency = new SomeOtherDependency();
systemUnderTest = new ReallyHardToTest(otherDependency, mockPathWrapper.Object);
}
[TestCase(@"c:\some\path\filename.txt", "filename.txt")]
[TestCase(@"c:\some\really\long\path\otherFile.txt", "otherFile.txt")]
public void SetFilename_Always_InvokesPathGetFileName(string input, string expectedFilename){
// Configure our mock expectations
mockPathWrapper.Setup(p=>p.GetFileName(input)).Returns(expectedFilename);
// Exercise our method under test
SystemUnderTest.SetFilename(input);
// Verify that our mock's expectations were met
mockPathWrapper.VerifyAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment