I'm creating some UnitTests and want to mock a service which returns a Thing object with a FileInformation property that implements a IFileInformation interface.
How do I fill in / mock the Thing without writing a implementation for this interface?
public interface IFileInformation
{
string Name { get; set; }
}
public class Thing
{
public IFileInformation FileInformation { get; set; }
}
I'm using Moq lib for my UnitTests.
Ok, it was easier than I thought.
Using Moq to mock the interface.
Mock<IFileInformation> fileInformation = new Mock<IFileInformation>();
fileInformation.SetupGet(x => x.Name).Returns("whatever.txt");
Thing serviceResult = new Thing();
serviceResult.FileInformation = fileInformation.Object;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With