本文整理汇总了C#中RubberduckTests.Mocks.MockVbeBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MockVbeBuilder类的具体用法?C# MockVbeBuilder怎么用?C# MockVbeBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockVbeBuilder类属于RubberduckTests.Mocks命名空间,在下文中一共展示了MockVbeBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: 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());
}
示例3: ObsoleteCallStatement_ReturnsMultipleResults
public void ObsoleteCallStatement_ReturnsMultipleResults()
{
const string inputCode =
@"Sub Foo()
Call Goo(1, ""test"")
End Sub
Sub Goo(arg1 As Integer, arg1 As String)
Call 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 ObsoleteCallStatementInspection(parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(2, inspectionResults.Count());
}
示例4: 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));
}
示例5: 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());
}
示例6: UseMeaningfulName_ReturnsResult_NameEndsWithDigit
public void UseMeaningfulName_ReturnsResult_NameEndsWithDigit()
{
const string inputCode =
@"Sub Foo1()
End Sub";
//Arrange
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", vbext_ProjectProtection.vbext_pp_none)
.AddComponent("MyClass", vbext_ComponentType.vbext_ct_ClassModule, inputCode)
.Build();
var vbe = builder.AddProject(project).Build();
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 UseMeaningfulNameInspection(null, parser.State);
var inspectionResults = inspection.GetInspectionResults();
Assert.AreEqual(1, inspectionResults.Count());
}
示例7: ObsoleteLetStatement_DoesNotReturnResult
public void ObsoleteLetStatement_DoesNotReturnResult()
{
const string inputCode =
@"Public Sub Foo()
Dim var1 As Integer
Dim var2 As Integer
var2 = var1
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(0, inspectionResults.Count());
}
示例8: 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());
}
示例9: 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());
}
示例10: 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());
}
示例11: 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());
}
示例12: 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());
}
示例13: 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());
}
示例14: 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());
}
示例15: Resolve
private RubberduckParserState Resolve(string code, vbext_ComponentType moduleType = vbext_ComponentType.vbext_ct_StdModule)
{
var builder = new MockVbeBuilder();
VBComponent component;
var vbe = builder.BuildFromSingleModule(code, moduleType, out component);
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
parser.Parse();
if (parser.State.Status != ParserState.Ready)
{
Assert.Inconclusive("Parser state should be 'Ready', but returns '{0}'.", parser.State.Status);
}
return parser.State;
}