Exemplo n.º 1
0
        public void PublishToBothSymbolServerTest()
        {
            var publishTask           = new PublishArtifactsInManifestV3();
            var feedConfigsForSymbols = new HashSet <TargetFeedConfig>();

            feedConfigsForSymbols.Add(new TargetFeedConfig(
                                          TargetFeedContentType.Symbols,
                                          "testUrl",
                                          FeedType.AzureStorageFeed,
                                          SymWebToken,
                                          string.Empty,
                                          AssetSelection.All,
                                          isolated: true,
                                          @internal: false,
                                          allowOverwrite: true,
                                          SymbolTargetType.SymWeb));
            feedConfigsForSymbols.Add(new TargetFeedConfig(
                                          TargetFeedContentType.Symbols,
                                          TargetUrl,
                                          FeedType.AzDoNugetFeed,
                                          MsdlToken,
                                          string.Empty,
                                          AssetSelection.All,
                                          isolated: true,
                                          @internal: false,
                                          allowOverwrite: true,
                                          SymbolTargetType.Msdl));
            Dictionary <string, string> test =
                publishTask.GetTargetSymbolServers(feedConfigsForSymbols, MsdlToken, SymWebToken);

            Assert.True(
                test.ContainsKey(Msdl));
            Assert.True(test.ContainsKey(SymWeb));
            Assert.True(test.Count == 2);
        }
Exemplo n.º 2
0
        public void DownloadFileAsyncSucceedsForValidUrl()
        {
            var buildEngine = new MockBuildEngine();
            var publishTask = new PublishArtifactsInManifestV3
            {
                BuildEngine = buildEngine,
            };

            var testFile        = Path.Combine("Symbols", "test.txt");
            var responseContent = TestInputs.ReadAllBytes(testFile);
            var response        = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(responseContent)
            };

            using HttpClient client = FakeHttpClient.WithResponses(response);
            var path = TestInputs.GetFullPath(Guid.NewGuid().ToString());

            var test = publishTask.DownloadFileAsync(
                client,
                PublishArtifactsInManifestBase.ArtifactName.BlobArtifacts,
                "1234",
                "test.txt",
                path);

            Assert.True(File.Exists(path));
            publishTask.DeleteTemporaryFiles(path);
            publishTask.DeleteTemporaryDirectory(path);
        }
Exemplo n.º 3
0
        public void TemporarySymbolsDirectoryTest()
        {
            var publishTask = new PublishArtifactsInManifestV3();
            var path        = TestInputs.GetFullPath("Test");

            publishTask.EnsureTemporarySymbolDirectoryExists(path);
            Assert.True(Directory.Exists(path));
            publishTask.DeleteSymbolTemporaryDirectory(path);
            Assert.False(Directory.Exists(path));
        }
Exemplo n.º 4
0
        public void TemporarySymbolDirectoryDoesNotExists()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifestV3()
            {
                BuildEngine = buildEngine,
            };
            var path    = TestInputs.GetFullPath("Symbol");
            var publish = task.HandleSymbolPublishingAsync(path, MsdlToken, SymWebToken, "", path, false);

            Assert.True(task.Log.HasLoggedErrors);
        }
Exemplo n.º 5
0
        public async Task TemporarySymbolDirectoryDoesNotExists()
        {
            var buildEngine = new MockBuildEngine();
            var task        = new PublishArtifactsInManifestV3()
            {
                BuildEngine = buildEngine,
            };
            var path       = TestInputs.GetFullPath("Symbol");
            var buildAsset = new Dictionary <string, HashSet <Asset> >();
            await task.HandleSymbolPublishingAsync(path, MsdlToken, SymWebToken, "", false, buildAsset, null, path);

            Assert.True(task.Log.HasLoggedErrors);
        }
Exemplo n.º 6
0
        public async Task DownloadFailureWhenStatusCodeIsInvalid(HttpStatusCode httpStatus)
        {
            var buildEngine = new MockBuildEngine();
            var publishTask = new PublishArtifactsInManifestV3
            {
                BuildEngine = buildEngine,
            };
            var testFile        = Path.Combine("Symbols", "test.txt");
            var responseContent = TestInputs.ReadAllBytes(testFile);

            publishTask.RetryHandler = new ExponentialRetry()
            {
                MaxAttempts = 3, DelayBase = 1
            };

            var responses = new[]
            {
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                },
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                },
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                }
            };

            using HttpClient client = FakeHttpClient.WithResponses(responses);
            var path = TestInputs.GetFullPath(Guid.NewGuid().ToString());

            var actualError = await Assert.ThrowsAsync <Exception>(() =>
                                                                   publishTask.DownloadFileAsync(
                                                                       client,
                                                                       PublishArtifactsInManifestBase.ArtifactName.BlobArtifacts,
                                                                       "1234",
                                                                       "test.txt",
                                                                       path));

            Assert.Contains($"Failed to download local file '{path}' after {publishTask.RetryHandler.MaxAttempts} attempts.  See inner exception for details.", actualError.Message);
        }
