src/Microsoft.VisualStudio.Editor.UnitTests/MyExtensibility/MyExtensibilitySettingsTest.cs
/// <summary>
/// Create a Project mock. Project.DTE.Solution will be a Solution3 and
/// GetProjectTemplatesWithCustomData will return the Templates mock containing the 
/// specified Template mocks.
/// </summary>
Create a Project mock. Project.DTE.Solution will be a Solution3 and
GetProjectTemplatesWithCustomData will return the Templates mock containing the
specified Template mocks.
Create a Project mock . Project . DTE . Solution will be a Solution3 and GetProjectTemplatesWithCustomData will return the Templates mock containing the specified Template mocks .
private static Mock<Project> CreateProjectMock(string projectKind, string customDataSignature, Mock<Template>[] templateMocks)
        {
            Mock<Templates> templatesMock = null; 
            if (null != templateMocks)
            {
                templatesMock = new Mock<Templates>(typeof(IEnumerable));
                templatesMock.Implement("get_Count", templateMocks.Length);
                SequenceMock<IEnumerator> templatesEnumeratorMock = new SequenceMock<IEnumerator>();
                foreach (Mock<Template> templateMock in templateMocks)
                {
                    templatesEnumeratorMock.AddExpectation("MoveNext", (bool)true);
                    templatesEnumeratorMock.AddExpectation("get_Current", (object)templateMock.Instance);
                }
                templatesEnumeratorMock.AddExpectation("MoveNext", (bool)false);
                templatesMock.Implement("GetEnumerator", (IEnumerator)templatesEnumeratorMock.Instance); 
            }
            Mock<Solution3> solution3Mock = new Mock<Solution3>(typeof(Solution));
            solution3Mock.Implement("GetProjectItemTemplates",
                new object[] { projectKind, customDataSignature }, 
                ( null==templateMocks ? null : (Templates)templatesMock.Instance));
            return CreateProjectMock(solution3Mock);
        }
private static Mock < Project > CreateProjectMock ( string projectKind , string customDataSignature , Mock < Template > [ ] templateMocks ) { Mock < Templates > templatesMock = null ; if ( null != templateMocks ) { templatesMock = new Mock < Templates > ( typeof ( IEnumerable ) ) ; templatesMock . Implement ( " " , templateMocks . Length ) ; SequenceMock < IEnumerator > templatesEnumeratorMock = new SequenceMock < IEnumerator > ( ) ; foreach ( Mock < Template > templateMock in templateMocks ) { templatesEnumeratorMock . AddExpectation ( " " , ( bool ) true ) ; templatesEnumeratorMock . AddExpectation ( " " , ( object ) templateMock . Instance ) ; } templatesEnumeratorMock . AddExpectation ( " " , ( bool ) false ) ; templatesMock . Implement ( " " , ( IEnumerator ) templatesEnumeratorMock . Instance ) ; } Mock < Solution3 > solution3Mock = new Mock < Solution3 > ( typeof ( Solution ) ) ; solution3Mock . Implement ( " " , new object [ ] { projectKind , customDataSignature } , ( null == templateMocks ? null : ( Templates ) templatesMock . Instance ) ) ; return CreateProjectMock ( solution3Mock ) ; }
Create a Project mock.
Create a Project mock .
// Mock of <Templates> // Mock of Templates.GetEnumerator // Templates.GetEnumerator implementation. // Mock of DTE.Solution // Solution.GetProjectItemTemplates implementation
projectKind
string
customDataSignature
string
templateMocks
Mock<Template>[]