コード例 #1
0
        public void Can_optimize_result_with_ToOptimizedResult()
        {
            var dto = new TestDto {
                Name = "test"
            };

            var httpReq = new MockHttpRequest();

            httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
            httpReq.ResponseContentType = "text/html";
            var httpRes = new ViewTests.MockHttpResponse();

            var httpRequestContext = new HttpRequestContext(httpReq, httpRes, dto);

            var appHost = new TestAppHost();

            new HtmlFormat().Register(appHost);

            EndpointHost.ContentTypeFilter = appHost.ContentTypeFilters;

            object result = httpRequestContext.ToOptimizedResult(dto);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is CompressedResult);
        }
コード例 #2
0
        private static void CanOptimizeResult(string contentType, IPlugin pluginFormat)
        {
            var dto = new TestDto {
                Name = "test"
            };

            var httpReq = new MockHttpRequest();

            httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
            httpReq.ResponseContentType = contentType;
            var httpRes = new ViewTests.MockHttpResponse();

            var httpRequestContext = new HttpRequestContext(httpReq, httpRes, dto);

            var appHost = new TestAppHost();

            if (pluginFormat != null)
            {
                pluginFormat.Register(appHost);
            }

            EndpointHost.ContentTypeFilter = appHost.ContentTypeFilters;

            object result = httpRequestContext.ToOptimizedResult(dto);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is CompressedResult);
        }
コード例 #3
0
        public static TestAppHost CreateAppHost()
        {
            var appHost = new TestAppHost();

            appHost.Init();

            return(appHost);
        }
コード例 #4
0
        public void Can_run_nested_service()
        {
            var host = new TestAppHost();

            host.Init();

            var request  = new Nested();
            var response = host.ExecuteService(request) as NestedResponse;

            Assert.That(response, Is.Not.Null);
        }
コード例 #5
0
        public void Can_run_test_service()
        {
            var host = new TestAppHost();

            host.Init();

            var request  = new Test();
            var response = host.ExecuteService(request) as TestResponse;

            Assert.That(response, Is.Not.Null);
            Assert.That(response.Foo, Is.Not.Null);
        }
コード例 #6
0
        public ServiceStackHostFixture()
        {
            var appHost = new TestAppHost();

            appHost.Init();

            if (!appHost.HasStarted)
            {
                appHost.Start(ListeningOn);
            }

            AppHost = appHost;
        }
コード例 #7
0
        private T StringToPoco <T>(string str)
        {
            var testAppHost = new TestAppHost(new Container(), GetType().Assembly);
            NameValueCollection queryString = HttpUtility.ParseQueryString(str);
            var restPath    = new RestPath(typeof(T), "/query", "GET, POST");
            var restHandler = new RestHandler()
            {
                RestPath = restPath
            };
            var httpReq = new HttpRequestMock("query", "GET", "application/json", "query", queryString,
                                              new MemoryStream(), new NameValueCollection());
            var request = (T)restHandler.CreateRequest(httpReq, "query");

            return(request);
        }
コード例 #8
0
        public void Call_AsyncOneWay_endpoint_on_AsyncTestService_calls_ExecuteAsync()
        {
            var host = new TestAppHost();

            host.Init();

            TestAsyncService.ResetStats();

            var request  = new TestAsync();
            var response = host.ExecuteService(request, EndpointAttributes.OneWay) as TestAsyncResponse;

            Assert.That(response, Is.Not.Null);
            Assert.That(response.ExecuteTimes, Is.EqualTo(0));
            Assert.That(response.ExecuteAsyncTimes, Is.EqualTo(1));
        }
コード例 #9
0
        public void Can_deserialize_TestRequest_QueryStringSerializer_output()
        {
            // Setup
            var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly);
            var restPath = new RestPath(typeof(TestRequest), "/service", "GET");
            var restHandler = new RestHandler { RestPath = restPath };

            var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
            NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
            var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());

            var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service");

            Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
            Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
        }
