From 28d1e89526538d954563356073eb49da4390ff73 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Wed, 18 Jan 2017 22:33:17 -0800 Subject: [PATCH 1/3] Fix not including delisted flag in case allversions and prerelease are false --- .../LegacyFeed/V2FeedListResource.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/NuGet.Core/NuGet.Protocol.Core.v3/LegacyFeed/V2FeedListResource.cs b/src/NuGet.Core/NuGet.Protocol.Core.v3/LegacyFeed/V2FeedListResource.cs index 7e3228a004f..c613fd2c147 100644 --- a/src/NuGet.Core/NuGet.Protocol.Core.v3/LegacyFeed/V2FeedListResource.cs +++ b/src/NuGet.Core/NuGet.Protocol.Core.v3/LegacyFeed/V2FeedListResource.cs @@ -64,7 +64,10 @@ public async override Task> ListAsync( { filter = new SearchFilter(includePrerelease: false, filter: SearchFilterType.IsLatestVersion) - { OrderBy = SearchOrderBy.Id }; + { + OrderBy = SearchOrderBy.Id, + IncludeDelisted = includeDelisted + }; } } } @@ -95,7 +98,10 @@ public async override Task> ListAsync( { filter = new SearchFilter(includePrerelease: false, filter: SearchFilterType.IsLatestVersion) - { OrderBy = SearchOrderBy.Id }; + { + OrderBy = SearchOrderBy.Id, + IncludeDelisted = includeDelisted + }; } } From 49bf525a96847c299b760b1ddfcedee0eaff3b25 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Thu, 19 Jan 2017 10:03:35 -0800 Subject: [PATCH 2/3] Add tests with only delisted response --- .../V2FeedListResourceTests.cs | 91 +++++++ .../compiler/resources/6DelistedEntries.xml | 253 ++++++++++++++++++ 2 files changed, 344 insertions(+) create mode 100644 test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/compiler/resources/6DelistedEntries.xml diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs index ca8acfb3591..07dd62687b3 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs @@ -20,6 +20,97 @@ namespace NuGet.Protocol.Tests { public class V2FeedListResourceTests { + + [Fact] + public async Task TestListDelistedNoPrereleaseNotAllVersionsDelistedOnlyResponse() + { + // Arrange + var serviceAddress = TestUtility.CreateServiceAddress() + "api/v2"; + + var responses = new Dictionary(); + + responses.Add(serviceAddress + "/Search()?$filter=IsLatestVersion&$orderby=Id&searchTerm='newton'&targetFramework=''&includePrerelease=false&$skip=0&$top=30", + TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.6DelistedEntries.xml", GetType())); + responses.Add(serviceAddress, string.Empty); + responses.Add(serviceAddress + "/$metadata", + TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.MetadataTT.xml", GetType())); + + var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); + + var parser = new V2FeedParser(httpSource, serviceAddress); + var legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress); + var resource = new V2FeedListResource(parser, legacyResource, serviceAddress); + + + var enumerable = await resource.ListAsync(searchTerm: "newton", + prerelease: false, allVersions: false, includeDelisted: true, logger: NullLogger.Instance, token: CancellationToken.None); + + int ExpectedCount = 6; + int ActualCount = 0; + var enumerator = enumerable.GetEnumeratorAsync(); + + + while (await enumerator.MoveNextAsync()) + { + if (enumerator.Current != null) + { + ActualCount++; + Assert.True(ExpectedCount >= ActualCount, "Too many results"); + } + else + { + Assert.False(false, "Null Value, this shouldn't happen."); + } + } + + Assert.True(ExpectedCount == ActualCount, "Expected was " + ExpectedCount + " but actual was " + ActualCount); + } + + [Fact] + public async Task TestListNoDelistedNoPrereleaseNotAllVersionsDelistedOnlyResponse() + { + // Arrange + var serviceAddress = TestUtility.CreateServiceAddress() + "api/v2"; + + var responses = new Dictionary(); + + responses.Add(serviceAddress + "/Search()?$filter=IsLatestVersion&$orderby=Id&searchTerm='newton'&targetFramework=''&includePrerelease=false&$skip=0&$top=30", + TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.6DelistedEntries.xml", GetType())); + responses.Add(serviceAddress, string.Empty); + responses.Add(serviceAddress + "/$metadata", + TestUtility.GetResource("NuGet.Protocol.Core.v3.Tests.compiler.resources.MetadataTT.xml", GetType())); + + var httpSource = new TestHttpSource(new PackageSource(serviceAddress), responses); + + var parser = new V2FeedParser(httpSource, serviceAddress); + var legacyResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceAddress); + var resource = new V2FeedListResource(parser, legacyResource, serviceAddress); + + + var enumerable = await resource.ListAsync(searchTerm: "newton", + prerelease: false, allVersions: false, includeDelisted: false, logger: NullLogger.Instance, token: CancellationToken.None); + + int ExpectedCount = 0; + int ActualCount = 0; + var enumerator = enumerable.GetEnumeratorAsync(); + + + while (await enumerator.MoveNextAsync()) + { + if (enumerator.Current != null) + { + ActualCount++; + Assert.True(ExpectedCount >= ActualCount, "Too many results"); + } + else + { + Assert.False(false, "Null Value, this shouldn't happen."); + } + } + + Assert.True(ExpectedCount == ActualCount, "Expected was " + ExpectedCount + " but actual was " + ActualCount); + } + [Fact] public async Task TestListNoDelistedNoPrereleaseNotAllVersions() { diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/compiler/resources/6DelistedEntries.xml b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/compiler/resources/6DelistedEntries.xml new file mode 100644 index 00000000000..b44a2161baf --- /dev/null +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/compiler/resources/6DelistedEntries.xml @@ -0,0 +1,253 @@ + + + http://schemas.datacontract.org/2004/07/ + + <updated>2017-01-18T21:15:38Z</updated> + <link rel="self" href="https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages" /> + <entry> + <id>https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3_V2Package10',Version='2.0.0')</id> + <category term="Microsoft.VisualStudio.Services.NuGet.Server.Controllers.V2.ServerV2FeedPackage" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> + <link rel="edit" href="https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3_V2Package10',Version='2.0.0')" /> + <link rel="self" href="https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3_V2Package10',Version='2.0.0')" /> + <title type="text">V40RC3_V2Package10 + 0001-01-02T00:00:00Z + + + + + + V40RC3_V2Package10 + 2.0.0 + 2.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + + https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3_V2Package20',Version='1.0.0') + + + + V40RC3_V2Package20 + 0001-01-02T00:00:00Z + + + + + + V40RC3_V2Package20 + 1.0.0 + 1.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + + https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3_V2Package30',Version='1.0.0') + + + + V40RC3_V2Package30 + 0001-01-02T00:00:00Z + + + + + + V40RC3_V2Package30 + 1.0.0 + 1.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + + https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3Package10',Version='2.0.0') + + + + V40RC3Package10 + 0001-01-02T00:00:00Z + + + + + + V40RC3Package10 + 2.0.0 + 2.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + + https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3Package20',Version='1.0.0') + + + + V40RC3Package20 + 0001-01-02T00:00:00Z + + + + + + V40RC3Package20 + 1.0.0 + 1.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + + https://_packaging/224e3f52-6a96-4fef-a1c9-cb56acee9375/nuget/v2/Packages(Id='V40RC3Package30',Version='1.0.0') + + + + V40RC3Package30 + 0001-01-02T00:00:00Z + + + + + + V40RC3Package30 + 1.0.0 + 1.0.0 + + + 0001-01-02T00:00:00 + + testdesc + 0 + + true + true + false + + 0001-01-02T00:00:00 + 0001-01-02T00:00:00 + 0 + + + false + + + + + 0001-01-02T00:00:00 + + true + + + \ No newline at end of file From 51a442d344b1d204896163a84ebc64247ff12ab3 Mon Sep 17 00:00:00 2001 From: Nikolche Kolev Date: Thu, 19 Jan 2017 14:16:05 -0800 Subject: [PATCH 3/3] use assert equals for cleaner code --- .../V2FeedListResourceTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs index 07dd62687b3..940ad279381 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Core.v3.Tests/V2FeedListResourceTests.cs @@ -63,7 +63,7 @@ public async Task TestListDelistedNoPrereleaseNotAllVersionsDelistedOnlyResponse } } - Assert.True(ExpectedCount == ActualCount, "Expected was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -108,7 +108,7 @@ public async Task TestListNoDelistedNoPrereleaseNotAllVersionsDelistedOnlyRespon } } - Assert.True(ExpectedCount == ActualCount, "Expected was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -155,7 +155,7 @@ public async Task TestListNoDelistedNoPrereleaseNotAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -200,7 +200,7 @@ public async Task TestListNoDelistedPrereleaseNotAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -247,7 +247,7 @@ public async Task TestListDelistedPrereleaseNoAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } @@ -293,7 +293,7 @@ public async Task TestListNoDelistedPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -341,7 +341,7 @@ public async Task TestListDelistedPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -388,7 +388,7 @@ public async Task TestListNoDelistedNoPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } }