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 + }; } } 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..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 @@ -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.Equal(ExpectedCount, 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.Equal(ExpectedCount, ActualCount); + } + [Fact] public async Task TestListNoDelistedNoPrereleaseNotAllVersions() { @@ -64,7 +155,7 @@ public async Task TestListNoDelistedNoPrereleaseNotAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -109,7 +200,7 @@ public async Task TestListNoDelistedPrereleaseNotAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -156,7 +247,7 @@ public async Task TestListDelistedPrereleaseNoAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } @@ -202,7 +293,7 @@ public async Task TestListNoDelistedPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -250,7 +341,7 @@ public async Task TestListDelistedPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } [Fact] @@ -297,7 +388,7 @@ public async Task TestListNoDelistedNoPrereleaseAllVersions() } } - Assert.True(ExpectedCount == ActualCount, "Expect was " + ExpectedCount + " but actual was " + ActualCount); + Assert.Equal(ExpectedCount, ActualCount); } } 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