public void ReplacesNonLatestFullVersionByNormalizedVersion()
            {
                ClearList();
                var latest = new FilteredVersionProperties("2.0.0", listed: true);

                _list.Upsert(latest);
                _list.Upsert(new FilteredVersionProperties("1.02.0-Alpha.1+git", listed: true));
                var properties = new FilteredVersionProperties("1.2.0.0-ALPHA.1+somethingelse", listed: true);

                var output = _list.Upsert(properties);

                Assert.Equal(SearchIndexChangeType.UpdateVersionList, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.UpdateMetadata(properties.ParsedVersion),
                    HijackIndexChange.SetLatestToFalse(properties.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(latest.ParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(latest.FullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(latest.ParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { properties.FullVersion, latest.FullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(
                    new[] { properties.ParsedVersion, latest.ParsedVersion },
                    _list._versions.Keys.ToArray());
            }
            public void LatestIsNullForEmpty()
            {
                var versions = new FilteredVersionProperties[0];

                var list = new FilteredVersionList(versions);

                Assert.Null(list._latestOrNull);
            }
            protected BaseFacts()
            {
                _initialVersionProperties  = new FilteredVersionProperties(InitialFullVersion, listed: true);
                _unlistedVersionProperties = new FilteredVersionProperties(InitialFullVersion, listed: false);

                var versions = new[] { _initialVersionProperties };

                _list = new FilteredVersionList(versions);
            }
Exemple #4
0
        public LatestIndexChanges Upsert(FilteredVersionProperties addedProperties)
        {
            var ctx = UpdateVersionList(
                (v, p) => _versions[v] = p,
                addedProperties.ParsedVersion,
                addedProperties);

            var searchIndexChangeType = UpsertToSearchIndex(ctx);
            var hijackIndexChanges    = UpsertToHijackIndex(ctx);

            return(new LatestIndexChanges(searchIndexChangeType, hijackIndexChanges));
        }
Exemple #5
0
 public Context(
     NuGetVersion changedVersion,
     FilteredVersionProperties oldProperties,
     FilteredVersionProperties newProperties,
     NuGetVersion oldLatest,
     NuGetVersion newLatest)
 {
     ChangedVersion = changedVersion ?? throw new ArgumentNullException(nameof(changedVersion));
     OldProperties  = oldProperties;
     NewProperties  = newProperties;
     OldLatest      = oldLatest;
     NewLatest      = newLatest;
 }
            public void DeletesLastListedVersion(string version)
            {
                var unlisted = new FilteredVersionProperties(version, listed: false);

                _list.Upsert(unlisted);

                var output = _list.Delete(InitialParsedVersion);

                Assert.Equal(SearchIndexChangeType.Delete, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.Delete(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Null(_list.GetLatestVersionInfo());
                Assert.Null(_list._latestOrNull);
                Assert.Equal(new[] { unlisted.ParsedVersion }, _list._versions.Keys.ToArray());
            }
            public void AddingListedNonLatestVersion()
            {
                var listed = new FilteredVersionProperties(PreviousFullVersion, listed: true);

                var output = _list.Upsert(listed);

                Assert.Equal(SearchIndexChangeType.UpdateVersionList, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.UpdateMetadata(listed.ParsedVersion),
                    HijackIndexChange.SetLatestToFalse(listed.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(InitialFullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(InitialParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { PreviousFullVersion, InitialFullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(new[] { listed.ParsedVersion, InitialParsedVersion }, _list._versions.Keys.ToArray());
            }
Exemple #8
0
        private Context UpdateVersionList(
            Action <NuGetVersion, FilteredVersionProperties> update,
            NuGetVersion version,
            FilteredVersionProperties newProperties)
        {
            var oldLatest = _latestOrNull;

            _versions.TryGetValue(version, out var oldProperties);

            update(version, newProperties);

            _latestOrNull = CalculateLatest();

            return(new Context(
                       version,
                       oldProperties,
                       newProperties,
                       oldLatest,
                       _latestOrNull));
        }
            public void DeletesNonLatestListedVersionWithOneOtherVersion()
            {
                var nonLatest = new FilteredVersionProperties(PreviousFullVersion, listed: true);

                _list.Upsert(nonLatest);

                var output = _list.Delete(nonLatest.ParsedVersion);

                Assert.Equal(SearchIndexChangeType.UpdateVersionList, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.Delete(nonLatest.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(InitialFullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(InitialParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { InitialFullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(new[] { InitialParsedVersion }, _list._versions.Keys.ToArray());
            }
            public void DeletesLatestVersion()
            {
                var latest = new FilteredVersionProperties(NextFullVersion, listed: true);

                _list.Upsert(latest);

                var output = _list.Delete(latest.ParsedVersion);

                Assert.Equal(SearchIndexChangeType.DowngradeLatest, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.Delete(latest.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(InitialFullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(InitialParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { InitialFullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(new[] { InitialParsedVersion }, _list._versions.Keys.ToArray());
            }
            public void AddingUnlistedVersion(string version)
            {
                var unlisted = new FilteredVersionProperties(version, listed: false);

                var output = _list.Upsert(unlisted);

                Assert.Equal(SearchIndexChangeType.UpdateVersionList, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.UpdateMetadata(unlisted.ParsedVersion),
                    HijackIndexChange.SetLatestToFalse(unlisted.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(InitialFullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(InitialParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { InitialFullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(
                    new[] { unlisted.ParsedVersion, InitialParsedVersion }.OrderBy(x => x).ToArray(),
                    _list._versions.Keys.ToArray());
            }
            public void UnlistingLatestWithOtherUnlistedVersions(string version)
            {
                var unlisted = new FilteredVersionProperties(version, listed: false);

                _list.Upsert(unlisted);

                var output = _list.Upsert(_unlistedVersionProperties);

                Assert.Equal(SearchIndexChangeType.Delete, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.UpdateMetadata(InitialParsedVersion),
                    HijackIndexChange.SetLatestToFalse(InitialParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Null(_list.GetLatestVersionInfo());
                Assert.Null(_list._latestOrNull);
                Assert.Equal(
                    new[] { InitialParsedVersion, unlisted.ParsedVersion }.OrderBy(x => x).ToArray(),
                    _list._versions.Keys.ToArray());
            }
            public void AddingFirstListedVersion(string version)
            {
                StartWithUnlisted();
                var listed = new FilteredVersionProperties(version, listed: true);

                var output = _list.Upsert(listed);

                Assert.Equal(SearchIndexChangeType.AddFirst, output.Search);
                Assert.Equal(
                    new[]
                {
                    HijackIndexChange.UpdateMetadata(listed.ParsedVersion),
                    HijackIndexChange.SetLatestToTrue(listed.ParsedVersion),
                },
                    output.Hijack.ToArray());
                Assert.Equal(listed.FullVersion, _list.GetLatestVersionInfo().FullVersion);
                Assert.Equal(listed.ParsedVersion, _list._latestOrNull);
                Assert.Equal(new[] { listed.FullVersion }, _list.GetLatestVersionInfo().ListedFullVersions);
                Assert.Equal(
                    new[] { InitialParsedVersion, listed.ParsedVersion }.OrderBy(x => x).ToArray(),
                    _list._versions.Keys.ToArray());
            }
Exemple #14
0
 public VersionProperties(string fullOrOriginalVersion, VersionPropertiesData data)
 {
     Data     = data ?? throw new ArgumentNullException(nameof(data));
     Filtered = new FilteredVersionProperties(fullOrOriginalVersion, Data.Listed);
 }