Example #1
0
        public void DoVersionsMatch_ShouldBeTrueWhenMatching()
        {
            var version = "12.2.1";

            VersionMatcher.DoVersionsMatch(version, version).Should()
            .BeTrue("because the versions exactly match");
        }
        public static void SetVersion(string file, Semver version)
        {
            if (!File.Exists(file))
            {
                return;
            }

            Program.VerboseOut(Verbose.Version, "Setting nuspec version {0} of {1}", version.ToString("P"), file);

            var lines    = File.ReadAllLines(file);
            var newLines = new List <string>();

            foreach (var line in lines)
            {
                if (VersionMatcher.IsMatch(line))
                {
                    newLines.Add(VersionMatcher.Replace(line, "${1}" + version.ToString("P") + "$2"));
                }
                else
                {
                    newLines.Add(line);
                }
            }

            FileUtil.AssertWritable(file);
            File.WriteAllLines(file, newLines, Encoding.UTF8);
        }
        public void IsGreaterThan(string left, string right, bool expected)
        {
            var versionMatcher = new VersionMatcher(NullLogger <VersionMatcher> .Instance);
            var result         = versionMatcher.IsGreaterThan(left, right);

            result.Should().Be(expected);
        }
Example #4
0
            /// <summary>
            /// 版本信息
            /// </summary>
            /// <param name="version"></param>
            public VersionData(string version)
            {
                var match = VersionMatcher.Match(version);

                Major         = int.Parse(match.Groups["major"].ToString());
                Minor         = int.Parse(match.Groups["minor"].ToString());
                Revised       = int.Parse(match.Groups["revised"].ToString());
                PreRelease    = match.Groups["pre_release"].ToString();
                BuildMetadata = match.Groups["build_metadata"].ToString();
            }
        protected override Result RunCore(IProductServer <ProductStatus> client, Argument[] args)
        {
            var actualVersion   = GetVersion(client);
            var expectedVersion = FindVersion(args);

            Logger.Info($"{_productName} is on version {actualVersion}. Expected version is {expectedVersion}");
            return(VersionMatcher.DoVersionsMatch(expectedVersion, actualVersion)
                ? Result.Successful()
                : Result.Failure(
                       $"Expecting {_productName} to be on version {expectedVersion} but instead it is on version {actualVersion}"));
        }
        public void TryParse(string source, string output, bool parsed)
        {
            var versionMatcher = new VersionMatcher(NullLogger <VersionMatcher> .Instance);
            var result         = versionMatcher.TryParse(source, out var version);

            result.Should().Be(parsed);

            var versionString = version?.ToString();

            versionString.Should().Be(output);
        }
Example #7
0
        public Result InstallOrUpgrade(string version, IMessagePresenter presenter)
        {
            if (!_installer.IsStaged(version))
            {
                var errorMessage = $"Could not install {_name} {version} because it is not yet staged. Stage it first, then install it.";
                presenter.ShowMessage(errorMessage);
                return(Result.Failure(errorMessage));
            }
            var  productInstallerMetaData = FindProductInstallationMetaData();
            bool isInstalled = productInstallerMetaData != null;

            if (isInstalled)
            {
                if (VersionMatcher.DoVersionsMatch(version, InstalledVersion.ToString()))
                {
                    presenter.ShowMessage($"Since {productInstallerMetaData.DisplayName} is already installed at the same version, we won't install it");
                    return(Result.Successful());
                }
                presenter.ShowMessage(
                    $"Since {productInstallerMetaData.DisplayName} is already installed, uninstalling it");
                var uninstallResult = _installer.Uninstall(ProductCode);
                if (uninstallResult.IsFailed)
                {
                    presenter.ShowMessage($"Uninstall failed, so {_name} cannot be installed on this machine");
                    return(uninstallResult);
                }
                if (IsInstalled)
                {
                    presenter.ShowMessage(
                        $"{_name} is still installed on this machine after the uninstall, so we cannot install");
                    return(Result.Failure($"Uninstall of {_name} failed"));
                }
            }
            else
            {
                presenter.ShowMessage($"{_name} is not installed, so installing it for the first time");
            }
            presenter.ShowMessage($"Installing {_name} {version}");
            var result = _installer.Install(version);

            if (result.IsFailed)
            {
                Logger.Info($"Could not install {_name} {version} because of an error: {result}");
                presenter.ShowMessage($"Could not install {_name} {version}. Make sure your server is running as an administrator");
            }
            else if (!IsInstalled)
            {
                presenter.ShowMessage($"Installer for {_name} {version} ran successfully, but it is still not installed. Make sure your server has rights to install {_name} for all users (Administrator rights).");
                return(Result.Failure(
                           $"Expecting {_name} to be installed after running the installer, but it is not installed"));
            }
            Logger.Info($"Result of install {_name} {version} is {result}");
            return(result);
        }
Example #8
0
        public async Task SearchByVersionManual(string input, int count)
        {
            var versionMatcher = new VersionMatcher(NullLogger <VersionMatcher> .Instance);
            var handler        = new SearchVersionHandler(NullLogger <SearchVersionHandler> .Instance, versionMatcher);

            var command = new SearchVersionCommand {
                Version = input
            };

            var results = await handler.Handle(command, CancellationToken.None);

            results.Should().NotBeNullOrEmpty();

            var list = results.ToList();

            list.Count.Should().Be(count);
        }
Example #9
0
 public void DoVersionsMatch_ShouldBeFalseWhenFirstDigitDifferentAndLastDigitDifferent()
 {
     VersionMatcher.DoVersionsMatch("13.2.1", "12.2.1.1").Should()
     .BeFalse("because first digit is different");
 }
Example #10
0
 public void DoVersionsMatch_ShouldBeTrueWhenLastDigitDifferent()
 {
     VersionMatcher.DoVersionsMatch("12.2.1", "12.2.1.1").Should()
     .BeTrue("because only the last digit is different");
 }
Example #11
0
 public void DoVersionsMatch_ShouldBeFalseWhenDifferent()
 {
     VersionMatcher.DoVersionsMatch("12.2.1", "12.2.2").Should()
     .BeFalse("because the versions are different");
 }
Example #12
0
 public static IMatcher<Version> VersionRange(VersionMatcher expect)
 {
     return Matchers.Function<Version>(
         (actual) => expect.Match(actual),
         () => "AVersion matching version range " + expect);
 }