Mocking the DTE and child properties
Below I have created mocks for my dte objects so that I can test some extension methods:
The italicized arranges above work as I expect them to but when it comes time for testing the Solution object in the extensions class the solution instance is always assigned to null. If I stop in the immediate window and type Dte.Solution, I can see the proxy object as expected. But, when the solution variable is set in the below code the it is always set to null.
The only other clues that I have found are that I get this error when I try to access the ActiveProject() from the proxy object:
'EnvDTE.Solution' does not contain a definition for 'ActiveProject' and the best extension method overload 'Ellevate.T4Razor.Model.VisualStudioExtensions.SolutionExtensions.ActiveProject(EnvDTE.Solution)' has some invalid arguments
Below I have created mocks for my dte objects so that I can test some extension methods:
var Dte = Mock.Create<
DTE
>();
var activeProject = Mock.Create<
Project
>();
var solution = Mock.Create<
Solution
>();
Mock.SetupStatic(typeof(RazorTemplateExtensions));
Mock.Arrange(() => Dte.Solution).Returns(solution);
Mock.Arrange(() => RazorTemplateExtensions.Dte).Returns(Dte);
Mock.Arrange(() => Solution.FileName).Returns("SolutionNameTest");
Mock.Arrange(() => ActiveProject.RootNamespace()).Returns("DefaultNamespace");
Mock.Arrange(() => Solution.ActiveProject()).Returns(ActiveProject);
The italicized arranges above work as I expect them to but when it comes time for testing the Solution object in the extensions class the solution instance is always assigned to null. If I stop in the immediate window and type Dte.Solution, I can see the proxy object as expected. But, when the solution variable is set in the below code the it is always set to null.
public static String DirectoryPath(this RazorTemplate razorTemplate)
{
var solution = Dte.Solution;
// while breaking here this solution is null
// In the immediate window the Dte.Solution returns proxy object.
...
}
The only other clues that I have found are that I get this error when I try to access the ActiveProject() from the proxy object:
'EnvDTE.Solution' does not contain a definition for 'ActiveProject' and the best extension method overload 'Ellevate.T4Razor.Model.VisualStudioExtensions.SolutionExtensions.ActiveProject(EnvDTE.Solution)' has some invalid arguments