protected string BuildEngineVersion(string engine) { var engineVersion = new VersionParser(UserAgent, engine); var result = engineVersion.Parse(); return(result.Success? result.Match.Name : string.Empty); }
public void ValidTagGeneratesResultWithNoErrors() { string value = "TLSRPTv1"; string key = "v"; string token = $"{key}={value}"; string record = $"{token};rua=mailto:[email protected]"; EvaluationResult <Tag> evaluationResult = _versionParser.Parse(new List <Tag>(), record, token, key, value); VersionTag versionTag = evaluationResult.Item as VersionTag; Assert.That(versionTag, Is.Not.Null); Assert.That(versionTag.RawValue, Is.EqualTo(token)); Assert.That(versionTag.Value, Is.EqualTo(value)); Assert.That(evaluationResult.Errors, Is.Empty); }
public void TestVersionParser() { var parser = new VersionParser(); parser.Parse("0.0.0").Equals(new Version()); parser.Parse("1.0.0").Equals(new Version(1)); parser.Parse("1.2.0").Equals(new Version(1, 2)); parser.Parse("1.2.3").Equals(new Version(1, 2, 3)); parser.Parse("1.2.3-alpha.1").Equals(new Version(1, 2, 3, new[] { "alpha", (object)1 })); parser.Parse("1.2.3+build.1").Equals(new Version(1, 2, 3, null, new[] { "build", "1" })); parser.Parse("1.2.3+build.1").Equals(new Version(1, 2, 3, null, new[] { "dliub", "2" })); // Build metadata is ignored parser.Parse("1.2.3-alpha.1+build.1").Equals(new Version(1, 2, 3, new[] { "alpha", (object)1 }, new[] { "build", "1" })); parser.Parse("1.2.3-alpha.1+build.1").Equals(new Version(1, 2, 3, new[] { "alpha", (object)1 }, new[] { "dliub", "2" })); // Build metadata is ignored }
public void ParsesVersionCorrectly(string input, string expectedPrerelease, string expectedBuild) { var version = VersionParser.Parse(input); var output = version.ToString(); Assert.AreEqual(expectedPrerelease, version.Prerelease); Assert.AreEqual(expectedBuild, version.Build); }
public void ThrowsExceptionForMissingBranchName() { var context = new Context { Version = VersionParser.Parse("1.0") }; ExceptionTester.CallMethodAndExpectException <ContinuaInitException>(() => context.ValidateContext()); }
public void SucceedsForValidContext() { var context = new Context { BranchName = "master", Version = VersionParser.Parse("1.0") }; // should not throw context.ValidateContext(); }
public void ReturnsTrueForDevelopBranch() { var context = new Context { BranchName = "develop", Version = VersionParser.Parse("1.0.0-unstable0001") }; var rule = new DisplayVersionRule(); Assert.AreEqual("1.0.0-alpha0001", rule.GetParameter(context).Value); }
public void ReturnsFalseForMasterBranch() { var context = new Context { BranchName = "master", Version = VersionParser.Parse("1.0.0") }; var rule = new DisplayVersionRule(); Assert.AreEqual("1.0.0", rule.GetParameter(context).Value); }
public void ReturnsVersion(string input, string expectedOutput) { var context = new Context { BranchName = "master", Version = VersionParser.Parse(input) }; var rule = new MajorMinorPatchVersionRule(); var actualOutput = rule.GetParameter(context).Value; Assert.AreEqual(expectedOutput, actualOutput); }
public void ReturnsRightValue(string versionInput, bool expectedOutput) { var context = new Context { Version = VersionParser.Parse(versionInput) }; var rule = new IsOfficialBuildRule(); var expected = expectedOutput.ToString().ToLower(); var actual = rule.GetParameter(context).Value.ToLower(); Assert.AreEqual(expected, actual); }
public void ReturnsRightValue(string versionInput, string expectedOutput) { var context = new Context { Version = VersionParser.Parse(versionInput) }; var rule = new PublishTypeRule(); var expected = expectedOutput.ToLower(); var actual = rule.GetParameter(context).Value.ToLower(); Assert.AreEqual(expected, actual); }
public void should_not_return_Version(string url) { VersionParser.Parse(new Uri(url)).Should().BeNull(); }
public string should_parse_version(string url) { return(VersionParser.Parse(new Uri(url))); }
public async Task <int> InvokeAsync(InvocationContext context) { var rawVersion = context.ParseResult.ValueForArgument("version"); if (rawVersion == null) { await Console.Error.WriteLineAsync($"Missing version argument"); return(1); } Version version; if (rawVersion.ToString()?.ToLower() == "latest") { try { version = _nodeWeb.GetLatestNodeVersion(); } catch (Exception) { await Console.Error.WriteLineAsync("Unable to determine latest Node.js version."); return(1); } } else if (rawVersion.ToString()?.Split(".").Length < 3) { try { version = _nodeWeb.GetLatestNodeVersion(rawVersion.ToString()); } catch (Exception) { await Console.Error.WriteLineAsync($"Unable to get latest Node.js version " + $"with prefix {rawVersion}."); return(1); } } else { try { version = VersionParser.Parse(rawVersion.ToString()); } catch (ArgumentException) { await Console.Error.WriteLineAsync($"Invalid version argument: {rawVersion}"); return(1); } } // // Is the requested version already installed? // if (_nodeLocal.GetInstalledVersions().FindIndex(v => v.Version.Equals(version)) != -1) { await Console.Error.WriteLineAsync($"{version} already installed"); return(1); } // // Download it // var downloadUrl = _nodeWeb.GetDownloadUrl(version); var zipPath = Path.Join(_globalContext.StoragePath, Path.GetFileName(downloadUrl)); var progressBar = new ProgressBar(100, "Download progress", new ProgressBarOptions { ProgressCharacter = '\u2593', ForegroundColor = ConsoleColor.Yellow, ForegroundColorDone = ConsoleColor.Green, }); var webClient = new WebClient(); webClient.DownloadProgressChanged += (s, e) => { progressBar.Tick(e.ProgressPercentage); }; webClient.DownloadFileCompleted += (s, e) => { progressBar.Dispose(); }; try { await webClient.DownloadFileTaskAsync(downloadUrl, zipPath).ConfigureAwait(false); } catch (Exception e) { await Console.Error.WriteLineAsync("Unable to download the Node.js zip file."); if (e.InnerException == null) { return(1); } await Console.Error.WriteLineAsync(e.InnerException.Message); await Console.Error.WriteLineAsync("You may need to run this command from an " + "elevated prompt. (Run as Administrator)"); return(1); } Console.WriteLine("Extracting..."); ConsoleSpinner.Instance.Update(); var timer = new Timer(250); timer.Elapsed += (s, e) => ConsoleSpinner.Instance.Update(); timer.Enabled = true; ZipFile.ExtractToDirectory(zipPath, _globalContext.StoragePath); timer.Enabled = false; ConsoleSpinner.Reset(); File.Delete(zipPath); Console.WriteLine($"Done. To use, run `nodeswap use {version}`"); return(0); }
public void Parse_ShouldThrowExceptionOnInvalidInput() { Assert.ThrowsException <ArgumentException>(() => VersionParser.Parse("a")); Assert.ThrowsException <ArgumentException>(() => VersionParser.Parse("1.a")); Assert.ThrowsException <ArgumentException>(() => VersionParser.Parse("1.2.a")); }
public void TestParseNullVersionThrows() { var parser = new VersionParser(); Assert.Throws <System.ArgumentException>(() => parser.Parse(null)); }
public void TestParseInvalidVersionThrows() { var parser = new VersionParser(); Assert.Throws <System.FormatException>(() => parser.Parse("")); }
public void Parse_ShouldParseProperly(string rawInput, Version version) { VersionParser.Parse(rawInput).ShouldBe(version); }