I'm trying to use Mocks in my Unit testing but I struggle with below code. I want to Callback from AppendName method in right way so that this method is correctly tested and mocked object name is actually changed.
public class GenericTests
{
[TestMethod]
public void TestMethod1()
{
IFile newFile = GetNewFile("Document").Object;
newFile.AppendName();
Assert.AreEqual("AppendedDocument", newFile.Name);
}
public Mock<IFile> GetNewFile(string name)
{
Mock<IFile> file = new Mock<IFile>();
file.Setup(f => f.Name).Returns(name);
file.Setup(f => f.Path).Returns(@"C:\Folder\" + name);
file.Setup(f => f.AppendName()).Callback.....problem is here.....
return file;
}
}
public interface IFile
{
string Name { get; set; }
string Path { get; set; }
void AppendName();
}
public class LocalFile : IFile
{
public string Name { get; set; }
public string Path { get; set; }
public void AppendName()
{
this.Name = "AppendedDocument";
}
}
Can someone please advice how to complete Callback for AppendName() ??? please