tests/NuGetGallery.FunctionalTests.Core/Helpers/ClientSdkHelper.cs
/// <summary>
/// Checks if the given package version is present in V2. This method bypasses the hijack.
/// </summary>
Checks if the given package version is present in V2. This method bypasses the hijack.
Checks if the given package version is present in V2 . This method bypasses the hijack .
private async Task<bool> CheckIfPackageVersionExistsInV2Async(string packageId, string version, bool? shouldBeListed)
        {
            var sourceUrl = UrlHelper.V2FeedRootUrl;
            var normalizedVersion = NuGetVersion.Parse(version).ToNormalizedString();
            var url = UrlHelper.V2FeedRootUrl + $"/Packages(Id='{packageId}',Version='{normalizedVersion}')?hijack=false";
            using (var httpClient = new System.Net.Http.HttpClient())
            {
                return await VerifyWithRetryAsync(
                    $"Verifying that package {packageId} {version} exists on source {sourceUrl} (non-hijacked).",
                    async () =>
                    {
                        using (var response = await httpClient.GetAsync(url))
                        {
                            if (response.StatusCode == HttpStatusCode.NotFound)
                            {
                                return false;
                            }
                            else if (response.StatusCode == HttpStatusCode.OK)
                            {
                                if (shouldBeListed.HasValue)
                                {
                                    var responseString = await response.Content.ReadAsStringAsync();
                                    var isActuallyListed = !responseString.Contains("<d:Published m:type=\"Edm.DateTime\">1900-01-01T00:00:00</d:Published>");
                                    return shouldBeListed == isActuallyListed;
                                }
                                return true;
                            }
                            response.EnsureSuccessStatusCode();
                            return false;
                        }
                    });
            }
        }
private async Task < bool > CheckIfPackageVersionExistsInV2Async ( string packageId , string version , bool ? shouldBeListed ) { var sourceUrl = UrlHelper . V2FeedRootUrl ; var normalizedVersion = NuGetVersion . Parse ( version ) . ToNormalizedString ( ) ; var url = UrlHelper . V2FeedRootUrl + $" /Packages(Id=' { packageId } ',Version=' { normalizedVersion } ')?hijack=false " ; using ( var httpClient = new System . Net . Http . HttpClient ( ) ) { return await VerifyWithRetryAsync ( $" Verifying that package  { packageId } { version }  exists on source  { sourceUrl }  (non-hijacked). " , async ( ) => { using ( var response = await httpClient . GetAsync ( url ) ) { if ( response . StatusCode == HttpStatusCode . NotFound ) { return false ; } else if ( response . StatusCode == HttpStatusCode . OK ) { if ( shouldBeListed . HasValue ) { var responseString = await response . Content . ReadAsStringAsync ( ) ; var isActuallyListed = ! responseString . Contains ( " \" \" " ) ; return shouldBeListed == isActuallyListed ; } return true ; } response . EnsureSuccessStatusCode ( ) ; return false ; } } ) ; } }
Checks if the given package version is present in V2.
Checks if the given package version is present in V2 .
packageId
string
version
string
shouldBeListed
bool?