public void Should_Execute_RestRequest_With_InvalidJson()
        {
            // arrange
            var client      = new RestClientAutolog("http://pruu.herokuapp.com/dump/restsharpAutoLog-test");
            var restRequest = new RestRequest(Method.POST);

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddParameter("", "{invalid}", ParameterType.RequestBody);

            // act
            var restResponse = client.Execute(restRequest);

            // assert
            Assert.Equal(DefaultMessage, client.Configuration.MessageTemplateForError);
            Assert.Equal(DefaultMessage, client.Configuration.MessageTemplateForSuccess);
            Assert.Null(client.Configuration.LoggerConfiguration);
            Assert.Equal("pruu.herokuapp.com", client.BaseUrl.Host);
            Assert.Equal("OK", restResponse.Content);
            Assert.Equal(200, (int)restResponse.StatusCode);
            Assert.True(restResponse.IsSuccessful);
        }
Ejemplo n.º 2
0
        public void Should_Execute_RestRequest_With_X_Www_Form_Url_Encoded()
        {
            // arrange
            var client      = new RestClientAutolog("http://pruu.herokuapp.com/dump/restsharpAutoLog-test");
            var restRequest = new RestRequest(Method.POST);

            restRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            restRequest.AddHeader("LogIgnored", "ResponseBody,ResponseContent");
            restRequest.AddParameter("", "someproperty=somevalue&someproperty=somevalue2&xpto&xpto=&", ParameterType.RequestBody);

            // act
            var restResponse = client.Execute(restRequest);

            // assert
            Assert.Equal(DefaultMessage, client.Configuration.MessageTemplateForError);
            Assert.Equal(DefaultMessage, client.Configuration.MessageTemplateForSuccess);
            Assert.Null(client.Configuration.LoggerConfiguration);
            Assert.Equal("pruu.herokuapp.com", client.BaseUrl.Host);
            Assert.Equal("OK", restResponse.Content);
            Assert.Equal(200, (int)restResponse.StatusCode);
            Assert.True(restResponse.IsSuccessful);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var loggerConfiguration = new LoggerConfiguration()
                                      .MinimumLevel.Debug()
                                      .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                                      .MinimumLevel.Override("System", LogEventLevel.Error)
                                      .Enrich.FromLogContext()
                                      .Enrich.WithMachineName()
                                      .Enrich.WithProperty("Domain", "MyTeam")
                                      .Enrich.WithProperty("Application", "MyProject")
                                      .WriteTo.Seq("http://localhost:5341")
                                      .WriteTo.Console();

            Log.Logger = loggerConfiguration.CreateLogger();

            //RestClientAutologConfiguration restClientAutologConfiguration = new RestClientAutologConfiguration()
            //{
            //    LoggerConfiguration = loggerConfiguration
            //};

            IRestClient client = new RestClientAutolog("http://pruu.herokuapp.com");

            client.AddDefaultHeader("DefaultHeaderTest", "SomeValue");

            RestRequest request = new RestRequest("dump/{name}", Method.POST);

            request.AddHeader("RequestCustomHeader", "SomeValue2");
            request.AddUrlSegment("name", "RestsharpAutoLog");
            request.AddQueryParameter("CustomQuery", "SomeValue3");
            request.AddJsonBody(new
            {
                TestOne = 123,
                TestTwo = "SomeValueBody"
            });

            var response = client.Execute(request);

            Console.ReadKey();
        }