Ejemplo n.º 1
0
        private IHttpClientFactory CreateHttpClientFactory(IGitFileRef imageOptionsFileRef, ImageArtifactDetails imageArtifactDetails)
        {
            string tempDir = Directory.CreateDirectory(
                Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())).FullName;

            this.foldersToDelete.Add(tempDir);

            string repoPath = Directory.CreateDirectory(
                Path.Combine(tempDir, $"{imageOptionsFileRef.Repo}-{imageOptionsFileRef.Branch}")).FullName;

            string imageInfoPath = Path.Combine(repoPath, imageOptionsFileRef.Path);

            File.WriteAllText(imageInfoPath, JsonConvert.SerializeObject(imageArtifactDetails));

            string repoZipPath = Path.Combine(tempDir, "repo.zip");

            ZipFile.CreateFromDirectory(repoPath, repoZipPath, CompressionLevel.Fastest, true);

            Dictionary <string, HttpResponseMessage> responses = new Dictionary <string, HttpResponseMessage>
            {
                {
                    GitHelper.GetArchiveUrl(imageOptionsFileRef).ToString(),
                    new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.OK,
                        Content    = new ByteArrayContent(File.ReadAllBytes(repoZipPath))
                    }
                }
            };

            HttpClient client = new HttpClient(new TestHttpMessageHandler(responses));

            Mock <IHttpClientFactory> httpClientFactoryMock = new Mock <IHttpClientFactory>();

            httpClientFactoryMock
            .Setup(o => o.GetClient())
            .Returns(client);

            return(httpClientFactoryMock.Object);
        }
Ejemplo n.º 2
0
 public static Uri GetBlobUrl(IGitFileRef fileRef) =>
 new Uri($"https://github.com/{fileRef.Owner}/{fileRef.Repo}/blob/{fileRef.Branch}/{fileRef.Path}");