I have determined that the following works:
I have two questions regarding the previous code:
public class TestCase1{ static TestCase1() { Mock.Replace<FileInfo, bool>(x => x.Exists).In<TestCase1>(); } [Theory] [InlineData(false)] [InlineData(true)] public void MockedFileExists(bool expected) { FileInfo file = Helper.GetMockedFile(expected); bool actual = file.Exists; Assert.Equal(expected, actual); }}public class TestCase2{ static TestCase2() { Mock.Replace<FileInfo, bool>(x => x.Exists).In<TestCase2>(); } [Theory] [InlineData(false)] [InlineData(true)] public void MockedFileExists(bool expected) { FileInfo file = Helper.GetMockedFile(expected); bool actual = file.Exists; Assert.Equal(expected, actual); }}public class Helper{ public static FileInfo GetMockedFile(bool exists) { FileInfo file = Mock.Create<FileInfo>("c:\\test.jpg"); Mock.Arrange(() => file.Exists).Returns(exists); return file; }}I have two questions regarding the previous code:
- Is there a way I can specify the Mock.Replace once and not have to specify it in every code file I use the helper method?
- WIth this approach I have to add a Mock.Replace method for each method that I want to mock. in cases where I am mocking multiple method calls is there a way to avoid having to specify a Mock.Replace for each method?
