Ejemplo n.º 1
0
        protected static void UpdateConfigure(EndpointRouteConfiguration configuration)
        {
            // Add your custom routes
            configuration.AddControllers(typeof(EpCustomersController));

            configuration.MaxTop(2).Expand().Select().OrderBy().Filter();

            configuration.MapODataRoute("odata", "odata", EndpointModelGenerator.GetConventionalEdmModel());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize the fixture.
        /// </summary>
        private void Initialize()
        {
            SecurityHelper.AddIpListen();

            // Be noted:
            // We use the convention as follows
            // 1) if you want to configure the service, add "protected static void UpdateConfigureServices(IServiceCollection)" method into your test class.
            // 2) if you want to configure the routing, add "protected static void updateConfigure(EndpointRouteConfiguration)" method into your test class.
            Type       testType = typeof(T);
            MethodInfo configureServicesMethod = testType.GetMethod("UpdateConfigureServices", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo configureMethod         = testType.GetMethod("UpdateConfigure", BindingFlags.NonPublic | BindingFlags.Static);
            // Owing that this is used in Test only, I assume every developer can following the convention.
            // So I skip the method parameter checking.

            string serverName = "localhost";

            // setup base address
            int port = PortArranger.Reserve();

            this.BaseAddress = string.Format(NormalBaseAddressTemplate, serverName, port.ToString());

            _selfHostServer = Host.CreateDefaultBuilder()
                              .ConfigureWebHostDefaults(webBuilder => webBuilder
                                                        .UseKestrel(options => options.Listen(IPAddress.Loopback, port))
                                                        .ConfigureServices(services =>
            {
                services.AddHttpClient();         // Add IHttpClientFactory
                services.AddOData();
                services.AddRouting();

                // Apply custom services for each test class
                configureServicesMethod?.Invoke(null, new object[] { services });
            })
                                                        .Configure(app =>
            {
                this.ClientFactory = app.ApplicationServices.GetRequiredService <IHttpClientFactory>();

                // should add ODataBatch middleware before the routing middelware
                app.UseODataBatching();
                app.UseRouting();
                app.UseEndpoints(endpoints =>
                {
                    // Apply test configuration.
                    EndpointRouteConfiguration config = new EndpointRouteConfiguration(endpoints);
                    configureMethod?.Invoke(null, new object[] { config });
                });
            })
                                                        .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddDebug();
                logging.SetMinimumLevel(LogLevel.Warning);
            }
                                                                          )).Build();

            _selfHostServer.Start();
        }
Ejemplo n.º 3
0
        protected static void UpdateConfigure(EndpointRouteConfiguration configuration)
        {
            // Add your custom routes
            configuration.AddControllers(typeof(EpCustomersController));

            configuration.MaxTop(2).Expand().Select().OrderBy().Filter();

            EdmModel = EndpointModelGenerator.GetConventionalEdmModel();
            configuration.MapODataRoute("odata", "odata",
                                        EdmModel,
                                        new DefaultODataPathHandler(),
                                        ODataRoutingConventions.CreateDefault(),
                                        new DefaultODataBatchHandler());
        }