Beispiel #1
0
        public void Configure(TestConfiguration aTestConfiguration, TestEnvironment aTestEnvironment)
        {
            var testDiscovery = new TestDiscovery(aTestEnvironment.CustomArguments);
            var testExecution = new TimeWarpExecution(aTestEnvironment.CustomArguments);

            aTestConfiguration.Conventions.Add(testDiscovery, testExecution);
        }
        public void Discovery_IgnoresNonAnnotatedTestMethods()
        {
            var testMethods = @"Public Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput + testMethods);

            var vbe = builder.AddProject(project.Build()).Build().Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                Assert.IsFalse(TestDiscovery.GetAllTests(state).Any());
            }
        }
        public void Discovery_IgnoresNonAnnotatedModuleCleanupInGivenNonTestModule()
        {
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetNormalModuleInput.Replace("'@ModuleCleanup", string.Empty));

            var vbe = builder.AddProject(project.Build()).Build().Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                var component           = project.MockComponents.Single(f => f.Object.Name == "TestModule1").Object;
                var qualifiedModuleName = new QualifiedModuleName(component);

                var initMethods = TestDiscovery.FindModuleCleanupMethods(qualifiedModuleName, state);
                Assert.IsFalse(initMethods.Any());
            }
        }
Beispiel #4
0
        public void Discovery_IgnoresAnnotatedTestMethodsNotInTestModule(string accessibility)
        {
            var testMethods = $@"'@TestMethod
{accessibility} Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetNormalModuleInput(accessibility) + testMethods);

            var vbe = builder.AddProject(project.Build()).Build().Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                Assert.IsFalse(TestDiscovery.GetAllTests(state).Any());
            }
        }
        public void Discovery_DiscoversAnnotatedModuleCleanupInGivenTestModule()
        {
            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput)
                          .AddComponent("TestModule2", ComponentType.StandardModule, GetTestModuleInput);

            var vbe = builder.AddProject(project.Build()).Build().Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                var component           = project.MockComponents.Single(f => f.Object.Name == "TestModule1").Object;
                var qualifiedModuleName = new QualifiedModuleName(component);

                var initMethods = TestDiscovery.FindModuleCleanupMethods(qualifiedModuleName, state).ToList();

                Assert.AreEqual(1, initMethods.Count);
                Assert.AreEqual("TestModule1", initMethods.ElementAt(0).QualifiedName.QualifiedModuleName.ComponentName);
                Assert.AreEqual("ModuleCleanup", initMethods.ElementAt(0).QualifiedName.MemberName);
            }
        }
        public void Discovery_DiscoversAnnotatedTestMethodsInGivenTestModule()
        {
            var testMethods = @"'@TestMethod
Public Sub TestMethod1()
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("TestModule1", ComponentType.StandardModule, GetTestModuleInput + testMethods)
                          .AddComponent("TestModule2", ComponentType.StandardModule, GetTestModuleInput + testMethods);

            var vbe = builder.AddProject(project.Build()).Build().Object;

            using (var state = MockParser.CreateAndParse(vbe))
            {
                var component = project.MockComponents.Single(f => f.Object.Name == "TestModule1").Object;
                var tests     = TestDiscovery.GetTests(vbe, component, state).ToList();

                Assert.AreEqual(1, tests.Count);
                Assert.AreEqual("TestModule1", tests.ElementAt(0).Declaration.ComponentName);
            }
        }
