示例#1
0
        /// <summary>
        /// Used internally to build the fixture model that the Storyteller client
        /// uses to render the screens
        /// </summary>
        /// <param name="conversions"></param>
        /// <returns></returns>
        public virtual FixtureModel Compile(CellHandling conversions)
        {
            GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(methodFromThis).Where(x => !x.HasAttribute <HiddenAttribute>()).Each(method =>
            {
                var grammarKey = method.GetKey();
                if (_grammars.Has(grammarKey))
                {
                    return;
                }

                var grammar      = GrammarBuilder.BuildGrammar(method, this);
                grammar.Key      = grammarKey;
                this[grammarKey] = grammar;
            });

            var grammars = new List <GrammarModel>();

            _grammars.Each((key, grammar) =>
            {
                var model      = grammar.Compile(this, conversions);
                model.key      = key;
                model.IsHidden = grammar.IsHidden;

                grammars.Add(model);
            });

            return(new FixtureModel(Key)
            {
                title = Title ?? Key.SplitCamelCase(),
                grammars = grammars.Where(x => !x.IsHidden).ToArray(),
                implementation = GetType().FullName
            });
        }
示例#2
0
        public static Type TypeForJson(string json)
        {
            var token = JToken.Parse(json);
            var type  = token.Value <string>("type");

            return((!type.IsEmpty() && _messageTypes.Has(type))
                ?_messageTypes[type]
                : null);
        }
示例#3
0
        public TypeConfig For(string typeName)
        {
            var exists     = _typeConfigurations.Has(typeName);
            var typeConfig = _typeConfigurations[typeName];

            if (!exists)
            {
                _forAllTypesConfigurationDelegates.Apply(a => a.Invoke(typeConfig));
            }
            return(typeConfig);
        }
示例#4
0
        public T TryRetrieve <T>(string key)
        {
            if (!_byName.Has(typeof(T)))
            {
                return(default(T));
            }

            var cache = _byName[typeof(T)];

            return(cache.Has(key) ? cache[key].As <T>() : default(T));
        }
示例#5
0
        public CommandRun BuildRun(IEnumerable <string> args)
        {
            if (!args.Any())
            {
                if (DefaultCommand == null)
                {
                    return(HelpRun(new Queue <string>()));
                }
            }

            args = ArgPreprocessor.Process(args);

            var queue = new Queue <string>(args);

            if (queue.Count == 0 && DefaultCommand != null)
            {
                return(buildRun(queue, CommandNameFor(DefaultCommand)));
            }



            var firstArg = queue.Peek().ToLowerInvariant();

            if (firstArg == "dump-usages")
            {
                queue.Dequeue();
                return(dumpUsagesRun(queue));
            }

            if (_helpCommands.Contains(firstArg))
            {
                queue.Dequeue();

                return(HelpRun(queue));
            }

            if (_commandTypes.Has(firstArg))
            {
                queue.Dequeue();
                return(buildRun(queue, firstArg));
            }

            if (DefaultCommand != null)
            {
                return(buildRun(queue, CommandNameFor(DefaultCommand)));
            }
            else
            {
                return(InvalidCommandRun(firstArg));
            }
        }
示例#6
0
        public TypeConfig For(string typeName)
        {
            var exists     = _typeConfigurations.Has(typeName);
            var typeConfig = _typeConfigurations[typeName];

            if (!exists)
            {
                foreach (var a in _forAllTypesConfigurationDelegates)
                {
                    a.Invoke(typeConfig);
                }
            }
            return(typeConfig);
        }
示例#7
0
        public Specification RemoveSpec(string id)
        {
            if (!Specifications.Has(id))
            {
                return(null);
            }

            var old   = Specifications[id];
            var suite = Suites[old.SuitePath()];

            suite.RemoveSpec(old);

            Specifications.Remove(id);

            return(old);
        }
示例#8
0
        public Route RouteFor(Type handlerType, MethodInfo method)
        {
            if (!_routesPerHandler.Has(handlerType))
            {
                throw new UrlResolutionException($"There are no matching routes for handler {handlerType.FullName}");
            }

            var routes = _routesPerHandler[handlerType];

            if (!routes.Has(method.Name))
            {
                throw new UrlResolutionException($"No route matches the method {handlerType.FullName}.{method.Name}()");
            }

            var route = routes[method.Name];

            return(route);
        }
示例#9
0
 private Route RouteByName(string routeName)
 {
     return(_routesPerName.Has(routeName) ? _routesPerName[routeName] : null);
 }
示例#10
0
 public IReadOnlyList <Type> ForwardingTypesTo(Type handledType)
 {
     return(_forwarders.Has(handledType) ? _forwarders[handledType] : new List <Type>());
 }
示例#11
0
 public bool Has(Type type)
 {
     return(_convertors.Has(type) || providers().Any(x => x.ConverterFor(type) != null));
 }
示例#12
0
 bool IQueueIndexer.Has(string queueName)
 {
     return _queues.Has(queueName);
 }
示例#13
0
 public Topic FindTopicByUrl(string url)
 {
     return(_topicByUrl.Has(url) ? _topicByUrl[url] : null);
 }
示例#14
0
 public void get_all_keys()
 {
     cache.Fill(Key, 42);
     cache.Count().ShouldBe(1);
     cache.Has(Key).ShouldBeTrue();
 }
示例#15
0
 public T TryRetrieve <T>()
 {
     return(_byType.Has(typeof(T)) ? _byType[typeof(T)].As <T>() : default(T));
 }