本文整理汇总了C#中RubberduckTests.Mocks.MockVbeBuilder.BuildFromSingleStandardModule方法的典型用法代码示例。如果您正苦于以下问题:C# MockVbeBuilder.BuildFromSingleStandardModule方法的具体用法?C# MockVbeBuilder.BuildFromSingleStandardModule怎么用?C# MockVbeBuilder.BuildFromSingleStandardModule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubberduckTests.Mocks.MockVbeBuilder
的用法示例。
在下文中一共展示了MockVbeBuilder.BuildFromSingleStandardModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcedureShouldBeFunction_ReturnsResult_MultipleSubs
public void ProcedureShouldBeFunction_ReturnsResult_MultipleSubs()
{
const string inputCode =
@"Private Sub Foo(ByRef foo As Boolean)
End Sub
Private Sub Goo(ByRef foo As Integer)
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new ProcedureCanBeWrittenAsFunctionInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(2, inspectionResults.Count());
}
示例2: EmptyStringLiteral_ReturnsResult_PassToProcedure
public void EmptyStringLiteral_ReturnsResult_PassToProcedure()
{
const string inputCode =
@"Public Sub Bar()
Foo """"
End Sub
Public Sub Foo(ByRef arg1 As String)
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new EmptyStringLiteralInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(1, inspectionResults.Count());
}
示例3: FunctionReturnValueNotUsed_ReturnsResult_AddressOf
public void FunctionReturnValueNotUsed_ReturnsResult_AddressOf()
{
const string inputCode =
@"Public Function Foo(ByVal bar As String) As Integer
Foo = 42
End Function
Public Sub Bar()
Bar AddressOf Foo
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new FunctionReturnValueNotUsedInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(1, inspectionResults.Count());
}
示例4: UnassignedVariable_DoesNotReturnResult
public void UnassignedVariable_DoesNotReturnResult()
{
const string inputCode =
@"Function Foo() As Boolean
Dim var1 as String
var1 = ""test""
Goo var1
End Function
Sub Goo(ByVal arg1 As String)
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new VariableNotUsedInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(0, inspectionResults.Count());
}
示例5: ImplicitPublicMember_ReturnsResult_MultipleSubs
public void ImplicitPublicMember_ReturnsResult_MultipleSubs()
{
const string inputCode =
@"Sub Foo()
End Sub
Sub Goo()
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new ImplicitPublicMemberInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(2, inspectionResults.Count());
}
示例6: GetInspectionResults
public Task<PartialViewResult> GetInspectionResults(string code)
{
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
// ensure line endings are \r\n
code = code.Replace("\r\n", "\n").Replace("\n", "\r\n");
var vbe = builder.BuildFromSingleStandardModule(code, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, _state);
Task.Run(() => parser.Parse(new System.Threading.CancellationTokenSource())).Wait();
if (parser.State.Status >= ParserState.Error)
{
throw new ArgumentException(parser.State.Status.ToString());
}
var results = _inspector.Inspect(parser.State);
if (results.Any())
{
return Task.FromResult(PartialView("~/Views/Home/InspectionResults.cshtml", results));
}
return Task.FromResult(PartialView("~/Views/Home/NoInspectionResults.cshtml", results));
}
示例7: ProcedureUsed_DoesNotReturnResult
public void ProcedureUsed_DoesNotReturnResult()
{
const string inputCode =
@"Private Sub Foo()
Goo
End Sub
Private Sub Goo()
Foo
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new ProcedureNotUsedInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(0, inspectionResults.Count());
}
示例8: ObjectVariableNotSet_GivenObjectVariableNotSet_ReturnsResult
public void ObjectVariableNotSet_GivenObjectVariableNotSet_ReturnsResult()
{
const string inputCode = @"
Private Sub Workbook_Open()
Dim target As Range
target = Range(""A1"")
target.Value = ""forgot something?""
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new ObjectVariableNotSetInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(1, inspectionResults.Count());
}
示例9: MoveFieldCloserToUsage_DoesNotReturnsResult_MultipleReferenceInDifferentScope
public void MoveFieldCloserToUsage_DoesNotReturnsResult_MultipleReferenceInDifferentScope()
{
const string inputCode =
@"Private bar As String
Public Sub Foo()
Let bar = ""test""
End Sub
Public Sub For()
Let bar = ""test""
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new MoveFieldCloserToUsageInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(0, inspectionResults.Count());
}
示例10: ObsoleteLetStatement_ReturnsResult_MultipleLets
public void ObsoleteLetStatement_ReturnsResult_MultipleLets()
{
const string inputCode =
@"Public Sub Foo()
Dim var1 As Integer
Dim var2 As Integer
Let var2 = var1
Let var1 = var2
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var inspection = new ObsoleteLetStatementInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(2, inspectionResults.Count());
}
示例11: EncapsulatePublicField_WithLetter
public void EncapsulatePublicField_WithLetter()
{
//Input
const string inputCode =
@"Public fizz As Integer";
var selection = new Selection(1, 1, 1, 1);
//Expectation
const string expectedCode =
@"Private fizz As Integer
Public Property Get Name() As Integer
Name = fizz
End Property
Public Property Let Name(ByVal value As Integer)
fizz = value
End Property
";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var project = vbe.Object.VBProjects.Item(0);
var module = project.VBComponents.Item(0).CodeModule;
var codePaneFactory = new CodePaneWrapperFactory();
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);
var model = new EncapsulateFieldModel(parser.State, qualifiedSelection)
{
ImplementLetSetterType = true,
ImplementSetSetterType = false,
ParameterName = "value",
PropertyName = "Name"
};
//SetupFactory
var factory = SetupFactory(model);
//Act
var refactoring = new EncapsulateFieldRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory));
refactoring.Refactor(qualifiedSelection);
//Assert
Assert.AreEqual(expectedCode, module.Lines());
}
示例12: ExtractMethod_PrivateFunction
public void ExtractMethod_PrivateFunction()
{
const string inputCode = @"
Private Sub Foo()
Dim x As Integer
x = 1 + 2
End Sub";
const string expectedCode = @"
Private Sub Foo()
x = Bar()
End Sub
Private Function Bar() As Integer
Dim x As Integer
x = 1 + 2
Bar = x
End Function
";
var codePaneFactory = new CodePaneWrapperFactory();
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var module = component.CodeModule;
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var editor = new ActiveCodePaneEditor(module.VBE, codePaneFactory);
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(module.Parent), new Selection(4, 1, 4, 20));
var model = new ExtractMethodModel(editor, parser.State.AllDeclarations, qualifiedSelection);
model.Method.Accessibility = Accessibility.Private;
model.Method.MethodName = "Bar";
model.Method.ReturnValue = new ExtractedParameter("Integer", ExtractedParameter.PassedBy.ByVal, "x");
model.Method.Parameters = new List<ExtractedParameter>();
var factory = SetupFactory(model);
//act
var refactoring = new ExtractMethodRefactoring(factory.Object, editor);
refactoring.Refactor(qualifiedSelection);
//assert
Assert.AreEqual(expectedCode, module.Lines());
}
示例13: Parse
private string Parse(string code)
{
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(code, out component);
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var state = new RubberduckParserState();
var parser = MockParser.Create(vbe.Object, state);
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var tree = state.GetParseTree(component);
var parsed = tree.GetText();
var withoutEOF = parsed.Substring(0, parsed.Length - 5);
return withoutEOF;
}
示例14: RenameRefactoring_RenameVariable
public void RenameRefactoring_RenameVariable()
{
//Input
const string inputCode =
@"Private Sub Foo()
Dim val1 As Integer
End Sub";
var selection = new Selection(2, 12, 2, 12);
//Expectation
const string expectedCode =
@"Private Sub Foo()
Dim val2 As Integer
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var project = vbe.Object.VBProjects.Item(0);
var module = project.VBComponents.Item(0).CodeModule;
var codePaneFactory = new CodePaneWrapperFactory();
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);
var model = new RenameModel(vbe.Object, parser.State, qualifiedSelection, null) { NewName = "val2" };
//SetupFactory
var factory = SetupFactory(model);
//Act
var refactoring = new RenameRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null, parser.State);
refactoring.Refactor(qualifiedSelection);
//Assert
Assert.AreEqual(expectedCode, module.Lines());
}
示例15: ReorderParams_RefactorDeclaration
public void ReorderParams_RefactorDeclaration()
{
//Input
const string inputCode =
@"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
var selection = new Selection(1, 23, 1, 27);
//Expectation
const string expectedCode =
@"Private Sub Foo(ByVal arg2 As String, ByVal arg1 As Integer)
End Sub";
//Arrange
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
var project = vbe.Object.VBProjects.Item(0);
var module = project.VBComponents.Item(0).CodeModule;
var codePaneFactory = new CodePaneWrapperFactory();
var mockHost = new Mock<IHostApplication>();
mockHost.SetupAllProperties();
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);
//set up model
var model = new ReorderParametersModel(parser.State, qualifiedSelection, null);
model.Parameters.Reverse();
var factory = SetupFactory(model);
//act
var refactoring = new ReorderParametersRefactoring(factory.Object, new ActiveCodePaneEditor(vbe.Object, codePaneFactory), null);
refactoring.Refactor(model.TargetDeclaration);
//assert
Assert.AreEqual(expectedCode, module.Lines());
}