public void IsValidXmlMissingFileTest() { var path = Path.GetTempFileName(); File.Delete(path); Assert.IsFalse(XmlResultParser.IsValidXml(path, out var jargon), "missing file"); }
public void UpdateMissingDataTest() // only works with NUnitV3 { string appName = "TestApp"; var path = CreateResultSample(XmlResultJargon.NUnitV3); var cleanPath = path + "_clean"; XmlResultParser.CleanXml(path, cleanPath); var updatedXml = path + "_updated"; var logs = new [] { "/first/path", "/second/path", "/last/path" }; XmlResultParser.UpdateMissingData(cleanPath, updatedXml, appName, logs); // assert that the required info was updated Assert.IsTrue(File.Exists(updatedXml), "file exists"); var doc = XDocument.Load(updatedXml); var testSuiteElements = doc.Descendants().Where(e => e.Name == "test-suite" && e.Attribute("type")?.Value == "Assembly"); // assert root node contains the attachments var rootNode = testSuiteElements.FirstOrDefault(); Assert.IsNotNull(rootNode, "Root node"); var attachments = rootNode.Descendants().Where(e => e.Name == "attachment"); var failureCount = rootNode.Descendants().Where(e => e.Name == "test-case" && e.Attribute("result").Value == "Failed").Count(); Assert.AreEqual(logs.Length * (failureCount + 1), attachments.Count(), "attachment count"); // assert that name and full name are present and are the app name foreach (var node in testSuiteElements) { Assert.AreEqual(appName, node.Attribute("name").Value, "name"); Assert.AreEqual(appName, node.Attribute("fullname").Value, "fullname"); } File.Delete(path); File.Delete(cleanPath); File.Delete(updatedXml); }
public void GetVSTSFileNameTest() { var path = Path.GetTempFileName(); var newPath = XmlResultParser.GetVSTSFilename(path); StringAssert.StartsWith("vsts-", Path.GetFileName(newPath)); File.Delete(path); }
public void GetXmlFilePathTest(string prefix, XmlResultJargon jargon) { var orignialPath = "/path/to/a/xml/result.xml"; var xmlPath = XmlResultParser.GetXmlFilePath(orignialPath, jargon); var fileName = Path.GetFileName(xmlPath); StringAssert.StartsWith(prefix, fileName, "xml prefix"); }
public void IsValidXmlTest(XmlResultJargon jargon) { var path = CreateResultSample(jargon); Assert.IsTrue(XmlResultParser.IsValidXml(path, out var resultJargon), "is valid"); Assert.AreEqual(jargon, resultJargon, "jargon"); File.Delete(path); }
public void When_parsing_a_restMS_domain() { _couldParse = XmlResultParser.TryParse(BODY, out _domain); //_should_be_able_to_parse_the_result _couldParse.Should().BeTrue(); //_should_have_a_domain_object _domain.Should().NotBeNull(); }
public void When_parsing_a_restMS_domain() { _couldParse = XmlResultParser.TryParse(BODY, out _domain); //_should_be_able_to_parse_the_result Assert.True(_couldParse); //_should_have_a_domain_object Assert.NotNull(_domain); }
public void CleanXmlPingTest(XmlResultJargon jargon) { var path = CreateResultSample(jargon, includePing: true); var cleanPath = path + "_clean"; XmlResultParser.CleanXml(path, cleanPath); Assert.IsTrue(XmlResultParser.IsValidXml(cleanPath, out var resultJargon), "is valid"); Assert.AreEqual(jargon, resultJargon, "jargon"); File.Delete(path); File.Delete(cleanPath); }
/// <summary> /// Parses the response. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="response">The response.</param> /// <returns>T.</returns> /// <exception cref="ResultParserException"></exception> public T ParseResponse <T>(HttpResponseMessage response) where T : class, new() { var entityBody = response.Content.ReadAsStringAsync().Result; T domainObject; if (!XmlResultParser.TryParse(entityBody, out domainObject)) { var errorString = string.Format("Could not parse entity body as a domain => {0}", entityBody); _logger.Value.ErrorFormat(errorString); throw new ResultParserException(errorString); } return(domainObject); }
public void CleanXmlTouchUnitTest() { // similar to CleanXmlPingTest but using TouchUnit, so we do not want to see the extra nodes var path = CreateResultSample(XmlResultJargon.TouchUnit, includePing: true); var cleanPath = path + "_clean"; XmlResultParser.CleanXml(path, cleanPath); Assert.IsTrue(XmlResultParser.IsValidXml(cleanPath, out var resultJargon), "is valid"); Assert.AreEqual(XmlResultJargon.NUnitV2, resultJargon, "jargon"); // load the xml, ensure we do not have the nodes we removed var doc = XDocument.Load(cleanPath); Assert.IsFalse(doc.Descendants().Where(e => e.Name == "TouchUnitTestRun").Any(), "TouchUnitTestRun"); Assert.IsFalse(doc.Descendants().Where(e => e.Name == "NUnitOutput").Any(), "NUnitOutput"); File.Delete(path); File.Delete(cleanPath); }
public async Task <bool> BuildAsync() { if (Finished) { return(true); } await VerifyBuildAsync(); if (Finished) { return(BuildTask.Succeeded); } ExecutionResult = TestExecutingResult.Building; await BuildTask.RunAsync(); if (!BuildTask.Succeeded) { if (BuildTask.TimedOut) { ExecutionResult = TestExecutingResult.TimedOut; } else { ExecutionResult = TestExecutingResult.BuildFailure; } FailureMessage = BuildTask.FailureMessage; if (Harness.InCI && BuildTask is MSBuildTask projectTask) { XmlResultParser.GenerateFailure(Logs, "build", projectTask.TestName, projectTask.Variation, "AppBuild", $"App could not be built {FailureMessage}.", projectTask.BuildLog.FullPath, Harness.XmlJargon); } } else { ExecutionResult = TestExecutingResult.Built; } return(BuildTask.Succeeded); }
public void TearDown() { resultParser = null; }
public void SetUp() { resultParser = new XmlResultParser(); }
public XmlResultParserTests() { _resultParser = new XmlResultParser(); }
protected override async Task RunTestAsync() { Jenkins.MainLog.WriteLine("Running '{0}' on device (candidates: '{1}')", ProjectFile, string.Join("', '", Candidates.Select((v) => v.Name).ToArray())); var uninstall_log = Logs.Create($"uninstall-{Timestamp}.log", "Uninstall log"); using (var device_resource = await NotifyBlockingWaitAsync(Jenkins.GetDeviceResources(Candidates).AcquireAnyConcurrentAsync())) { try { // Set the device we acquired. Device = Candidates.First((d) => d.UDID == device_resource.Resource.Name); if (Device.DevicePlatform == DevicePlatform.watchOS) { CompanionDevice = Jenkins.Devices.FindCompanionDevice(Jenkins.DeviceLoadLog, Device); } Jenkins.MainLog.WriteLine("Acquired device '{0}' for '{1}'", Device.Name, ProjectFile); runner = new AppRunner { Harness = Harness, ProjectFile = ProjectFile, Target = AppRunnerTarget, LogDirectory = LogDirectory, MainLog = uninstall_log, DeviceName = Device.Name, CompanionDeviceName = CompanionDevice?.Name, Configuration = ProjectConfiguration, TimeoutMultiplier = TimeoutMultiplier, Variation = Variation, BuildTask = BuildTask, }; // Sometimes devices can't upgrade (depending on what has changed), so make sure to uninstall any existing apps first. if (Jenkins.UninstallTestApp) { runner.MainLog = uninstall_log; var uninstall_result = await runner.UninstallAsync(); if (!uninstall_result.Succeeded) { MainLog.WriteLine($"Pre-run uninstall failed, exit code: {uninstall_result.ExitCode} (this hopefully won't affect the test result)"); } } else { uninstall_log.WriteLine($"Pre-run uninstall skipped."); } if (!Failed) { // Install the app this.install_log = new AppInstallMonitorLog(Logs.Create($"install-{Timestamp}.log", "Install log")); try { runner.MainLog = this.install_log; var install_result = await runner.InstallAsync(install_log.CancellationToken); if (!install_result.Succeeded) { FailureMessage = $"Install failed, exit code: {install_result.ExitCode}."; ExecutionResult = TestExecutingResult.Failed; if (Harness.InCI) { XmlResultParser.GenerateFailure(Logs, "install", runner.AppName, runner.Variation, $"AppInstallation on {runner.DeviceName}", $"Install failed on {runner.DeviceName}, exit code: {install_result.ExitCode}", install_log.FullPath, Harness.XmlJargon); } } } finally { this.install_log.Dispose(); this.install_log = null; } } if (!Failed) { // Run the app runner.MainLog = Logs.Create($"run-{Device.UDID}-{Timestamp}.log", "Run log"); await runner.RunAsync(); if (!string.IsNullOrEmpty(runner.FailureMessage)) { FailureMessage = runner.FailureMessage; } else if (runner.Result != TestExecutingResult.Succeeded) { FailureMessage = GuessFailureReason(runner.MainLog); } if (runner.Result == TestExecutingResult.Succeeded && Platform == TestPlatform.iOS_TodayExtension64) { // For the today extension, the main app is just a single test. // This is because running the today extension will not wake up the device, // nor will it close & reopen the today app (but launching the main app // will do both of these things, preparing the device for launching the today extension). AppRunner todayRunner = new AppRunner { Harness = Harness, ProjectFile = TestProject.GetTodayExtension().Path, Target = AppRunnerTarget, LogDirectory = LogDirectory, MainLog = Logs.Create($"extension-run-{Device.UDID}-{Timestamp}.log", "Extension run log"), DeviceName = Device.Name, CompanionDeviceName = CompanionDevice?.Name, Configuration = ProjectConfiguration, Variation = Variation, BuildTask = BuildTask, }; additional_runner = todayRunner; await todayRunner.RunAsync(); foreach (var log in todayRunner.Logs.Where((v) => !v.Description.StartsWith("Extension ", StringComparison.Ordinal))) { log.Description = "Extension " + log.Description [0].ToString().ToLower() + log.Description.Substring(1); } ExecutionResult = todayRunner.Result; if (!string.IsNullOrEmpty(todayRunner.FailureMessage)) { FailureMessage = todayRunner.FailureMessage; } } else { ExecutionResult = runner.Result; } } } finally { // Uninstall again, so that we don't leave junk behind and fill up the device. if (Jenkins.UninstallTestApp) { runner.MainLog = uninstall_log; var uninstall_result = await runner.UninstallAsync(); if (!uninstall_result.Succeeded) { MainLog.WriteLine($"Post-run uninstall failed, exit code: {uninstall_result.ExitCode} (this won't affect the test result)"); } } else { uninstall_log.WriteLine($"Post-run uninstall skipped."); } // Also clean up after us locally. if (Harness.InCI || Jenkins.CleanSuccessfulTestRuns && Succeeded) { await BuildTask.CleanAsync(); } } } }
public void GenerateFailureTest(XmlResultJargon jargon) { var src = "test-case"; var appName = "MyUnitTest"; var variation = "Debug"; var title = "Testing"; var message = "This is a test"; var stderrMessage = "Something went very wrong"; var stderrPath = Path.GetTempFileName(); // write the message in the stderrParh that should be read using (var writer = new StreamWriter(stderrPath)) { writer.WriteLine(stderrMessage); } // create a path with data in it var logs = new Mock <ILogs> (); var tmpLogMock = new Mock <ILogFile> (); var xmlLogMock = new Mock <ILogFile> (); var tmpPath = Path.GetTempFileName(); var finalPath = Path.GetTempFileName(); // create a number of fake logs to be added to the failure var logsDir = Path.GetTempFileName(); File.Delete(logsDir); Directory.CreateDirectory(logsDir); var failureLogs = new [] { "first.txt", "second.txt", "last.txt" }; foreach (var file in failureLogs) { var path = Path.Combine(logsDir, file); File.Create(path); } // expect the creation of the two diff xml file logs _ = logs.Setup(l => l.Create(It.IsAny <string> (), "Failure Log tmp", null)).Returns(tmpLogMock.Object); _ = logs.Setup(l => l.Create(It.IsAny <string> (), LogType.XmlLog.ToString(), null)).Returns(xmlLogMock.Object); if (jargon == XmlResultJargon.NUnitV3) { _ = logs.Setup(l => l.Directory).Returns(logsDir); _ = tmpLogMock.Setup(tmpLog => tmpLog.FullPath).Returns(tmpPath); } // return the two temp files so that we can later validate that everything is present _ = xmlLogMock.Setup(xmlLog => xmlLog.FullPath).Returns(finalPath); XmlResultParser.GenerateFailure(logs.Object, src, appName, variation, title, message, stderrPath, jargon); // actual assertions do happen in the validation functions ValidationMap [jargon] (src, appName, variation, title, message, stderrMessage, finalPath, failureLogs.Length); // verify that we are correctly adding the logs logs.Verify(l => l.Create(It.IsAny <string> (), It.IsAny <string> (), null), (jargon == XmlResultJargon.NUnitV3) ? Times.AtMost(2) : Times.AtMostOnce()); if (jargon == XmlResultJargon.NUnitV3) { logs.Verify(l => l.Directory, Times.Once); tmpLogMock.Verify(l => l.FullPath, Times.AtLeastOnce); } xmlLogMock.Verify(l => l.FullPath, Times.AtLeastOnce); // clean files File.Delete(stderrPath); File.Delete(tmpPath); File.Delete(finalPath); Directory.Delete(logsDir, true); }