Beispiel #7
0
        private void generate_button_Click(object sender, EventArgs e)
        {
            if (_scenario == null)
            {
                return;
            }

            TestMetadata metadata = new TestMetadata
            {
                file_url                  = $"{_scenario.EnterpriseScenarioId}",
                name                      = _scenario.Name,
                is_manual                 = 0,
                last_mod_by               = UserManager.CurrentUserName,
                last_mod_date             = DateTime.Now,
                primary_owner_entity_type = "STF",
                primary_owner_entity_name = owner_comboBox.Text,
                purpose                   = purpose_textBox.Text,
                status                    = (Status)status_comboBox.SelectedIndex,
                test_classification       = (TestClassification)classification_comboBox.SelectedIndex,
                test_framework            = TestFrameWork.Stf,
                test_tier                 = 1,
                timeout                   = TimeSpan.FromHours(_scenario.EstimatedRuntime).TotalMinutes.ToString(CultureInfo.InvariantCulture),
                title                     = _scenario.Name,
                version                   = "1.0",
                test_dependencies         = new List <string>(),
                resources                 = new List <Dictionary <string, object> >()
            };
            Dictionary <string, object> resourceDictionary = new Dictionary <string, object>
            {
                { "type", 18 },
                { "id", "STF" },
                { "StfWebApiServer", $"http://{_currentDatabase}:9000/api/Session" }
            };

            metadata.resources.Add(resourceDictionary);


            TestDiscovery testDiscovery = new TestDiscovery
            {
                data = new List <TestMetadata> {
                    metadata
                },
                datatype    = "tests",
                repo_type   = "sqlserver",
                repo_branch = "EnterpriseTest",
                repo_url    = _currentDatabase
            };

            var metadataFilePath = Path.Combine(Path.GetTempPath(), "TestsDiscovered.json");

            var jsonString = JsonConvert.SerializeObject(testDiscovery);

            File.WriteAllText(metadataFilePath, jsonString);

            var metadataTarFilePath = Path.Combine(Path.GetTempPath(), "TestsDiscovered.tar");

            using (var targetStream = new TarOutputStream(File.Create(metadataTarFilePath)))
            {
                CreateTarManually(targetStream, metadataFilePath);
            }
            //now pack it using BZ2 compression
            var metadataBzFilePath = metadataTarFilePath + ".bz2";

            using (Stream tarInputStream = File.OpenRead(metadataTarFilePath))
            {
                using (Stream tarOutputStream = File.Create(metadataBzFilePath))
                {
                    BZip2.Compress(tarInputStream, tarOutputStream, true, 9);
                }
            }

            HttpClientHandler handler = new HttpClientHandler();

            using (HttpClient httpClient = new HttpClient(handler))
            {
                using (var multiPartFormData = new MultipartFormDataContent())
                {
                    using (var fileContent = new StreamContent(File.OpenRead(metadataBzFilePath)))
                    {
                        fileContent.Headers.Add("Content-Type", "application/x-bzip2");
                        fileContent.Headers.Add("Content-Disposition",
                                                "form-data; name=\"file\"; filename=\"" + (metadataBzFilePath) + "\"");
                        multiPartFormData.Add(fileContent, "file", metadataBzFilePath);

                        var message = httpClient.PutAsync(
                            $"https://{_tmsServer}/tms/v1/testcases/uploadtestcases/",
                            multiPartFormData);

                        if (message.Result.IsSuccessStatusCode)
                        {
                            MessageBox.Show(@"Test Case submitted.", @"BTF Metadata Helper", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public static int Main(string[] args)
        {
            var options = new Options();
            var parser  = new Parser(new ParserSettings(System.Console.Out));

            if (!parser.ParseArguments(args, options) || options.Input.Count < 1)
            {
                System.Console.WriteLine(options.GetUsage());
                return(1);
            }

            var assembly = EcsCompilerService.AssemblyHelper.LoadAssemblyWithResolver(options.Input[0]);

            MethodDefinition entryPoint;

            if (options.Test != null)
            {
                var tests         = TestDiscovery.DiscoverTests(assembly);
                var filteredTests = tests.Where(x => (x.DeclaringType.Name + "." + x.Name).StartsWith(options.Test) || x.FullName.StartsWith(options.Test)).ToArray();


                if (filteredTests.Count() == 0)
                {
                    throw new ArgumentException("No matching test was found");
                }
                else
                {
                    var mod = ModuleDefinition.CreateModule("TestModule", new ModuleParameters {
                        AssemblyResolver = assembly.AssemblyResolver
                    });
                    var testClass = TestEntryGenerator.GenerateTestEntry(filteredTests, mod);

                    // make sure the actual code is resolvable
                    assembly.Types.Add(testClass);

                    entryPoint = testClass.Methods.Last();
                }
            }
            else
            {
                if (options.EntryClass == null)
                {
                    entryPoint = assembly.Types.Select(x => x.Methods.FirstOrDefault(m => m.Name == "Main" && m.IsStatic)).First(x => x != null);
                }
                else
                {
                    var entryType = assembly.Types.First(x => x.Name == options.EntryClass);
                    entryPoint = entryType.Methods.First(x => x.Name == "Main" && x.IsStatic);
                }
            }

            //Logger.IsVerbose = options.Verbose;

            // Ouput directory
            var outputdir = options.OutputDir;

            if (outputdir == null)
            {
                //var targetString = toolchain.GetType().Name.Replace("Target", "");
                var targetString = "";
                outputdir = "out_" + targetString;
            }

            var execName = assembly.Name;

            // directly include source/header files
            IncludeCFiles.SrcDir  = "../../..";
            IncludeCFiles.DestDir = outputdir;

            System.Console.WriteLine("Generating C Code ...");
            var cFiles = CompilerService.Run(entryPoint);


            var target      = new TargetPC();
            var targetFiles = target.ConvertTargetFiles(cFiles, execName, entryPoint.DeclaringType.Name + "_Main");

            // todo: is this still needed?
            if (options.Override)               // override all taget files
            {
                foreach (var t in targetFiles)
                {
                    t.Override = true;
                }
            }

            FileWriter.SaveFiles(targetFiles, outputdir);

            if (options.GenerateOnly)
            {
                return(0);
            }

            RunOptions runOptions = new RunOptions {
                Verbose    = options.Verbose,
                WorkingDir = outputdir,
                Variant    = options.Board
            };

            System.Console.WriteLine("Compiling ...");
            target.Compile(runOptions, execName);


            if (options.CompileOnly)
            {
                return(0);
            }

            int returnCode = 0;

            try {
                System.Console.WriteLine("Running ...");
                target.Exec(runOptions, execName);
            } catch (BadReturnCodeExcpetion e) {
                returnCode = e.Code;
            }

            System.Console.WriteLine();

            if (returnCode != 0)
            {
                System.Console.WriteLine("Program terminated with return code {0}", returnCode);
            }

            if (options.Wait)
            {
                System.Console.WriteLine("Done - Press Key to Exit");
                System.Console.ReadKey();
            }

            return(returnCode);
        }