本文整理汇总了C#中Mock.ImplementExpr方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.ImplementExpr方法的具体用法?C# Mock.ImplementExpr怎么用?C# Mock.ImplementExpr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.ImplementExpr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VsGetEnumeratorSelectedProjectsTest
public void VsGetEnumeratorSelectedProjectsTest()
{
ProjectCollection target = new ProjectCollection();
Mock<IEnumerable> mockEnumerable = new Mock<IEnumerable>();
Mock<IEnumerator> mockEnumerator = new Mock<IEnumerator>();
IEnumerator expected = mockEnumerator.Instance;
mockEnumerable.ImplementExpr(e => e.GetEnumerator(), expected);
target.SelectedProjects = mockEnumerable.Instance;
IEnumerator actual;
actual = target.GetEnumerator();
Assert.AreEqual(expected, actual);
}
示例2: PackageCommandSetConstructorTest
public void PackageCommandSetConstructorTest()
{
var mockActiveDocument = new Mock<Document>();
var mockDte = new Mock<DTE>();
mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
PackageCommandSet_Accessor target = new PackageCommandSet_Accessor(this.mockServiceProvider.Instance);
CommandSet_Accessor innerTarget = new PackageCommandSet_Accessor(this.mockServiceProvider.Instance);
Assert.IsNotNull(target.CommandList, "CommandList was not created.");
Assert.IsNotNull(innerTarget.ServiceProvider, "Service provider not stored by the constructor");
}
示例3: VsOutputPanePropertyTest
public void VsOutputPanePropertyTest()
{
// Setup
Mock<EnvDTE.Window> mockWindow = SetupMockWindow();
Mock<EnvDTE.OutputWindow> mockOutputWindow = new Mock<EnvDTE.OutputWindow>();
mockWindow.ImplementExpr(w => w.Object, (EnvDTE.OutputWindow)mockOutputWindow.Instance);
Mock<EnvDTE.OutputWindowPane> mockOutputWindowPane = new Mock<EnvDTE.OutputWindowPane>();
Mock<EnvDTE.OutputWindowPanes> mockOutputWindowPanes = new Mock<EnvDTE.OutputWindowPanes>();
mockOutputWindow.ImplementExpr(ow => ow.OutputWindowPanes, (EnvDTE.OutputWindowPanes)mockOutputWindowPanes.Instance);
mockOutputWindowPanes.ImplementExpr(owp => owp.Add("StyleCop"), (EnvDTE.OutputWindowPane)mockOutputWindowPane.Instance);
// Call
VSWindows_Accessor actual = VSWindows_Accessor.GetInstance(this.serviceProvider);
// Verify
Assert.IsNotNull(actual.OutputPane, "OutputPane property was null");
}
示例4: PackageCommandSetConstructorTest
public void PackageCommandSetConstructorTest()
{
var mockActiveDocument = new Mock<Document>();
var mockDte = new Mock<DTE>();
mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
PackageCommandSet target = new PackageCommandSet(this.mockServiceProvider.Instance);
CommandSet innerTarget = new PackageCommandSet(this.mockServiceProvider.Instance);
Assert.IsNotNull(typeof(PackageCommandSet).GetProperty("CommandList", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(innerTarget),
"CommandList was not created.");
Assert.IsNotNull(typeof(PackageCommandSet).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(innerTarget),
"Service provider not stored by the constructor");
}
示例5: PackageCommandSetConstructorTest
public void PackageCommandSetConstructorTest()
{
var mockActiveDocument = new Mock<Document>();
var mockDte = new Mock<DTE>();
mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
PackageCommandSet target = new PackageCommandSet(this.mockServiceProvider.Instance);
CommandSet innerTarget = new PackageCommandSet(this.mockServiceProvider.Instance);
PrivateObject packageCommandSet = new PrivateObject(target, new PrivateType(typeof(PackageCommandSet)));
PrivateObject commandSet = new PrivateObject(innerTarget, new PrivateType(typeof(CommandSet)));
Assert.IsNotNull(packageCommandSet.GetFieldOrProperty("CommandList"), "CommandList was not created.");
Assert.IsNotNull(commandSet.GetFieldOrProperty("ServiceProvider"), "Service provider not stored by the constructor");
}
示例6: SetupMockWindow
private Mock<Window> SetupMockWindow()
{
Mock<Windows> mockWindows = new Mock<Windows>();
Mock<Window> mockWindow = new Mock<Window>();
mockWindows.ImplementExpr(ws => ws.Item(EnvDTE.Constants.vsWindowKindOutput), (EnvDTE.Window)mockWindow.Instance);
this.serviceProvider.DTE.Windows = mockWindows.Instance as EnvDTE.Windows;
return mockWindow;
}
示例7: PrepareServiceProvider
private IServiceProvider PrepareServiceProvider()
{
var mock = new Mock<IServiceProvider>();
var mockSolution = new Mock<IVsSolution>();
mock.ImplementExpr(m => m.GetService(typeof(SVsSolution)), mockSolution.Instance as IVsSolution);
return mock.Instance as IServiceProvider;
}
示例8: SetupProjectUtilities
private void SetupProjectUtilities(
SequenceMock<IEnumerator> mockDocumentEnumerator,
Mock<DTE> mockDte,
Mock<Documents> mockDocuments,
SequenceMock<Document> mockDocument,
Mock<Document> mockActiveDocument,
string fileName)
{
var mockSolution = new Mock<Solution>();
var mockProjects = new Mock<Projects>();
var mockProject = new Mock<Project>();
var mockProjectEnumerator = new SequenceMock<IEnumerator>();
// var mockEvents = new Mock<EnvDTE.Events>();
mockDte.ImplementExpr(dte => dte.Solution, mockSolution.Instance);
mockDte.ImplementExpr(dte => dte.Documents, mockDocuments.Instance);
mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);
// mockDte.ImplementExpr(dte => dte.Events, mockEvents.Instance);
mockSolution.ImplementExpr(sol => sol.Projects, mockProjects.Instance);
mockProjects.ImplementExpr(e => e.GetEnumerator(), mockProjectEnumerator.Instance);
mockProjectEnumerator.AddExpectationExpr(en => en.MoveNext(), true);
mockProjectEnumerator.AddExpectationExpr(en => en.Current, mockProject.Instance);
mockProjectEnumerator.AddExpectationExpr(en => en.MoveNext(), false);
mockProject.ImplementExpr(p => p.Kind, EnvDTE.Constants.vsProjectKindMisc);
mockProject.ImplementExpr(p => p.ProjectItems, (Func<ProjectItems>)delegate { return null; });
mockDocuments.ImplementExpr(docs => docs.GetEnumerator(), mockDocumentEnumerator.Instance);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockDocument.Instance);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);
mockDocument.AddExpectationExpr(doc => doc.FullName, fileName);
}
示例9: OnNavigateToDocNotInProjectTest
public void OnNavigateToDocNotInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
var mockSecondDocument = new SequenceMock<Document>();
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockSecondDocument.Instance);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);
mockSecondDocument.AddExpectationExpr(doc => doc.FullName, "DummyFile.txt");
AnalysisHelper analysisHelper = this.SetCoreNoUI();
bool eventFired = false;
var styleCopCore = (StyleCopCore)typeof(AnalysisHelper)
.GetField("core", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(analysisHelper);
styleCopCore.OutputGenerated += (sender, args) => { eventFired = true; };
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
typeof(ProjectUtilities).GetField("serviceProvider", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, this.mockServiceProvider.Instance);
// Execute
typeof(ViolationTask).GetMethod("OnNavigate", BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(this.taskUnderTest, new object[] { EventArgs.Empty });
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
Assert.IsTrue(eventFired, "Core did not fire output event");
}
示例10: OnNavigateToDocInProjectTest
public void OnNavigateToDocInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, this.violation.File);
mockDocument.AddExpectationExpr(doc => doc.Activate());
mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<DTE>)delegate { return (EnvDTE.DTE)mockDte.Instance; });
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
typeof(ProjectUtilities).GetField("serviceProvider", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, this.mockServiceProvider.Instance);
// Execute
typeof(ViolationTask).GetMethod("OnNavigate", BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(this.taskUnderTest, new object[] { EventArgs.Empty });
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
}
示例11: OnNavigateToDocNotInProjectTest
public void OnNavigateToDocNotInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
var mockSecondDocument = new SequenceMock<Document>();
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockSecondDocument.Instance);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);
mockSecondDocument.AddExpectationExpr(doc => doc.FullName, "DummyFile.txt");
AnalysisHelper_Accessor analysisHelper = this.SetCoreNoUI();
bool eventFired = false;
analysisHelper.core.OutputGenerated += (sender, args) => { eventFired = true; };
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
ProjectUtilities_Accessor.serviceProvider = this.mockServiceProvider.Instance;
// Execute
this.taskUnderTest.OnNavigate(EventArgs.Empty);
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
Assert.IsTrue(eventFired, "Core did not fire output event");
}
示例12: OnNavigateToDocInProjectTest
public void OnNavigateToDocInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, this.violation.File);
mockDocument.AddExpectationExpr(doc => doc.Activate());
mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<DTE>)delegate { return (EnvDTE.DTE)mockDte.Instance; });
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
ProjectUtilities_Accessor.serviceProvider = this.mockServiceProvider.Instance;
// Execute
this.taskUnderTest.OnNavigate(EventArgs.Empty);
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
}
示例13: OnNavigateToDocNotInProjectTest
public void OnNavigateToDocNotInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
var mockSecondDocument = new SequenceMock<Document>();
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockSecondDocument.Instance);
mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);
mockSecondDocument.AddExpectationExpr(doc => doc.FullName, "DummyFile.txt");
AnalysisHelper analysisHelper = this.SetCoreNoUI();
bool eventFired = false;
PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage)));
actual.SetFieldOrProperty("core", this.package.Core);
// Register output generated event to test event fired
this.package.Core.OutputGenerated += (sender, args) => { eventFired = true; };
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
// Use private type to set static private field
PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);
// Execute
PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
Assert.IsTrue(eventFired, "Core did not fire output event");
}
示例14: OnNavigateToDocInProjectTest
public void OnNavigateToDocInProjectTest()
{
var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
var mockDte = new Mock<DTE>();
var mockDocuments = new Mock<Documents>();
var mockDocument = new SequenceMock<Document>();
var mockActiveDocument = new Mock<Document>();
var mockTextSelection = new SequenceMock<TextSelection>();
var mockVirtualPoint = new SequenceMock<VirtualPoint>();
this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, this.violation.File);
mockDocument.AddExpectationExpr(doc => doc.Activate());
mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<DTE>)delegate { return (EnvDTE.DTE)mockDte.Instance; });
mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);
mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);
mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(SVsSolutionBuildManager)), new MockSolutionBuildManager());
// Use private type to set static private field
PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);
// Execute
PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);
// Verify the required methods are called to show the violation
mockTextSelection.Verify();
mockVirtualPoint.Verify();
mockDocument.Verify();
}
示例15: OutputPanePropertyTest
public void OutputPanePropertyTest()
{
try
{
// Setup
Mock<Window> mockWindow = this.SetupMockWindow();
Mock<OutputWindow> mockOutputWindow = new Mock<OutputWindow>();
mockWindow.ImplementExpr(w => w.Object, (EnvDTE.OutputWindow)mockOutputWindow.Instance);
Mock<OutputWindowPane> mockOutputWindowPane = new Mock<OutputWindowPane>();
Mock<OutputWindowPanes> mockOutputWindowPanes = new Mock<OutputWindowPanes>();
mockOutputWindow.ImplementExpr(ow => ow.OutputWindowPanes, (EnvDTE.OutputWindowPanes)mockOutputWindowPanes.Instance);
mockOutputWindowPanes.ImplementExpr(owp => owp.Add("StyleCop"), (EnvDTE.OutputWindowPane)mockOutputWindowPane.Instance);
// Call
VSWindows actual = VSWindows.GetInstance(this.serviceProvider);
// Verify
Assert.IsNotNull(actual.OutputPane, "OutputPane property was null");
}
catch (Exception ex)
{
// Use try catch to test a workaround on CI build (AppVeyor)
Console.WriteLine(ex.Message);
}
}