コード例 #10
0
        public void Can_deserialize_TestRequest_QueryStringSerializer_output()
        {
            // Setup
            var testAppHost = new TestAppHost(new Container(), typeof(TestService).Assembly);
            var restPath    = new RestPath(typeof(TestRequest), "/service", "GET");
            var restHandler = new RestHandler {
                RestPath = restPath
            };

            var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
            NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
            var httpReq = new HttpRequestMock("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());

            var request2 = (TestRequest)restHandler.CreateRequest(httpReq, "service");

            Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
            Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
        }
            public void Response_returned_when_valid()
            {
                using (var appHost = new TestAppHost())
                {
                    appHost.Plugins.Add(new ValidationFeature());
                    appHost.Init();
                    appHost.Start(Urlbase);

                    var sc = new JsonServiceClient(Urlbase);

                    var response = sc.Get(new EchoRequest {
                        Day = "Monday", Word = "Word"
                    });

                    Assert.That(response.Day, Is.EqualTo("Monday"));
                    Assert.That(response.Word, Is.EqualTo("Word"));
                }
            }
            public void Can_treat_warnings_and_info_as_errors()
            {
                using (var appHost = new TestAppHost())
                {
                    appHost.Plugins.Add(new ValidationFeature {
                        TreatInfoAndWarningsAsErrors = true
                    });
                    appHost.Init();
                    appHost.Start(Urlbase);

                    var sc = new JsonServiceClient(Urlbase);

                    Assert.Throws <WebServiceException>(() => sc.Get(new EchoRequest {
                        Day = "Monday", Word = ""
                    }),
                                                        "'Word' should not be empty.");
                }
            }
コード例 #13
0
        public void Can_optimize_result_with_ToOptimizedResult()
        {
            var dto = new TestDto {Name = "test"};

            var httpReq = new MockHttpRequest();
            httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
            httpReq.ResponseContentType = "text/html";
            var httpRes = new ViewTests.MockHttpResponse();

            var httpRequestContext = new HttpRequestContext(httpReq, httpRes, dto);

            var appHost = new TestAppHost();
            HtmlFormat.Register(appHost);
            EndpointHost.ContentTypeFilter = appHost.ContentTypeFilters;

            object result = httpRequestContext.ToOptimizedResult(dto);
            Assert.IsNotNull(result);
            Assert.IsTrue(result is CompressedResult);
        }
            public void Can_return_response_when_no_failed_validations_and_TreatInfoAndWarningsAsErrors_set_false()
            {
                using (var appHost = new TestAppHost())
                {
                    appHost.Plugins.Add(new ValidationFeature {
                        TreatInfoAndWarningsAsErrors = false
                    });
                    appHost.Init();
                    appHost.Start(Urlbase);

                    var sc = new JsonServiceClient(Urlbase);

                    var resp = sc.Get(new EchoRequest {
                        Day = "Monday", Word = "Word"
                    });

                    Assert.That(resp.ResponseStatus, Is.Null);
                }
            }
コード例 #15
0
        private static void CanOptimizeResult(string contentType, IPlugin pluginFormat)
        {
            var dto = new TestDto {Name = "test"};

            var httpReq = new MockHttpRequest();
            httpReq.Headers.Add(HttpHeaders.AcceptEncoding, "gzip,deflate,sdch");
            httpReq.ResponseContentType = contentType;
            var httpRes = new ViewTests.MockHttpResponse();

            var httpRequestContext = new HttpRequestContext(httpReq, httpRes, dto);

            var appHost = new TestAppHost();
            if (pluginFormat != null) pluginFormat.Register(appHost);

            EndpointHost.ContentTypeFilter = appHost.ContentTypeFilters;

            object result = httpRequestContext.ToOptimizedResult(dto);
            Assert.IsNotNull(result);
            Assert.IsTrue(result is CompressedResult);
        }
            public void Can_ignore_warnings_and_info_as_errors()
            {
                using (var appHost = new TestAppHost())
                {
                    appHost.Plugins.Add(new ValidationFeature {
                        TreatInfoAndWarningsAsErrors = false
                    });
                    appHost.Init();
                    appHost.Start(Urlbase);

                    var sc = new JsonServiceClient(Urlbase);

                    var response = sc.Get(new EchoRequest {
                        Day = "", Word = ""
                    });

                    Assert.That(response.ResponseStatus, Is.Not.Null);
                    Assert.That(response.ResponseStatus.Errors, Is.Not.Empty);
                    Assert.That(response.ResponseStatus.Errors.First().Meta["Severity"], Is.EqualTo("Info"));
                    Assert.That(response.ResponseStatus.Errors[1].Meta["Severity"], Is.EqualTo("Warning"));
                }
            }
コード例 #17
0
        public void AppTriggersAlerts()
        {
            using var host = new TestAppHost();

            var app = new ValueListApp
            {
                PropertyName = "Test"
            };

            app.Attach(host);

            app.On(Some.LogEvent(new Dictionary <string, object> {
                ["Something"] = "Irrelevant"
            }));

            Assert.Empty(Directory.GetFiles(host.StoragePath));

            app.On(Some.LogEvent(new Dictionary <string, object> {
                ["Test"] = "First"
            }));

            var file  = Assert.Single(Directory.GetFiles(host.StoragePath));
            var lines = File.ReadLines(file !);
            var line  = Assert.Single(lines);

            Assert.Equal("First", line);
            Assert.Equal(1, host.DiagnosticsEmitted.Count);

            app.On(Some.LogEvent(new Dictionary <string, object> {
                ["Test"] = "First"
            }));
            app.On(Some.LogEvent(new Dictionary <string, object> {
                ["Test"] = "Second"
            }));

            Assert.Equal(2, File.ReadLines(file).Count());
            Assert.Equal(2, host.DiagnosticsEmitted.Count);
        }
コード例 #18
0
 public void RunBeforeAnyTests()
 {
     _appHost = new TestAppHost();
     _appHost.Init();
     _appHost.Start(Config.ServiceStackBaseUri);
 }
コード例 #19
0
 public void TestFixtureSetUp()
 {
     appHost = CreateAppHost();
 }
コード例 #20
0
 public void RunBeforeAnyTests()
 {
     _appHost = new TestAppHost();
     _appHost.Init();
     _appHost.Start(Config.ServiceStackBaseUri);
 }