private bool IsNewVersion(Version version, Version currentVersion)
 {
     return((version?.Major > currentVersion?.Major) ||
            (version?.Major == currentVersion?.Major && version?.Minor > currentVersion?.Minor) ||
            (version?.Major == currentVersion?.Major && version?.Minor == currentVersion?.Minor && version?.Increment > currentVersion?.Increment) ||
            IsNewRefDataVersion(version?.ReferenceDataVersion, currentVersion?.ReferenceDataVersion));
 }
        public async Task <ApplicationVersionResult> GetLatestApplicationVersion(Version currentVersion)
        {
            _logger.LogInfo("Retrieving Application versions from SLD API.");

            var result = new ApplicationVersionResult();

            try
            {
                var applicationVersions = await _versionClient.GetAsync();

                var newerVersion = GetNewerApplicationVersion(currentVersion, applicationVersions.Versions);

                _logger.LogInfo("Finished retrieving Application versions from SLD API.");

                result = newerVersion == null
                ? null : _applicationVersionResultFactory.GetResult(
                    newerVersion.VersionName,
                    newerVersion.ReleaseDateTime,
                    applicationVersions.Url,
                    newerVersion.ReferenceDataVersion?.VersionName,
                    newerVersion.ReferenceDataVersion?.FileName);
            }
            catch (Exception e)
            {
                _logger.LogError("Error retrieving Application versions from SLD API.", e);
            }

            return(result);
        }
        private Version GetNewerApplicationVersion(Version currentVersion, IEnumerable <Version> availableVersions)
        {
            var newVersion = availableVersions
                             .OrderByDescending(v => v.Major).ThenByDescending(v => v.Minor).ThenByDescending(v => v.Increment)
                             .FirstOrDefault(v => IsNewVersion(v, currentVersion));

            return(newVersion ?? currentVersion);
        }
        public async Task CheckForUpdates_Returns_Fasle_And_Does_Not_Send_Message()
        {
            var url           = "test";
            var versionNumber = "1.0.0.0";
            var releaseDate   = new DateTime(2020, 11, 10, 8, 0, 0);
            var versionSplit  = versionNumber.Split('.');
            var major         = Convert.ToInt32(versionSplit[0]);
            var minor         = Convert.ToInt32(versionSplit[1]);
            var increment     = Convert.ToInt32(versionSplit[2]);

            var version = new Version
            {
                VersionName = versionNumber,
                Major       = major,
                Minor       = minor,
                Increment   = increment
            };

            var applicationVersionResult = new ApplicationVersionResult
            {
                ApplicationVersion = versionNumber,
                Url             = url,
                ReleaseDateTime = releaseDate
            };

            var versionMessage = new VersionMessage
            {
                ApplicationVersion = applicationVersionResult
            };

            var versionMessageFactoryMock = new Mock <IVersionMessageFactory>();

            versionMessageFactoryMock
            .Setup(m => m.GetVersionMessage(applicationVersionResult))
            .Returns(versionMessage);

            var versionFactoryMock = new Mock <IVersionFactory>();

            versionFactoryMock
            .Setup(m => m.GetVersion(versionNumber, It.IsAny <string>()))
            .Returns(version);

            var versionInformationService = new Mock <IReleaseVersionInformationService>();

            versionInformationService
            .Setup(m => m.VersionNumber)
            .Returns(versionNumber);

            var versionService = new Mock <IVersionService>();

            versionService
            .Setup(m => m.GetLatestApplicationVersion(version))
            .ReturnsAsync(default(ApplicationVersionResult));

            var service = GetVersionMediatorService(
                versionFactoryMock.Object,
                versionInformationService.Object,
                versionService.Object);

            var found = service.GetCurrentApplicationVersion();

            found.VersionName.Should().Be(version.VersionName);
            found.ReleaseDateTime.Should().Be(version.ReleaseDateTime);
            found.Major.Should().Be(version.Major);
            found.Minor.Should().Be(version.Minor);
            found.Increment.Should().Be(version.Increment);
        }
コード例 #5
0
        public async Task GetLatestApplicationVersion_Correctly_Returns_Null_When_No_Newer_Version(
            int currentMajor,
            int currentMinor,
            int currentIncrement)
        {
            var versionNumber        = "1.1.1.1";
            var releaseDateTime      = new DateTime(2020, 11, 19, 8, 0, 0);
            var url                  = "foo.com";
            var major                = 1;
            var minor                = 1;
            var increment            = 1;
            var refDataVersionNumber = "1.1.1.1";
            var refDataFileName      = "FISReferenceData.1.1.1.1";

            var currentVersion = new Version
            {
                VersionName          = "1.0.0.0",
                ReleaseDateTime      = releaseDateTime,
                Major                = currentMajor,
                Minor                = currentMinor,
                Increment            = currentIncrement,
                ReferenceDataVersion = new Models.ReferenceData
                {
                    FileName    = "FISReferenceData.1.1.1.1",
                    Major       = currentMajor,
                    Minor       = currentMinor,
                    Increment   = currentIncrement,
                    VersionName = refDataVersionNumber
                }
            };

            var applicationVersion = GetApplicationVersion(
                versionNumber,
                url,
                releaseDateTime,
                releaseDateTime,
                major,
                minor,
                increment,
                refDataVersionNumber);

            var applicationVersionResult = new ApplicationVersionResult
            {
                ApplicationVersion = versionNumber,
                Url                         = url,
                ReleaseDateTime             = releaseDateTime,
                LatestReferenceDataVersion  = refDataVersionNumber,
                LatestReferenceDataFileName = refDataFileName
            };

            var versionClientMock = new Mock <IApplicationVersionResultClient>();

            versionClientMock
            .Setup(m => m.GetAsync())
            .ReturnsAsync(applicationVersion);

            var versionResultFactory = new Mock <IAPIResultFactory <ApplicationVersionResult> >();

            versionResultFactory
            .Setup(m => m.GetResult(versionNumber, releaseDateTime, url, refDataVersionNumber, refDataFileName))
            .Returns(applicationVersionResult);

            var service = NewService(versionClientMock.Object, versionResultFactory.Object);

            var result = await service.GetLatestApplicationVersion(currentVersion);

            result.Should().BeNull();
        }