this question has been ask here before, but I do not see how the answer is of any use in this case.
I want to test a method where I have something like this:
(SPWeb web = site.OpenWeb())
At this time the URL does not exist.
In the test case I create a mock for SPSite and SPWeb (SharePoint objects).
var spSite = Mock.Create<SPSite>();
var spWeb = Mock.Create<SPWeb>();
Mock.Arrange(() => spSite.OpenWeb()).Returns(spWeb);
But I get this exception in the mehtod under test when the new SPSite is created:
System.IO.FileNotFoundException: The Web application at http://someUrl could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
How can I use the mock spSite when new SPSite("http://someURL")) is called?
IgnoreInstance only swaps method calls and does not work with constructor calls. (?)