コード例 #1
0
        public async Task Initialize_Succeeds()
        {
            using (var test = await PluginTest.CreateAsync())
            {
                Assert.Equal(PluginProtocolConstants.CurrentVersion, test.Plugin.Connection.ProtocolVersion);

                // Send canned response
                var responseSenderTask = Task.Run(() => test.ResponseSender.StartSendingAsync(test.CancellationToken));
                await test.ResponseSender.SendAsync(
                    MessageType.Response,
                    MessageMethod.Initialize,
                    new InitializeResponse(MessageResponseCode.Success));

                var clientVersion = MinClientVersionUtility.GetNuGetClientVersion().ToNormalizedString();
                var culture       = CultureInfo.CurrentCulture.Name;
                var payload       = new InitializeRequest(
                    clientVersion,
                    culture,
                    PluginConstants.RequestTimeout);

                var response = await test.Plugin.Connection.SendRequestAndReceiveResponseAsync <InitializeRequest, InitializeResponse>(
                    MessageMethod.Initialize,
                    payload,
                    test.CancellationToken);

                Assert.NotNull(response);
                Assert.Equal(MessageResponseCode.Success, response.ResponseCode);
            }
        }
コード例 #2
0
ファイル: PluginManager.cs プロジェクト: dslzuha/nugetclient
        private static async Task InitializePluginAsync(
            IPlugin plugin,
            TimeSpan requestTimeout,
            CancellationToken cancellationToken)
        {
            var clientVersion = MinClientVersionUtility.GetNuGetClientVersion().ToNormalizedString();
            var culture       = GetCurrentCultureName();

            var payload = new InitializeRequest(
                clientVersion,
                culture,
                requestTimeout);

            var response = await plugin.Connection.SendRequestAndReceiveResponseAsync <InitializeRequest, InitializeResponse>(
                MessageMethod.Initialize,
                payload,
                cancellationToken);

            if (response != null && response.ResponseCode != MessageResponseCode.Success)
            {
                throw new PluginException(Strings.Plugin_InitializationFailed);
            }

            plugin.Connection.Options.SetRequestTimeout(requestTimeout);
        }
コード例 #3
0
        public async Task EnsurePackageCompatibilityAsync_WithLowerMinClientVersion_Fails()
        {
            // Arrange
            var tc = new TestContext();

            tc.MinClientVersion = new NuGetVersion("10.0.0");
            var result = new DownloadResourceResult(Stream.Null, tc.PackageReader.Object, string.Empty);

            // Act & Assert
            var ex = await Assert.ThrowsAsync <MinClientVersionException>(() =>
                                                                          tc.Target.EnsurePackageCompatibilityAsync(
                                                                              tc.NuGetProject,
                                                                              tc.PackageIdentityA,
                                                                              result,
                                                                              CancellationToken.None));

            Assert.Equal(
                "The 'PackageA 1.0.0' package requires NuGet client version '10.0.0' or above, " +
                $"but the current NuGet version is '{MinClientVersionUtility.GetNuGetClientVersion()}'. " +
                "To upgrade NuGet, please go to http://docs.nuget.org/consume/installing-nuget",
                ex.Message);

            tc.PackageReader.Verify(x => x.GetMinClientVersion(), Times.Never);
            tc.PackageReader.Verify(x => x.GetPackageTypes(), Times.Never);
            tc.NuspecReader.Verify(x => x.GetMinClientVersion(), Times.AtLeastOnce);
            tc.NuspecReader.Verify(x => x.GetPackageTypes(), Times.Never);
        }
コード例 #4
0
        public UserAgentStringBuilder(string clientName)
        {
            _clientName = clientName;

            // Read the client version from the assembly metadata and normalize it.
            NuGetClientVersion = MinClientVersionUtility.GetNuGetClientVersion().ToNormalizedString();
        }
        public void MinClientVersionUtility_CurrentVersionIsCompatible()
        {
            // Arrange && Act
            var result = MinClientVersionUtility.IsMinClientVersionCompatible(MinClientVersionUtility.GetNuGetClientVersion());

            // Assert
            Assert.True(result);
        }
コード例 #6
0
        /// <summary>
        /// Set user agent string on HttpClient to the static string.
        /// </summary>
        /// <param name="client">Http client</param>
        public static void SetUserAgent(HttpClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (!string.IsNullOrEmpty(UserAgentString))
            {
                client.DefaultRequestHeaders.Add("user-agent", UserAgentString);
                client.DefaultRequestHeaders.Add("X-NuGet-Client-Version", MinClientVersionUtility.GetNuGetClientVersion().ToNormalizedString());
            }
        }
コード例 #7
0
 /// <summary>
 /// Apply standard properties in a property group.
 /// </summary>
 public static void AddNuGetProperties(
     XDocument doc,
     IEnumerable <string> packageFolders,
     string repositoryRoot,
     ProjectStyle projectStyle,
     string assetsFilePath,
     bool success)
 {
     doc.Root.AddFirst(
         new XElement(Namespace + "PropertyGroup",
                      new XAttribute("Condition", $" {ExcludeAllCondition} "),
                      GenerateProperty("RestoreSuccess", success.ToString()),
                      GenerateProperty("RestoreTool", "NuGet"),
                      GenerateProperty("ProjectAssetsFile", assetsFilePath),
                      GenerateProperty("NuGetPackageRoot", ReplacePathsWithMacros(repositoryRoot)),
                      GenerateProperty("NuGetPackageFolders", string.Join(";", packageFolders)),
                      GenerateProperty("NuGetProjectStyle", projectStyle.ToString()),
                      GenerateProperty("NuGetToolVersion", MinClientVersionUtility.GetNuGetClientVersion().ToFullString())));
 }
コード例 #8
0
        /// <summary>
        /// Get the list of service entries that best match the current clientVersion and type.
        /// </summary>
        public virtual IReadOnlyList <ServiceIndexEntry> GetServiceEntries(params string[] orderedTypes)
        {
            var clientVersion = MinClientVersionUtility.GetNuGetClientVersion();

            return(GetServiceEntries(clientVersion, orderedTypes));
        }
コード例 #9
0
        /// <summary>
        /// Get the best match service URI.
        /// </summary>
        public virtual Uri GetServiceEntryUri(params string[] orderedTypes)
        {
            var clientVersion = MinClientVersionUtility.GetNuGetClientVersion();

            return(GetServiceEntryUris(clientVersion, orderedTypes).FirstOrDefault());
        }