internal static async Task <HttpFileSystemBasedFindPackageByIdResourceTest> CreateAsync(TestEnvironmentVariableReader testEnvironmentVariableReader = null)
            {
                var packageIdentity = new PackageIdentity(id: "DeepEqual", version: NuGetVersion.Parse("1.4.0"));
                var testDirectory   = TestDirectory.Create();
                var packageSource   = new PackageSource("http://unit.test/v3-flatcontainer");
                var package         = await SimpleTestPackageUtility.CreateFullPackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString());

                var packageBytes = File.ReadAllBytes(package.FullName);

                var responses = new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > >
                {
                    {
                        $"{packageSource.Source}/deepequal/index.json",
                        request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new TestContent(JsonData.DeepEqualFlatContainerIndex)
                        })
                    },
                    {
                        $"{packageSource.Source}/deepequal/1.4.0/deepequal.1.4.0.nupkg",
                        _ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new ByteArrayContent(packageBytes)
                        })
                    },
                    {
                        $"{packageSource.Source}/a/index.json",
                        request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound))
                    },
                    {
                        $"{packageSource.Source}/socketexception/index.json",
                        request =>
                        {
                            SocketExceptionCallsMade += 1;
                            throw new Exception("Oh this isn't going well", new IOException("This is what TCP hang-ups look like", new SocketException(123)));
                        }
                    },
                };

                var baseUris = new List <Uri>()
                {
                    packageSource.SourceUri
                };
                var httpSource = new TestHttpSource(packageSource, responses);
                var resource   = new HttpFileSystemBasedFindPackageByIdResource(
                    baseUris,
                    httpSource,
                    testEnvironmentVariableReader != null ? testEnvironmentVariableReader : EnvironmentVariableWrapper.Instance);

                return(new HttpFileSystemBasedFindPackageByIdResourceTest(
                           resource,
                           package,
                           packageIdentity,
                           new SourceCacheContext(),
                           httpSource,
                           testDirectory));
            }
            internal static async Task <HttpFileSystemBasedFindPackageByIdResourceTest> CreateAsync()
            {
                var packageIdentity = new PackageIdentity(id: "DeepEqual", version: NuGetVersion.Parse("1.4.0"));
                var testDirectory   = TestDirectory.Create();
                var packageSource   = new PackageSource("http://unit.test/v3-flatcontainer");
                var package         = await SimpleTestPackageUtility.CreateFullPackageAsync(
                    testDirectory.Path,
                    packageIdentity.Id,
                    packageIdentity.Version.ToNormalizedString());

                var packageBytes = File.ReadAllBytes(package.FullName);

                var responses = new Dictionary <string, Func <HttpRequestMessage, Task <HttpResponseMessage> > >
                {
                    {
                        $"{packageSource.Source}/deepequal/index.json",
                        request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new TestContent(JsonData.DeepEqualFlatContainerIndex)
                        })
                    },
                    {
                        $"{packageSource.Source}/deepequal/1.4.0/deepequal.1.4.0.nupkg",
                        _ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                        {
                            Content = new ByteArrayContent(packageBytes)
                        })
                    },
                    {
                        $"{packageSource.Source}/a/index.json",
                        request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound))
                    }
                };

                var baseUris = new List <Uri>()
                {
                    packageSource.SourceUri
                };
                var httpSource = new TestHttpSource(packageSource, responses);
                var resource   = new HttpFileSystemBasedFindPackageByIdResource(
                    baseUris,
                    httpSource);

                return(new HttpFileSystemBasedFindPackageByIdResourceTest(
                           resource,
                           package,
                           packageIdentity,
                           new SourceCacheContext(),
                           httpSource,
                           testDirectory));
            }
 private HttpFileSystemBasedFindPackageByIdResourceTest(
     HttpFileSystemBasedFindPackageByIdResource resource,
     FileInfo package,
     PackageIdentity packageIdentity,
     SourceCacheContext sourceCacheContext,
     TestHttpSource httpSource,
     TestDirectory testDirectory)
 {
     Resource           = resource;
     Package            = package;
     PackageIdentity    = packageIdentity;
     SourceCacheContext = sourceCacheContext;
     _httpSource        = httpSource;
     TestDirectory      = testDirectory;
 }