Exemplo n.º 7
0
        public async Task ErrorAfterMaxRetriesToGetContainerId(HttpStatusCode httpStatus)
        {
            var buildEngine = new MockBuildEngine();
            var publishTask = new PublishArtifactsInManifestV3
            {
                BuildEngine = buildEngine,
            };

            publishTask.BuildId      = "1243456";
            publishTask.RetryHandler = new ExponentialRetry()
            {
                MaxAttempts = 3, DelayBase = 1
            };

            var testPackageName = Path.Combine("Symbols", "test.txt");
            var responseContent = TestInputs.ReadAllBytes(testPackageName);
            var responses       = new[]
            {
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                },
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                },
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                }
            };

            using HttpClient client = FakeHttpClient.WithResponses(responses);

            var actualError = await Assert.ThrowsAsync <Exception>(() =>
                                                                   publishTask.GetContainerIdAsync(
                                                                       client,
                                                                       PublishArtifactsInManifestBase.ArtifactName.BlobArtifacts));

            Assert.Contains($"Failed to get container id after {publishTask.RetryHandler.MaxAttempts} attempts.  See inner exception for details,", actualError.Message);
        }
Exemplo n.º 8
0
        public async Task DownloadFileSuccessfulAfterRetryTest(HttpStatusCode httpStatus)
        {
            var buildEngine = new MockBuildEngine();
            var publishTask = new PublishArtifactsInManifestV3
            {
                BuildEngine = buildEngine,
            };
            var testFile        = Path.Combine("Symbols", "test.txt");
            var responseContent = TestInputs.ReadAllBytes(testFile);

            publishTask.RetryHandler = new ExponentialRetry()
            {
                MaxAttempts = 2, DelayBase = 1
            };

            var responses = new[]
            {
                new HttpResponseMessage(httpStatus)
                {
                    Content = new ByteArrayContent(responseContent)
                },
                new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(responseContent)
                }
            };

            using HttpClient client = FakeHttpClient.WithResponses(responses);
            var path = TestInputs.GetFullPath(Guid.NewGuid().ToString());

            await publishTask.DownloadFileAsync(
                client,
                PublishArtifactsInManifestBase.ArtifactName.BlobArtifacts,
                "1234",
                "test.txt",
                path);

            Assert.True(File.Exists(path));
            publishTask.DeleteTemporaryFiles(path);
            publishTask.DeleteTemporaryDirectory(path);
        }
Exemplo n.º 9
0
        public async Task GetContainerIdToDownloadArtifactAsync(PublishArtifactsInManifestBase.ArtifactName artifactName, string containerId)
        {
            var buildEngine = new MockBuildEngine();
            var publishTask = new PublishArtifactsInManifestV3
            {
                BuildEngine = buildEngine,
            };

            publishTask.BuildId = "1243456";
            var testPackageName = Path.Combine("Symbols", "test.txt");
            var responseContent = TestInputs.ReadAllBytes(testPackageName);
            var responses       = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(responseContent)
            };

            using HttpClient client = FakeHttpClient.WithResponses(responses);
            var test = await publishTask.GetContainerIdAsync(
                client,
                artifactName);

            Assert.Equal(containerId, test);
        }
Exemplo n.º 10
0
        public void PublishToSymbolServersTest(SymbolTargetType symbolTargetType, string symbolServer)
        {
            var publishTask           = new PublishArtifactsInManifestV3();
            var feedConfigsForSymbols = new HashSet <TargetFeedConfig>();

            feedConfigsForSymbols.Add(new TargetFeedConfig(
                                          TargetFeedContentType.Symbols,
                                          "TargetUrl",
                                          FeedType.AzureStorageFeed,
                                          MsdlToken,
                                          new List <string>(),
                                          AssetSelection.All,
                                          isolated: true,
                                          @internal: false,
                                          allowOverwrite: true,
                                          symbolTargetType));
            Dictionary <string, string> test =
                publishTask.GetTargetSymbolServers(feedConfigsForSymbols, MsdlToken, SymWebToken);

            Assert.True(
                test.ContainsKey(symbolServer));
            Assert.True(test.Count == 1);
        }
Exemplo n.º 11
0
        public void PublishSymbolApiIsCalledTest()
        {
            var publishTask = new PublishArtifactsInManifestV3();
            var path        = TestInputs.GetFullPath("Symbols");

            string[] fileEntries           = Directory.GetFiles(path);
            var      feedConfigsForSymbols = new HashSet <TargetFeedConfig>();

            feedConfigsForSymbols.Add(new TargetFeedConfig(
                                          TargetFeedContentType.Symbols,
                                          TargetUrl,
                                          FeedType.AzureStorageFeed,
                                          SymWebToken,
                                          string.Empty,
                                          AssetSelection.All,
                                          isolated: true,
                                          @internal: false,
                                          allowOverwrite: true,
                                          SymbolTargetType.SymWeb));
            Dictionary <string, string> test =
                publishTask.GetTargetSymbolServers(feedConfigsForSymbols, MsdlToken, SymWebToken);

            Assert.True(PublishSymbolsHelper.PublishAsync(null,
                                                          path,
                                                          SymWebToken,
                                                          fileEntries,
                                                          fileEntries,
                                                          null,
                                                          365,
                                                          false,
                                                          false,
                                                          null,
                                                          false,
                                                          false,
                                                          false).IsCompleted);
        }