Ejemplo n.º 1
0
        public void CommandTest()
        {
            BaseTest();
            string routeKey     = RouteKey.CreateCommandKey("/testcontroller/cmd1");
            var    commandRoute = _commandActionRouteDictionary[routeKey];

            Assert.NotNull(commandRoute);
        }
Ejemplo n.º 2
0
    private void RefreshRouteTable()
    {
        var routeKey = new RouteKey(AppAssembly, AdditionalAssemblies);

        if (!routeKey.Equals(_routeTableLastBuiltForRouteKey))
        {
            _routeTableLastBuiltForRouteKey = routeKey;
            Routes = RouteTableFactory.Create(routeKey);
        }
    }
Ejemplo n.º 3
0
    public void RouteKey_WithAdditionalAssemblies_DifferentAdditionalAssemblies()
    {
        // Arrange
        var key1 = new RouteKey(typeof(ComponentBase).Assembly, new[] { typeof(object).Assembly });
        var key2 = new RouteKey(typeof(ComponentBase).Assembly, new[] { GetType().Assembly, });

        // Act & Assert
        Assert.Equal(key1.GetHashCode(), key2.GetHashCode());
        Assert.False(key1.Equals(key2));
    }
Ejemplo n.º 4
0
    public void RouteKey_WithAdditionalAssemblies()
    {
        // Arrange
        var key1 = new RouteKey(typeof(string).Assembly, new[] { typeof(ComponentBase).Assembly, GetType().Assembly });
        var key2 = new RouteKey(typeof(string).Assembly, new[] { typeof(ComponentBase).Assembly, GetType().Assembly });

        // Act & Assert
        Assert.Equal(key1.GetHashCode(), key2.GetHashCode());
        Assert.True(key1.Equals(key2));
    }
Ejemplo n.º 5
0
    public void RouteKey_DefaultAgainstNonDefault()
    {
        // Arrange
        var key1 = default(RouteKey);
        var key2 = new RouteKey(typeof(string).Assembly, null);

        // Act & Assert
        Assert.NotEqual(key1.GetHashCode(), key2.GetHashCode());
        Assert.False(key1.Equals(key2));
    }
Ejemplo n.º 6
0
    public void RouteKey_WithNoAdditionalAssemblies_DifferentAssemblies()
    {
        // Arrange
        var key1 = new RouteKey(typeof(string).Assembly, null);
        var key2 = new RouteKey(typeof(ComponentBase).Assembly, null);

        // Act & Assert
        Assert.NotEqual(key1.GetHashCode(), key2.GetHashCode());
        Assert.False(key1.Equals(key2));
    }
Ejemplo n.º 7
0
    public void RouteKey_WithNoAdditionalAssemblies_Equality()
    {
        // Arrange
        var key1 = new RouteKey(typeof(string).Assembly, null);
        var key2 = new RouteKey(typeof(string).Assembly, null);

        // Act & Assert
        Assert.Equal(key1.GetHashCode(), key2.GetHashCode());
        Assert.True(key1.Equals(key2));
    }
Ejemplo n.º 8
0
        public void SaveInvokeTest()
        {
            BaseTest();
            string routeKey  = RouteKey.CreateRequestKey("/testcontroller/movies");
            var    routeSave = _requestActionRouteDictionary[routeKey];

            Assert.NotNull(routeSave);

            var parameter = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            var response  = routeSave.Invoke(new ChromelyRequest("/testcontroller/movies", null, parameter));

            Assert.NotNull(response);
            Assert.True(response.Data is string);
            Assert.Equal(parameter, (string)response.Data);
        }
Ejemplo n.º 9
0
        public void Get2InvokeTest()
        {
            BaseTest();

            string routeKey  = RouteKey.CreateRequestKey("/testcontroller/movies/2");
            var    routeGet2 = _requestActionRouteDictionary[routeKey];

            Assert.NotNull(routeGet2);

            IChromelyResponse response = routeGet2.Invoke(new ChromelyRequest("/testcontroller/movies/2", null, null));

            Assert.NotNull(response);
            Assert.True(response.Data is string);
            Assert.Equal("Test Get 2", (string)response.Data);
        }
Ejemplo n.º 10
0
        public void Get1InvokeTest()
        {
            BaseTest();

            string routeKey  = RouteKey.CreateRequestKey("/testcontroller/movies/1");
            var    routeGet1 = _requestActionRouteDictionary[routeKey];

            Assert.NotNull(routeGet1);

            var response = routeGet1.Invoke(new ChromelyRequest("/testcontroller/movies/1", null, null));

            Assert.NotNull(response);
            Assert.True(response.Data is int);
            Assert.Equal(1000, (int)response.Data);
        }
Ejemplo n.º 11
0
        public virtual CommandActionRoute GetCommandRoute(string commandUrl)
        {
            var key = RouteKey.CreateCommandKey(commandUrl);

            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            EnsureContainersAreInitialized();
            if (CommandRouteDictionary.ContainsKey(key))
            {
                return(CommandRouteDictionary[key]);
            }

            return(null);
        }
Ejemplo n.º 12
0
        public virtual RequestActionRoute GetActionRoute(string routeUrl)
        {
            var key = RouteKey.CreateRequestKey(routeUrl);

            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            EnsureContainersAreInitialized();
            if (ActionRouteDictionary.ContainsKey(key))
            {
                return(ActionRouteDictionary[key]);
            }

            return(null);
        }
Ejemplo n.º 13
0
    public Route GetRoute(Location startLoc, Location endLoc)
    {
        Route    retRoute;
        RouteKey routeKey = new RouteKey(startLoc.LocID, endLoc.LocID);

        // Try to get the route from the cache
        if (routeCache.TryGetValue(routeKey, out retRoute))
        {
            retRoute = routeCache[routeKey];
        }
        // If not in cache, generate and add it
        else
        {
            retRoute = CalculateRoute(startLoc, endLoc);
            routeCache.Add(routeKey, retRoute);
        }

        return(retRoute);
    }
Ejemplo n.º 14
0
 private void ClearRouteCaches()
 {
     RouteTableFactory.ClearCaches();
     _routeTableLastBuiltForRouteKey = default;
 }
Ejemplo n.º 15
0
 internal RouteMapper()
 {
     root = new RouteKey();
 }
Ejemplo n.º 16
0
        private (RouteLeaf route, List <PathParameter> pathParams) MatchingContract(string[] pathTokens, string verb, RouteKey root, List <PathParameter> @params, int startIndex = 0)
        {
            if (startIndex == pathTokens.Length)
            {
                var routeMatch = root.Contracts.FirstOrDefault(leaf => leaf.Verb == verb);
                if (routeMatch == null)
                {
                    return(null, null);
                }
                return(routeMatch, @params);
            }
            var component = pathTokens[startIndex];
            //TODO allow configurable case sensitive mapping;
            var componentLower = component.ToLower();

            if (root.Children.ContainsKey(componentLower))
            {
                var(match, pathParams) = MatchingContract(pathTokens, verb, root.Children[componentLower], @params, startIndex + 1);
                if (match != null)
                {
                    return(match, pathParams);
                }
            }
            if (root.Children.ContainsKey(ParameterDelimiter))
            {
                @params.Add(new PathParameter
                {
                    PathIndex          = startIndex,
                    MappedPropertyName = null,
                    ParameterValue     = component
                });
                var(match, pathParams) = MatchingContract(pathTokens, verb, root.Children[ParameterDelimiter], @params, startIndex + 1);
                if (match != null)
                {
                    return(match, pathParams);
                }
            }
            return(null, null);
        }