Пример #1
0
 internal Task RegisterRoutesAsync(IEnumerable <IRouteDefinitions> routeDefs)
 {
     lock (_lockObject)
     {
         _routes = RoutesUtils.GetValidRouteDefs(routeDefs);
         _routeDefinitionProvider = null;
         _useProvider             = false;
     }
     return(Task.CompletedTask);
 }
        public void GetValidRouteDefsTest()
        {
            TestingUtils.ResetRoutesRepository();
            var result = RoutesUtils.GetValidRouteDefs(new List <IRouteDefinitions>()
            {
                new Routes()
            });

            Assert.Equal(7, result.Keys.Count);
            Assert.Equal(2, result["PUT"].Count);
        }
 public void GetValidRouteDefsTest_InvalidRouteTemplate()
 {
     TestingUtils.ResetRoutesRepository();
     try
     {
         RoutesUtils.GetValidRouteDefs(new List <IRouteDefinitions>()
         {
             new InvalidRouteTemplateRoutes()
         });
     }
     catch (Exception)
     {
         return;
     }
     Assert.True(false);
 }
Пример #4
0
        internal async Task <Dictionary <string, List <InternalRouteDefinition> > > GetRoutesAsync()
        {
            if (!_useProvider || _routeDefinitionProvider == null)
            {
                return(_routes);
            }
            LoadRefreshTimestamp();
            if (DateTime.Now - _lastRetrievedAt > _refreshTimespan)
            {
                var routes = await _routeDefinitionProvider.GetAsync().ConfigureAwait(false);

                var routesDict = RoutesUtils.GetValidRouteDefs(routes);
                lock (_refreshLockObject)
                {
                    _routes          = routesDict;
                    _lastRetrievedAt = DateTime.Now;
                }
            }
            return(_routes);
        }
 public void GetValidRouteDefsTest_NullRouteDefs()
 {
     TestingUtils.ResetRoutesRepository();
     Assert.Equal(new Dictionary <string, List <InternalRouteDefinition> >(), RoutesUtils.GetValidRouteDefs(null));
 }