public void Can_Register_NewApi_Routes_From_Assembly()
        {
            var routes = new ServiceRoutes();
            routes.AddFromAssembly(typeof(NewApiRestServiceWithAllVerbsImplemented).Assembly);

            RestPath restWithAllMethodsRoute =
                (from r in routes.RestPaths
                 where r.Path == "/NewApiRequestDto"
                 select r).FirstOrDefault();

            Assert.That(restWithAllMethodsRoute, Is.Not.Null);

            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("GET"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("POST"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("PUT"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("DELETE"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("PATCH"));

            RestPath restWithAllMethodsRoute2 =
                (from r in routes.RestPaths
                 where r.Path == "/NewApiRequestDto2"
                 select r).FirstOrDefault();

            Assert.That(restWithAllMethodsRoute2, Is.Not.Null);

            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("GET"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("POST"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("PUT"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("DELETE"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("PATCH"));
        }
示例#2
0
 public void Can_Register_Routes_Using_Add_Extension()
 {
     var routes = new ServiceRoutes();
     routes.Add<Customer>(HttpMethod.Get, "/Users/{0}/Orders/{1}", x => x.Name, x => x.OrderId);
     var route = routes.RestPaths[0];
     Assert.That(route.Path == "/Users/{Name}/Orders/{OrderId}");
 }
示例#3
0
        public void Can_Register_NewApi_Routes_From_Assembly()
        {
            var routes = new ServiceRoutes();

            routes.AddFromAssembly(typeof(NewApiRestServiceWithAllVerbsImplemented).Assembly);

            RestPath restWithAllMethodsRoute =
                (from r in routes.RestPaths
                 where r.Path == "/NewApiRequestDto"
                 select r).FirstOrDefault();

            Assert.That(restWithAllMethodsRoute, Is.Not.Null);

            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("GET"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("POST"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("PUT"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("DELETE"));
            Assert.That(restWithAllMethodsRoute.AllowedVerbs.Contains("PATCH"));

            RestPath restWithAllMethodsRoute2 =
                (from r in routes.RestPaths
                 where r.Path == "/NewApiRequestDto2"
                 select r).FirstOrDefault();

            Assert.That(restWithAllMethodsRoute2, Is.Not.Null);

            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("GET"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("POST"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("PUT"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("DELETE"));
            Assert.That(restWithAllMethodsRoute2.AllowedVerbs.Contains("PATCH"));
        }
        protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
        {
            this.StartedAt = DateTime.UtcNow;

            ServiceName = serviceName;
            Container   = new Container {
                DefaultOwner = Owner.External
            };
            ServiceController = CreateServiceController(assembliesWithServices);

            ContentTypes              = Host.ContentTypes.Instance;
            RestPaths                 = new List <RestPath>();
            Routes                    = new ServiceRoutes(this);
            Metadata                  = new ServiceMetadata(RestPaths);
            PreRequestFilters         = new List <Action <IRequest, IResponse> >();
            GlobalRequestFilters      = new List <Action <IRequest, IResponse, object> >();
            GlobalResponseFilters     = new List <Action <IRequest, IResponse, object> >();
            ViewEngines               = new List <IViewEngine>();
            ServiceExceptionHandlers  = new List <HandleServiceExceptionDelegate>();
            UncaughtExceptionHandlers = new List <HandleUncaughtExceptionDelegate>();
            RawHttpHandlers           = new List <Func <IHttpRequest, IHttpHandler> > {
                HttpHandlerFactory.ReturnRequestInfo,
                MiniProfilerHandler.MatchesRequest,
            };
            CatchAllHandlers        = new List <HttpHandlerResolverDelegate>();
            CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler>();
            Plugins = new List <IPlugin> {
                new HtmlFormat(),
                new CsvFormat(),
                new MarkdownFormat(),
                new PredefinedRoutesFeature(),
                new MetadataFeature(),
            };
        }
示例#5
0
 public void Can_Register_Routes_Using_Add_Extension()
 {
     var routes = new ServiceRoutes(appHost);
     routes.Add<Customer>("/Users/{0}/Orders/{1}", ApplyTo.Get, x => x.Name, x => x.OrderId);
     var route = appHost.RestPaths[0];
     Assert.That(route.Path == "/Users/{Name}/Orders/{OrderId}");
 }
示例#6
0
        protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
        {
            this.StartedAt = DateTime.UtcNow;

            ServiceName = serviceName;
            AppSettings = new AppSettings();
            Container   = new Container {
                DefaultOwner = Owner.External
            };
            ServiceController = CreateServiceController(assembliesWithServices);

            ContentTypes                      = Host.ContentTypes.Instance;
            RestPaths                         = new List <RestPath>();
            Routes                            = new ServiceRoutes(this);
            Metadata                          = new ServiceMetadata(RestPaths);
            PreRequestFilters                 = new List <Action <IRequest, IResponse> >();
            GlobalRequestFilters              = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedRequestFilters         = new Dictionary <Type, ITypedFilter>();
            GlobalResponseFilters             = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedResponseFilters        = new Dictionary <Type, ITypedFilter>();
            GlobalMessageRequestFilters       = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedMessageRequestFilters  = new Dictionary <Type, ITypedFilter>();
            GlobalMessageResponseFilters      = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedMessageResponseFilters = new Dictionary <Type, ITypedFilter>();
            ViewEngines                       = new List <IViewEngine>();
            ServiceExceptionHandlers          = new List <HandleServiceExceptionDelegate>();
            UncaughtExceptionHandlers         = new List <HandleUncaughtExceptionDelegate>();
            AfterInitCallbacks                = new List <Action <IAppHost> >();
            OnDisposeCallbacks                = new List <Action <IAppHost> >();
            RawHttpHandlers                   = new List <Func <IHttpRequest, IHttpHandler> > {
                HttpHandlerFactory.ReturnRequestInfo,
                MiniProfilerHandler.MatchesRequest,
            };
            CatchAllHandlers        = new List <HttpHandlerResolverDelegate>();
            CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler> {
                { HttpStatusCode.Forbidden, new ForbiddenHttpHandler() },
                { HttpStatusCode.NotFound, new NotFoundHttpHandler() },
            };
            StartUpErrors = new List <ResponseStatus>();
            PluginsLoaded = new List <string>();
            Plugins       = new List <IPlugin> {
                new HtmlFormat(),
                new CsvFormat(),
                new MarkdownFormat(),
                new PredefinedRoutesFeature(),
                new MetadataFeature(),
                new NativeTypesFeature(),
            };
            ExcludeAutoRegisteringServiceTypes = new HashSet <Type> {
                typeof(AuthenticateService),
                typeof(RegisterService),
                typeof(AssignRolesService),
                typeof(UnAssignRolesService),
                typeof(NativeTypesService),
                typeof(PostmanService),
            };

            // force deterministic initialization of static constructor
            using (JsConfig.BeginScope()) { }
        }
示例#7
0
        public void Can_Register_Routes_Using_Add_Extension()
        {
            var routes = new ServiceRoutes();

            routes.Add <Customer>(HttpMethod.Get, "/Users/{0}/Orders/{1}", x => x.Name, x => x.OrderId);
            var route = routes.RestPaths[0];

            Assert.That(route.Path == "/Users/{Name}/Orders/{OrderId}");
        }
示例#8
0
        public void Can_Register_Routes_Using_Add_Extension()
        {
            var routes = new ServiceRoutes();

            routes.Add <Customer>("/Users/{0}/Orders/{1}", ApplyTo.Get, x => x.Name, x => x.OrderId);
            var route = routes.Last();

            Assert.That(route.Path, Is.EqualTo("/Users/{Name}/Orders/{OrderId}"));
        }
        public void Can_Register_Routes_With_Partially_Implemented_REST_Verbs()
        {
            var routes = new ServiceRoutes();
            routes.AddFromAssembly(typeof(RestServiceWithSomeVerbsImplemented).Assembly);

            RestPath restWithAFewMethodsRoute = (from r in routes.RestPaths
                                                 where r.Path == "RestServiceWithSomeVerbsImplemented"
                                                 select r).FirstOrDefault();

            Assert.That(restWithAFewMethodsRoute, Is.Not.Null);

            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("GET"), Is.True);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("POST"), Is.False);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("PUT"), Is.True);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("DELETE"), Is.False);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("PATCH"), Is.False);
        }
示例#10
0
        public void Can_Register_Routes_With_Partially_Implemented_REST_Verbs()
        {
            var routes = new ServiceRoutes();

            routes.AddFromAssembly(typeof(RestServiceWithSomeVerbsImplemented).Assembly);

            RestPath restWithAFewMethodsRoute = (from r in routes.RestPaths
                                                 where r.Path == "RestServiceWithSomeVerbsImplemented"
                                                 select r).FirstOrDefault();

            Assert.That(restWithAFewMethodsRoute, Is.Not.Null);

            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("GET"), Is.True);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("POST"), Is.False);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("PUT"), Is.True);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("DELETE"), Is.False);
            Assert.That(restWithAFewMethodsRoute.AllowedVerbs.Contains("PATCH"), Is.False);
        }
		public void Can_Register_NewApi_Routes_With_Field_Id_and_Any_Fallback_From_Assembly()
		{
			var routes = new ServiceRoutes();
			routes.AddFromAssembly(typeof(NewApiRequestDtoWithFieldIdService).Assembly);

			var route = (from r in routes.RestPaths
						 where r.Path == "/NewApiRequestDtoWithFieldId"
						 select r).FirstOrDefault();

			Assert.That(route, Is.Not.Null);
			Assert.That(route.AllowedVerbs, Is.Null);

			route = (from r in routes.RestPaths
					 where r.Path == "/NewApiRequestDtoWithFieldId/{Id}"
					 select r).FirstOrDefault();

			Assert.That(route, Is.Not.Null);
			Assert.That(route.AllowedVerbs, Is.Null);
		}
示例#12
0
		public void Can_Register_NewApi_Routes_With_Field_Id_and_Any_Fallback_From_Assembly()
		{
            var routes = new ServiceRoutes(appHost);
			routes.AddFromAssembly(typeof(NewApiRequestDtoWithFieldIdService).Assembly);

            var route = (from r in appHost.RestPaths
						 where r.Path == "/NewApiRequestDtoWithFieldId"
						 select r).FirstOrDefault();

			Assert.That(route, Is.Not.Null);
			Assert.That(route.AllowedVerbs, Is.Null);

            route = (from r in appHost.RestPaths
					 where r.Path == "/NewApiRequestDtoWithFieldId/{Id}"
					 select r).FirstOrDefault();

			Assert.That(route, Is.Not.Null);
			Assert.That(route.AllowedVerbs, Is.Null);
		}
示例#13
0
        protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
        {
            this.StartedAt = DateTime.UtcNow;

            ServiceName = serviceName;
            AppSettings = new AppSettings();
            Container   = new Container {
                DefaultOwner = Owner.External
            };
            ServiceAssemblies = assembliesWithServices.ToList();

            ContentTypes                      = new ContentTypes();
            RestPaths                         = new List <RestPath>();
            Routes                            = new ServiceRoutes(this);
            Metadata                          = new ServiceMetadata(RestPaths);
            PreRequestFilters                 = new List <Action <IRequest, IResponse> >();
            RequestConverters                 = new List <Func <IRequest, object, Task <object> > >();
            ResponseConverters                = new List <Func <IRequest, object, Task <object> > >();
            GlobalRequestFilters              = new List <Action <IRequest, IResponse, object> >();
            GlobalRequestFiltersAsync         = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedRequestFilters         = new Dictionary <Type, ITypedFilter>();
            GlobalResponseFilters             = new List <Action <IRequest, IResponse, object> >();
            GlobalResponseFiltersAsync        = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedResponseFilters        = new Dictionary <Type, ITypedFilter>();
            GlobalMessageRequestFilters       = new List <Action <IRequest, IResponse, object> >();
            GlobalMessageRequestFiltersAsync  = new List <Func <IRequest, IResponse, object, Task> >();
            GlobalTypedMessageRequestFilters  = new Dictionary <Type, ITypedFilter>();
            GlobalMessageResponseFilters      = new List <Action <IRequest, IResponse, object> >();
            GlobalTypedMessageResponseFilters = new Dictionary <Type, ITypedFilter>();
            GatewayRequestFilters             = new List <Action <IRequest, object> >();
            GatewayRequestFiltersAsync        = new List <Func <IRequest, object, Task> >();
            GatewayResponseFilters            = new List <Action <IRequest, object> >();
            GatewayResponseFiltersAsync       = new List <Func <IRequest, object, Task> >();
            ViewEngines                       = new List <IViewEngine>();
            ServiceExceptionHandlers          = new List <HandleServiceExceptionDelegate>();
            UncaughtExceptionHandlers         = new List <HandleUncaughtExceptionDelegate>();
            BeforeConfigure                   = new List <Action <ServiceStackHost> >();
            AfterConfigure                    = new List <Action <ServiceStackHost> >();
            AfterInitCallbacks                = new List <Action <IAppHost> >();
            OnDisposeCallbacks                = new List <Action <IAppHost> >();
            OnEndRequestCallbacks             = new List <Action <IRequest> >();
            AddVirtualFileSources             = new List <IVirtualPathProvider>();
            RawHttpHandlers                   = new List <Func <IHttpRequest, IHttpHandler> > {
                ReturnRedirectHandler,
                ReturnRequestInfoHandler,
            };
            CatchAllHandlers        = new List <HttpHandlerResolverDelegate>();
            CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler> {
                { HttpStatusCode.Forbidden, new ForbiddenHttpHandler() },
                { HttpStatusCode.NotFound, new NotFoundHttpHandler() },
            };
            StartUpErrors = new List <ResponseStatus>();
            AsyncErrors   = new List <ResponseStatus>();
            PluginsLoaded = new List <string>();
            Plugins       = new List <IPlugin> {
                new HtmlFormat(),
                new CsvFormat(),
                new PredefinedRoutesFeature(),
                new MetadataFeature(),
                new NativeTypesFeature(),
                new HttpCacheFeature(),
                new RequestInfoFeature(),
            };
            ExcludeAutoRegisteringServiceTypes = new HashSet <Type> {
                typeof(AuthenticateService),
                typeof(RegisterService),
                typeof(AssignRolesService),
                typeof(UnAssignRolesService),
                typeof(NativeTypesService),
                typeof(PostmanService),
                typeof(TemplateHotReloadService),
                typeof(TemplateHotReloadFilesService),
                typeof(TemplateApiPagesService),
                typeof(TemplateMetadataDebugService),
            };

            JsConfig.InitStatics();
        }
 protected ServiceStackHost(string serviceName, params Assembly[] assembliesWithServices)
 {
     Platform.HostInstance = this;
     Config = new HostConfig {
         DebugMode = GetType().Assembly.IsDebugBuild()
     };
     AppSettings       = ServiceStack.Configuration.AppSettings.Default;
     Metadata          = new ServiceMetadata();
     ServiceName       = serviceName;
     ServiceAssemblies = assembliesWithServices;
     Container         = new Container {
         DefaultOwner = Owner.External
     };
     ContentTypes                      = new ServiceStack.Host.ContentTypes();
     Routes                            = new ServiceRoutes();
     WebHostPhysicalPath               = GetWebRootPath();
     PreRequestFilters                 = new List <Action <IRequest, IResponse> >();
     RequestConverters                 = new List <Func <IRequest, object, Task <object> > >();
     ResponseConverters                = new List <Func <IRequest, object, Task <object> > >();
     GlobalRequestFilters              = new List <Action <IRequest, IResponse, object> >();
     GlobalRequestFiltersAsync         = new List <Func <IRequest, IResponse, object, Task> >();
     GlobalTypedRequestFilters         = new Dictionary <Type, ITypedFilter>();
     GlobalResponseFilters             = new List <Action <IRequest, IResponse, object> >();
     GlobalResponseFiltersAsync        = new List <Func <IRequest, IResponse, object, Task> >();
     GlobalTypedResponseFilters        = new Dictionary <Type, ITypedFilter>();
     GlobalMessageRequestFilters       = new List <Action <IRequest, IResponse, object> >();
     GlobalMessageRequestFiltersAsync  = new List <Func <IRequest, IResponse, object, Task> >();
     GlobalTypedMessageRequestFilters  = new Dictionary <Type, ITypedFilter>();
     GlobalMessageResponseFilters      = new List <Action <IRequest, IResponse, object> >();
     GlobalMessageResponseFiltersAsync = new List <Func <IRequest, IResponse, object, Task> >();
     GlobalTypedMessageResponseFilters = new Dictionary <Type, ITypedFilter>();
     GatewayRequestFilters             = new List <Action <IRequest, object> >();
     GatewayRequestFiltersAsync        = new List <Func <IRequest, object, Task> >();
     GatewayResponseFilters            = new List <Action <IRequest, object> >();
     GatewayResponseFiltersAsync       = new List <Func <IRequest, object, Task> >();
     ViewEngines                       = new List <IViewEngine>();
     ServiceExceptionHandlers          = new List <ServiceExceptionHandler>();
     ServiceExceptionHandlersAsync     = new List <HandleServiceExceptionAsyncDelegate>();
     UncaughtExceptionHandlers         = new List <UncatchedExceptionHandler>();
     UncaughtExceptionHandlersAsync    = new List <HandleUncaughtExceptionAsyncDelegate>();
     AfterInitCallbacks                = new List <Action <IAppHost> >();
     OnDisposeCallbacks                = new List <Action <IAppHost> >();
     OnEndRequestCallbacks             = new List <Action <IRequest> >();
     AddVirtualFileSources             = new List <IVirtualPathProvider>();
     RawHttpHandlers                   = new List <Func <IHttpRequest, IServiceStackHandler> > {
         ReturnRedirectHandler
     };
     CatchAllHandlers        = new List <HttpHandlerResolver>();
     CustomErrorHttpHandlers = new Dictionary <HttpStatusCode, IServiceStackHandler> {
         { HttpStatusCode.Forbidden, new ForbiddenHttpHandler() },
         { HttpStatusCode.NotFound, new NotFoundHttpHandler() },
     };
     StartUpErrors = new List <ResponseStatus>();
     AsyncErrors   = new List <ResponseStatus>();
     Plugins       = new List <IPlugin> {
         new HtmlFormat(),
         new CsvFormat(),
         new PredefinedRoutesFeature(),
         new MetadataFeature(),
         new NativeTypesFeature(),
         new HttpCacheFeature()
     };
     ExcludeAutoRegisteringServiceTypes = new HashSet <Type> {
         typeof(AuthenticateService),
         typeof(RegisterService),
         typeof(AssignRolesService),
         typeof(UnAssignRolesService),
         typeof(NativeTypesService),
         typeof(PostmanService),
         typeof(TemplateHotReloadService),
         typeof(HotReloadFilesService),
         typeof(TemplateApiPagesService),
         typeof(TemplateMetadataDebugService),
         typeof(ServerEventsSubscribersService),
         typeof(ServerEventsUnRegisterService),
     };
 }
示例#15
0
 public void Can_Register_Routes_Using_Add_Extension()
 {
     var routes = new ServiceRoutes(appHost);
     routes.Add<Customer>("/Users/{0}/Orders/{1}", ApplyTo.Get, x => x.Name, x => x.OrderId);
     var route = appHost.RestPaths.Last();
     Assert.That(route.Path, Is.EqualTo("/Users/{Name}/Orders/{OrderId}"));
 }