示例#1
0
        public async Task GetOperationClaims_ReturnsSupportedClaims()
        {
            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.GetOperationClaims,
                    new GetOperationClaimsResponse(new OperationClaim[] { OperationClaim.DownloadPackage }));

                var serviceIndex = JObject.Parse("{}");
                var payload      = new GetOperationClaimsRequest(packageSourceRepository: "a", serviceIndex: serviceIndex);

                var response = await test.Plugin.Connection.SendRequestAndReceiveResponseAsync <GetOperationClaimsRequest, GetOperationClaimsResponse>(
                    MessageMethod.GetOperationClaims,
                    payload,
                    test.CancellationToken);

                Assert.NotNull(response);
                Assert.Equal(1, response.Claims.Count);
                Assert.Equal(OperationClaim.DownloadPackage, response.Claims[0]);
            }
        }
示例#2
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);
            }
        }
示例#3
0
        public async Task Fault_WritesExceptionToConsole()
        {
            using (var test = await PluginTest.CreateAsync())
                using (var closedEvent = new ManualResetEventSlim(initialState: false))
                {
                    Assert.Equal(PluginProtocolConstants.CurrentVersion, test.Plugin.Connection.ProtocolVersion);

                    test.Plugin.Closed += (object sender, EventArgs e) =>
                    {
                        closedEvent.Set();
                    };

                    // Send canned response
                    // This response is unexpected and will generate a protocol error.
                    var responseSenderTask = Task.Run(() => test.ResponseSender.StartSendingAsync(test.CancellationToken));
                    await test.ResponseSender.SendAsync(
                        MessageType.Response,
                        MessageMethod.Initialize,
                        new InitializeResponse(MessageResponseCode.Success));

                    var serviceIndex = JObject.Parse("{}");
                    var payload      = new GetOperationClaimsRequest(packageSourceRepository: "a", serviceIndex: serviceIndex);

                    string consoleOutput;

                    using (var spy = new ConsoleOutputSpy())
                    {
                        var requestTask = Task.Run(
                            () => test.Plugin.Connection.SendRequestAndReceiveResponseAsync <GetOperationClaimsRequest, GetOperationClaimsResponse>(
                                MessageMethod.GetOperationClaims,
                                payload,
                                test.CancellationToken));

                        closedEvent.Wait();

                        consoleOutput = spy.GetOutput();
                    }

                    Assert.Contains(
                        $"Terminating plugin '{test.Plugin.Name}' due to an unrecoverable fault:  NuGet.Protocol.Plugins.ProtocolException: A plugin protocol exception occurred.",
                        consoleOutput);
                }
        }