private void DiscoverMediatrRoutes()
        {
            _configuration.Routes.MapHttpRoute(
                "process",
                "process",
                new { controller = "ServiceBus", action = "Process" });

            _configuration.Routes.MapHttpRoute(
                "publish",
                "publish",
                new { controller = "ServiceBus", action = "Publish" });

            _configuration.Routes.MapHttpRoute(
                "tag",
                "tag/{client}/{args*}",
                new { Controller = "ServiceBus", Action = "Process" });

            MediatRInstaller.RequestsSupported += requestMetadatas =>
            {
                foreach (var metadata in requestMetadatas)
                {
                    var request     = metadata.RequestType;
                    var requestPath = ServiceBusRouter.GetRequestPath(request);
                    var template    = $"process/{requestPath}";
                    AddServiceBusRoute("Process", template);
                    AddServiceBusRoute("Process", $"{template}/{{args*}}");
                }
            };

            MediatRInstaller.NotificationsSupported += requestMetadatas =>
            {
                foreach (var metadata in requestMetadatas)
                {
                    var request     = metadata.RequestType;
                    var requestPath = ServiceBusRouter.GetRequestPath(request);
                    var template    = $"publish/{requestPath}";
                    AddServiceBusRoute("Publish", template);
                }
            };
        }
        private IEnumerable <KeyValuePair <string, PathItem> > BuildPaths(
            string resource, SchemaRegistry registry, IEnumerable <RequestMetadata> requests)
        {
            var stringSchema        = registry.GetOrRegister(typeof(string));
            var unprocessableSchema = registry.GetOrRegister(typeof(ValidationFailureShim));

            return(requests.Select(x =>
            {
                var assembly = x.RequestType.Assembly.GetName();
                var tag = $"{assembly.Name} [{assembly.Version}]";
                var requestSchema = GetMessageSchema(registry, x.RequestType);
                var responseSchema = GetMessageSchema(registry, x.ResponseType);
                var requestPath = ServiceBusRouter.GetRequestPath(x.RequestType);

                var requestSummary = GetReferencedSchema(registry,
                                                         registry.GetOrRegister(x.RequestType))?.description;

                var handlerAssembly = x.HandlerType.Assembly.GetName();
                var handlerNotes = $"Handled by {x.HandlerType.FullName} in {handlerAssembly.Name} [{handlerAssembly.Version}]";

                return new KeyValuePair <string, PathItem>($"/{resource}/{requestPath}", new PathItem
                {
                    post = new Operation
                    {
                        summary = requestSummary,
                        operationId = x.RequestType.FullName,
                        description = handlerNotes,
                        tags = new [] { tag },
                        consumes = JsonFormats,
                        produces = JsonFormats,
                        parameters = new []
                        {
                            new Parameter
                            {
                                @in = "body",
                                name = "message",
                                description = "request to process",
                                schema = requestSchema,
                                required = true
                            }
                        },
                        responses = new Dictionary <string, Response>
                        {
                            {
                                "200", new Response {
                                    description = "OK",
                                    schema = responseSchema
                                }
                            },
                            {
                                "422", new Response {
                                    description = "Unprocessable",
                                    schema = unprocessableSchema
                                }
                            },
                            {
                                "409", new Response {
                                    description = "Concurrency Conflict",
                                    schema = stringSchema
                                }
                            }
                        }
                    }
                });
            }));
        }
Exemple #3
0
        public void Should_Return_Nothing_If_Generic_Request_Type()
        {
            var path = ServiceBusRouter.GetRequestPath(typeof(GetRequest <Stock, Stock>));

            Assert.IsNull(path);
        }
Exemple #4
0
        public void Should_Return_Nothing_If_Not_Request_Instance()
        {
            var path = ServiceBusRouter.GetRequestPath(this);

            Assert.IsNull(path);
        }
Exemple #5
0
        public void Should_Return_Nothing_If_Generic_Request_Definition()
        {
            var path = ServiceBusRouter.GetRequestPath(typeof(GetRequest <,>));

            Assert.IsNull(path);
        }
Exemple #6
0
        public void Should_Return_Nothing_If_Not_Request_Type()
        {
            var path = ServiceBusRouter.GetRequestPath(typeof(ServiceBusRouterTests));

            Assert.IsNull(path);
        }
Exemple #7
0
        public void Should_Get_Path_For_Decorated_Request()
        {
            var path = ServiceBusRouter.GetRequestPath(new GetStocks().Cached().RouteTo(""));

            Assert.AreEqual("improving/aspNet/tests/domain/getStocks/routed/cached", path);
        }
Exemple #8
0
        public void Should_Get_Path_For_Request_Decorator()
        {
            var path = ServiceBusRouter.GetRequestPath(typeof(Cached <StocksResult>));

            Assert.AreEqual("cached", path);
        }
Exemple #9
0
        public void Should_Get_Path_For_Notification_Instance()
        {
            var path = ServiceBusRouter.GetRequestPath(new StockChanged());

            Assert.AreEqual("improving/aspNet/tests/domain/stockChanged", path);
        }
Exemple #10
0
        public void Should_Get_Path_For_Request_Instance()
        {
            var path = ServiceBusRouter.GetRequestPath(new GetStocks());

            Assert.AreEqual("improving/aspNet/tests/domain/getStocks", path);
        }