public void AddsTestModuleWithStubsAddsStubsPublicProcedures() { const string code = @"Public Sub PublicSub() End Sub Public Function PublicFunction() End Function Public Property Get PublicProperty() End Property Public Property Let PublicProperty(v As Variant) End Property Public Property Set PublicProperty(s As Object) End Property "; var(vbe, state) = ArrangeAndParseTestCode(ComponentType.StandardModule, "Module1", code); using (state) { var addTestModuleCommand = new AddTestModuleCommand(vbe.Object, state, ArrangeCodeGenerator(vbe.Object, state)); var addWithStubsCommand = new AddTestModuleWithStubsCommand(vbe.Object, addTestModuleCommand); var project = state.DeclarationFinder.FindProject(TestProjectName); var target = state.DeclarationFinder.FindStdModule("Module1", project); var _ = Enumerable.Empty <Declaration>().ToList(); var model = new CodeExplorerComponentViewModel(null, target, ref _, vbe.Object); addWithStubsCommand.Execute(model); var testModule = state.DeclarationFinder.FindStdModule($"{TestModuleBaseName}1", project); Assert.IsTrue(testModule.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule)); var stubIdentifierNames = new List <string> { $"PublicSub{TestMethodBaseName}", $"PublicFunction{TestMethodBaseName}", $"GetPublicProperty{TestMethodBaseName}", $"LetPublicProperty{TestMethodBaseName}", $"SetPublicProperty{TestMethodBaseName}" }; var stubs = state.DeclarationFinder.AllUserDeclarations.Where(d => d.IdentifierName.EndsWith(TestMethodBaseName)).ToList(); Assert.AreEqual(stubIdentifierNames.Count, stubs.Count); Assert.IsTrue(stubs.All(d => stubIdentifierNames.Contains(d.IdentifierName))); } }
public void AddsTestModuleWithStubs() { var(vbe, state) = ArrangeAndParseTestCode(ComponentType.StandardModule, "Module1", string.Empty); using (state) { var addTestModuleCommand = new AddTestModuleCommand(vbe.Object, state, ArrangeCodeGenerator(vbe.Object, state)); var addWithStubsCommand = new AddTestModuleWithStubsCommand(vbe.Object, addTestModuleCommand); addWithStubsCommand.Execute(null); var expectedModule = $"{TestModuleBaseName}1"; var generated = state.DeclarationFinder.AllUserDeclarations.SingleOrDefault(test => test.IdentifierName.Equals(expectedModule)); Assert.NotNull(generated); } }
public void AddsTestModuleWithStubsNoStubsAddedNonProcedures() { const string code = @"Public Type UserDefinedType UserDefinedTypeMember As String End Type Public Declare PtrSafe Sub LibraryProcedure Lib ""lib.dll""() Public Declare PtrSafe Function LibraryFunction Lib ""lib.dll""() Public Variable As String Public Const Constant As String = vbNullString Public Enum Enumeration EnumerationMember End Enum "; var(vbe, state) = ArrangeAndParseTestCode(ComponentType.StandardModule, "Module1", code); using (state) { var addTestModuleCommand = new AddTestModuleCommand(vbe.Object, state, ArrangeCodeGenerator(vbe.Object, state)); var addWithStubsCommand = new AddTestModuleWithStubsCommand(vbe.Object, addTestModuleCommand); var project = state.DeclarationFinder.FindProject(TestProjectName); var target = state.DeclarationFinder.FindStdModule("Module1", project); var _ = Enumerable.Empty <Declaration>().ToList(); var model = new CodeExplorerComponentViewModel(null, target, ref _, vbe.Object); addWithStubsCommand.Execute(model); var testModule = state.DeclarationFinder.FindStdModule($"{TestModuleBaseName}1", project); Assert.IsTrue(testModule.Annotations.Any(a => a.AnnotationType == AnnotationType.TestModule)); var stubs = state.DeclarationFinder.AllUserDeclarations.Where(d => d.IdentifierName.EndsWith(TestMethodBaseName)).ToList(); Assert.AreEqual(0, stubs.Count); } }
public void AddsTestModulePicksCorrectNumberWithStubs(int first, int second, int added) { var existing = new List <(ComponentType type, string name, string code)> { (ComponentType.StandardModule, $"{TestModuleBaseName}{first}", string.Empty), (ComponentType.StandardModule, $"{TestModuleBaseName}{second}", string.Empty) }; var(vbe, state) = ArrangeAndParseTestCode(TestProjectName, existing); using (state) { var addTestModuleCommand = new AddTestModuleCommand(vbe.Object, state, ArrangeCodeGenerator(vbe.Object, state)); var addWithStubsCommand = new AddTestModuleWithStubsCommand(vbe.Object, addTestModuleCommand); addWithStubsCommand.Execute(null); var expectedModule = $"{TestModuleBaseName}{added}"; var generated = state.DeclarationFinder.AllUserDeclarations.SingleOrDefault(test => test.IdentifierName.Equals(expectedModule)); Assert.NotNull(generated); } }