public static Resource GetResource <T>(this FubuMVC.Swank.Specification.Specification specification) { var url = typeof(T).GetHandlerUrl(new StackFrame(1).GetMethod().DeclaringType.Namespace); return(specification.Modules.SelectMany(x => x.Resources) .FirstOrDefault(x => x.Endpoints.Any(y => y.Url == url))); }
public static Endpoint GetEndpoint <T>(this FubuMVC.Swank.Specification.Specification specification) { var url = typeof(T).GetHandlerUrl(new StackFrame(1).GetMethod().DeclaringType.Namespace); return(specification.Modules.SelectMany(x => x.Resources).Concat(specification.Resources) .SelectMany(x => x.Endpoints).FirstOrDefault(x => x.Url.Split('?')[0] == url)); }
public void should_merge_overlapping_resource_modules() { var spec2 = new FubuMVC.Swank.Specification.Specification { Modules = new List <Module> { new Module { Name = "Some module", Resources = new List <Resource> { new Resource { Name = "Some module resource", Endpoints = new List <Endpoint> { new Endpoint { Url = "/overlappingmoduleresource", Method = "POST" }, new Endpoint { Url = "/overlappingmoduleresource", Method = "GET" } } } } } } }; var spec = new MergeService().Merge(_spec1, spec2); spec.Modules.Count.ShouldEqual(1); var module = spec.Modules[0]; module.Name.ShouldEqual("Some module"); module.Comments.ShouldEqual("Some module comments"); module.Resources.Count.ShouldEqual(1); var resource = module.Resources[0]; resource.Name.ShouldEqual("Some module resource"); resource.Comments.ShouldEqual("Some module resource comments"); resource.Endpoints.Count.ShouldEqual(3); var endpoint = resource.Endpoints[0]; endpoint.Name.ShouldBeNull(); endpoint.Comments.ShouldBeNull(); endpoint.Url.ShouldEqual("/overlappingmoduleresource"); endpoint.Method.ShouldEqual("GET"); endpoint = resource.Endpoints[1]; endpoint.Name.ShouldBeNull(); endpoint.Comments.ShouldBeNull(); endpoint.Url.ShouldEqual("/overlappingmoduleresource"); endpoint.Method.ShouldEqual("POST"); endpoint = resource.Endpoints[2]; endpoint.Name.ShouldEqual("Some endpoint"); endpoint.Comments.ShouldEqual("Some endpoint comments"); endpoint.Url.ShouldEqual("/some/url"); endpoint.Method.ShouldEqual("METHOD"); }
public void Setup() { var dir = Path.GetDirectoryName(typeof(MergeServiceTests).Assembly.CodeBase); dir = new Uri(dir).LocalPath; Directory.SetCurrentDirectory(dir); _jsonPath = Path.GetFullPath(@"Specification\MergeServiceTests\Merge.json"); _spec1 = File.ReadAllText(_jsonPath).DeserializeJson <FubuMVC.Swank.Specification.Specification>(); }
public void should_merge_overlapping_modules() { var spec2 = new FubuMVC.Swank.Specification.Specification { Modules = new List <Module> { new Module { Name = "Some module", Resources = new List <Resource> { new Resource { Name = "/overlappingmodule", Endpoints = new List <Endpoint> { new Endpoint { Url = "" } } } } } } }; var spec = new MergeService().Merge(_spec1, spec2); spec.Modules.Count.ShouldEqual(1); var module = spec.Modules[0]; module.Name.ShouldEqual("Some module"); module.Comments.ShouldEqual("Some module comments"); module.Resources.Count.ShouldEqual(2); var resource = module.Resources[0]; resource.Name.ShouldEqual("/overlappingmodule"); resource.Comments.ShouldBeNull(); resource.Endpoints.Count.ShouldEqual(1); resource = module.Resources[1]; resource.Name.ShouldEqual("Some module resource"); resource.Comments.ShouldEqual("Some module resource comments"); resource.Endpoints.Count.ShouldEqual(1); }
public void Setup() { Spec = GetSpec(); }
public Specification Generate() { var behaviorMappings = GetBehaviorMapping(_behaviors.GetChains()); CheckForOrphanedChains(behaviorMappings); var modules = GetModules(behaviorMappings.Where(x => x.Module != null).ToList()); var resources = GetResources(behaviorMappings.Where(x => x.Module == null).ToList()); if (resources.Any()) modules.Add(new Module { Name = Module.DefaultName, Resources = resources }); var specification = new Specification { FavIconUrl = _configuration.FavIconUrl, Title = _configuration.Title ?? _configuration.Name, Name = _configuration.Name, LogoUrl = _configuration.LogoUrl, Comments = _configuration.AppliesToAssemblies.FindTextResourceNamed("*" + _configuration.Comments), Modules = modules }; return specification; }