public void InstallRuntimeFailsIfNotFound()
        {
            List <RequestResponseHelper> requestResponseHelpers = new List <RequestResponseHelper>()
            {
                new RequestResponseHelper()
                {
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Get, "https://dotnetcli.blob.core.windows.net/dotnet/Runtime/6.0.102/runtime-productVersion.txt"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent("6.0.102")
                    }
                },
                new RequestResponseHelper()
                {
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Head, "https://dotnetcli.blob.core.windows.net/dotnet/Runtime/6.0.102/dotnet-runtime-6.0.102-win-x86.zip"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.NotFound)
                },
                new RequestResponseHelper()
                {
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Get, "https://dotnetbuilds.blob.core.windows.net/public/Runtime/6.0.102/runtime-productVersion.txt"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent("6.0.102")
                    }
                },
                new RequestResponseHelper()
                {
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Head, "https://dotnetbuilds.blob.core.windows.net/public/Runtime/6.0.102/dotnet-runtime-6.0.102-win-x86.zip"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.NotFound)
                }
            };

            var collection = CreateMockServiceCollection(requestResponseHelpers.ToArray());

            MockBuildEngine buildEngineMock = new MockBuildEngine();

            FindDotNetCliPackage task = new FindDotNetCliPackage()
            {
                Channel     = "Current",
                Version     = "6.0.102",
                Runtime     = "win-x86",
                PackageType = "runtime",
                BuildEngine = buildEngineMock
            };

            task.ConfigureServices(collection);

            // Act
            using var provider = collection.BuildServiceProvider();
            task.InvokeExecute(provider).Should().BeFalse();

            // verify we didn't print the sas token
            buildEngineMock.BuildMessageEvents.Should().NotContain(x => Regex.IsMatch(x.Message, @"\?sv=[^ ]+"));

            buildEngineMock.BuildMessageEvents.Should().NotContain(x => x.Message.Contains("is valid."));
        }
        public void IfAuthenticatedFeedReturnsForbiddenFails()
        {
            List <RequestResponseHelper> requestResponseHelpers = new List <RequestResponseHelper>(GetDefaultRequestResponseHelpers());

            requestResponseHelpers.AddRange(new[] {
                new RequestResponseHelper()
                {
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Get, "https://fakeazureaccount.blob.core.windows.net/Runtime/6.0.102/runtime-productVersion.txt"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent("6.0.102")
                    }
                },
                new RequestResponseHelper()
                {
                    // If your sas token is invalid or missing, azure storage returns 403 (Forbidden)
                    RequestMessage  = new HttpRequestMessage(HttpMethod.Head, "https://fakeazureaccount.blob.core.windows.net/Runtime/6.0.102/dotnet-runtime-6.0.102-win-x86.zip"),
                    ResponseMessage = new HttpResponseMessage(HttpStatusCode.Forbidden)
                }
            });

            var collection = CreateMockServiceCollection(requestResponseHelpers.ToArray());
            Dictionary <string, string> metadata = new Dictionary <string, string>()
            {
                { "SasToken", "bar" }
            };

            ITaskItem[] additionalFeed = new TaskItem[]
            {
                new TaskItem("https://fakeazureaccount.blob.core.windows.net", metadata)
            };
            MockBuildEngine buildEngineMock = new MockBuildEngine();

            FindDotNetCliPackage task = new FindDotNetCliPackage()
            {
                Channel     = "Current",
                Version     = "6.0.102",
                Runtime     = "win-x86",
                PackageType = "runtime",
                BuildEngine = buildEngineMock
            };

            task.AdditionalFeeds = additionalFeed;
            task.ConfigureServices(collection);

            // Act
            using var provider = collection.BuildServiceProvider();
            task.InvokeExecute(provider).Should().BeFalse();

            // verify we reported being unable to access container
            buildEngineMock.BuildMessageEvents.Should().Contain(x => x.Message.Contains("Response status code does not indicate success: 403 (Forbidden)."));
            // verify we didn't print the sas token
            buildEngineMock.BuildMessageEvents.Should().NotContain(x => Regex.IsMatch(x.Message, @"\?sv=[^ ]+"));

            buildEngineMock.BuildMessageEvents.Should().NotContain(x => x.Message.Contains("is valid."));
        }