Esempio n. 1
0
        private void PopulateRoutingTableWithHandlers(RoutingTable routingTable, IEnumerable <Type> handlerTypes)
        {
            foreach (var exportedType in handlerTypes)
            {
                var respondsWithTypes = RespondsWithAttribute.Get(exportedType).SelectMany(rta => rta.ContentTypes).ToList();
                var respondsToTypes   = RespondsToAttribute.Get(exportedType).SelectMany(rta => rta.ContentTypes).ToList();
                foreach (var uriTemplate in UriTemplateAttribute.GetAllTemplates(exportedType))
                {
                    if (exportedType.IsGenericTypeDefinition)
                    {
                        BuildRoutesForGenericHandlerType(routingTable, exportedType, uriTemplate, respondsToTypes, respondsWithTypes);
                    }
                    else
                    {
                        routingTable.Add(uriTemplate, new HandlerTypeInfo(exportedType, respondsToTypes, respondsWithTypes));
                    }
                }

                // If it's the LoginPage, set it to the configuration
                if (SimpleWeb.Configuration.LoginPage == null && typeof(ILoginPage).IsAssignableFrom(exportedType))
                {
                    SimpleWeb.Configuration.LoginPage = exportedType;
                }
            }
        }
        public void BuildsCompundUriTemplate()
        {
            var actual = UriTemplateAttribute.GetAllTemplates(typeof(CompoundTest)).ToList();

            Assert.Equal(4, actual.Count);
            Assert.Contains("/foo/quux/", actual);
            Assert.Contains("/foo/wibble/", actual);
            Assert.Contains("/bar/quux/", actual);
            Assert.Contains("/bar/wibble/", actual);
        }
Esempio n. 3
0
        private static Link CreateLink(Type type, LinkAttributeBase linkAttribute)
        {
            string uriTemplate;

            if (string.IsNullOrWhiteSpace(linkAttribute.UriTemplate))
            {
                try
                {
                    uriTemplate = UriTemplateAttribute.GetAllTemplates(type).Single();
                }
                catch (InvalidOperationException)
                {
                    throw new InvalidOperationException("Must specify a UriTemplate for LinkAttribute where more than one UriTemplateAttribute is used.");
                }
            }
            else
            {
                uriTemplate = linkAttribute.UriTemplate;
            }

            return(new Link(type, uriTemplate, linkAttribute.GetRel(), linkAttribute.Type, linkAttribute.Title));
        }
        public void OverrideExcludesBase()
        {
            var actual = UriTemplateAttribute.GetAllTemplates(typeof(OverrideBaseTest)).Single();

            Assert.Equal("/override", actual);
        }
        public void StillFindsSingleTemplate()
        {
            var actual = UriTemplateAttribute.GetAllTemplates(typeof(NoBaseTest)).Single();

            Assert.Equal("/rock", actual);
        }
Esempio n. 6
0
        public void SkipsMiddleBase()
        {
            var actual = UriTemplateAttribute.GetAllTemplates(typeof(Bottom)).Single();

            Assert.Equal("/top/bottom", actual);
        }