Пример #1
0
        public void HttpResponseDataInResult()
        {
            MockServiceTracer tracer = new MockServiceTracer();

            System.Net.Http.HttpResponseMessage httpResponse = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
            httpResponse.Headers.Add("x-ms-header", "value");
            tracer.HttpResponses.Add(httpResponse);

            LiveTestRequest request = new LiveTestRequest();

            request.Id           = "12345";
            request.JsonRpc      = "2.0";
            request.HttpResponse = true;

            CommandExecutionResult result   = new CommandExecutionResult(null, null, false);
            LiveTestResponse       response = request.MakeResponse(result, tracer, this.logger);

            Assert.NotNull(response.Result.Headers);
            Assert.True(response.Result.Headers is Dictionary <string, object>);
            Dictionary <string, object> headers = (Dictionary <string, object>)response.Result.Headers;

            Assert.Equal(1, headers.Count);
            Assert.True(headers.ContainsKey("x-ms-header"));
            Assert.Equal(new string[] { "value" }, headers["x-ms-header"]);

            Assert.Equal((long)System.Net.HttpStatusCode.Accepted, response.Result.StatusCode);
        }
Пример #2
0
        public void MultipleResultResponse()
        {
            MockServiceTracer tracer    = new MockServiceTracer();
            object            psResult1 = 5;
            object            psResult2 = "test";
            List <object>     psResults = new List <object>();

            psResults.Add(psResult1);
            psResults.Add(psResult2);
            CommandExecutionResult result  = new CommandExecutionResult(psResults, null, false);
            LiveTestRequest        request = new LiveTestRequest();

            request.Id      = "12345";
            request.JsonRpc = "2.0";
            LiveTestResponse response = request.MakeResponse(result, tracer, this.logger);

            Assert.Equal(request.Id, response.Id);
            Assert.Equal(request.JsonRpc, response.JsonRpc);

            Assert.NotNull(response.Result);
            Assert.Null(response.Result.Headers);
            Assert.Equal(default(long), response.Result.StatusCode);
            Assert.NotNull(response.Result.Response);
            Assert.Collection <object>((object[])response.Result.Response, new Action <object>[]
            {
                (obj) =>
                {
                    Assert.Equal(psResult1, obj);
                },
                (obj) =>
                {
                    Assert.Equal(psResult2, obj);
                }
            });
        }
Пример #3
0
        public void SingleErrorResponse()
        {
            MockServiceTracer tracer      = new MockServiceTracer();
            object            errorResult = 5;
            List <object>     errors      = new List <object>();

            errors.Add(errorResult);
            CommandExecutionResult result  = new CommandExecutionResult(null, errors, true);
            LiveTestRequest        request = new LiveTestRequest();

            request.Id      = "12345";
            request.JsonRpc = "2.0";
            LiveTestResponse response = request.MakeResponse(result, tracer, this.logger);

            Assert.Equal(request.Id, response.Id);
            Assert.Equal(request.JsonRpc, response.JsonRpc);

            Assert.NotNull(response.Error);
            Assert.Equal(-32600, response.Error.Code); // Invalid Request error code defined by LSP

            Assert.NotNull(response.Error.Data);
            Assert.Null(response.Error.Data.Headers);
            Assert.Equal(default(long), response.Error.Data.StatusCode);
            Assert.NotNull(response.Error.Data.Response);
            Assert.Equal(errorResult, response.Error.Data.Response);
        }
Пример #4
0
        public void NullResultResponse()
        {
            MockServiceTracer      tracer  = new MockServiceTracer();
            CommandExecutionResult result  = new CommandExecutionResult(null, null, false);
            LiveTestRequest        request = new LiveTestRequest();

            request.Id      = "12345";
            request.JsonRpc = "2.0";
            LiveTestResponse response = request.MakeResponse(result, tracer, this.logger);

            Assert.Equal(request.Id, response.Id);
            Assert.Equal(request.JsonRpc, response.JsonRpc);

            Assert.NotNull(response.Result);
            Assert.Null(response.Result.Headers);
            Assert.Equal(default(long), response.Result.StatusCode);
            Assert.Null(response.Result.Response);
        }
Пример #5
0
        public void HttpResponseDataInErrorNoHttpResponseEnabled()
        {
            MockServiceTracer tracer = new MockServiceTracer();

            System.Net.Http.HttpResponseMessage httpResponse = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.BadGateway);
            httpResponse.Headers.Add("x-ms-header", "value");
            tracer.HttpResponses.Add(httpResponse);

            LiveTestRequest request = new LiveTestRequest();

            request.Id      = "12345";
            request.JsonRpc = "2.0";

            CommandExecutionResult result   = new CommandExecutionResult(null, null, true);
            LiveTestResponse       response = request.MakeResponse(result, tracer, this.logger);

            Assert.Null(response.Error.Data.Headers);
            Assert.Equal(default(long), response.Error.Data.StatusCode);
        }
Пример #6
0
        public void MultipleErrorResponse()
        {
            MockServiceTracer tracer       = new MockServiceTracer();
            object            errorResult1 = 5;
            object            errorResult2 = "test";
            List <object>     errors       = new List <object>();

            errors.Add(errorResult1);
            errors.Add(errorResult2);
            CommandExecutionResult result  = new CommandExecutionResult(null, errors, true);
            LiveTestRequest        request = new LiveTestRequest();

            request.Id      = "12345";
            request.JsonRpc = "2.0";
            LiveTestResponse response = request.MakeResponse(result, tracer, this.logger);

            Assert.Equal(request.Id, response.Id);
            Assert.Equal(request.JsonRpc, response.JsonRpc);

            Assert.NotNull(response.Error);
            Assert.Equal(-32600, response.Error.Code); // Invalid Request error code defined by LSP

            Assert.NotNull(response.Error.Data);
            Assert.Null(response.Error.Data.Headers);
            Assert.Equal(default(long), response.Error.Data.StatusCode);
            Assert.NotNull(response.Error.Data.Response);
            Assert.True(response.Error.Data.Response is object[]);
            Assert.Collection <object>((object[])response.Error.Data.Response, new Action <object>[]
            {
                (obj) =>
                {
                    Assert.Equal(errorResult1, obj);
                },
                (obj) =>
                {
                    Assert.Equal(errorResult2, obj);
                }
            });
        }