public void Add_WithTrustAndUnsupportPackageSource_Fail()
        {
            using (var preserver = new DefaultConfigurationFilePreserver())
                using (var mockServer = new MockServer())
                {
                    // Arrange
                    var baseUrl = mockServer.Uri.TrimEnd(new[] { '/' });
                    var builder = new MockResponseBuilder(baseUrl);

                    mockServer.Get.Add(
                        builder.GetV3IndexPath(),
                        request =>
                    {
                        return(new Action <HttpListenerResponse>(response =>
                        {
                            var mockResponse = builder.BuildV3IndexResponse(mockServer);
                            response.ContentType = mockResponse.ContentType;
                            MockServer.SetResponseContent(response, mockResponse.Content);
                        }));
                    });

                    var nugetexe = Util.GetNuGetExePath();
                    var args     = new string[] {
                        "sources",
                        "Add",
                        "-Name",
                        "test_source",
                        "-Source",
                        builder.GetV3Source(),
                        "-Trust"
                    };
                    var root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());

                    mockServer.Start();

                    // Act
                    var result = CommandRunner.Run(nugetexe, root, string.Join(" ", args), true);

                    // Assert'
                    mockServer.Stop();
                    Assert.Equal(1, result.Item1);
                    Assert.True(result.Item3.Contains("Package source with name 'test_source' cannot be added as a trusted repository because it does not support repository signing."));
                }
        }
示例#2
0
        private void InitializeServer()
        {
            Get.Add(
                _builder.GetV3IndexPath(),
                request =>
            {
                return(new Action <HttpListenerResponse>(response =>
                {
                    var mockResponse = _builder.BuildV3IndexResponse(Uri);
                    response.ContentType = mockResponse.ContentType;
                    SetResponseContent(response, mockResponse.Content);
                }));
            });

            Get.Add("/", request =>
            {
                return(ServerHandlerV3(request));
            });
        }