public void should_apply_a_caching_node_before_the_action_that_uses_the_asset_content_cache() { var cachingNode = theChain.FirstCall().Previous.ShouldBeOfType <OutputCachingNode>(); cachingNode.ETagCache.Value.ShouldBeOfType <AssetContentCache>(); cachingNode.OutputCache.Value.ShouldBeOfType <AssetContentCache>(); }
private List <Member> GetMembers(System.Type type, BehaviorChain chain) { ActionCall action = null; if (chain != null) { action = chain.FirstCall(); } var properties = type.IsProjection() ? type.GetProjectionProperties() : _typeCache.GetPropertiesFor(type).Select(x => x.Value); return(properties .Where(x => !x.IsHidden() && !x.IsAutoBound() && !x.IsQuerystring(action) && !x.IsUrlParameter(action)) .Select(x => { var description = _memberConvention.GetDescription(x); var memberType = description.WhenNotNull(y => y.Type).Otherwise(x.PropertyType.GetListElementType(), x.PropertyType); return _configuration.MemberOverrides.Apply(x, new Member { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), DefaultValue = description.WhenNotNull(y => y.DefaultValue).WhenNotNull(z => z.ToDefaultValueString(_configuration)).OtherwiseDefault(), Required = description.WhenNotNull(y => y.Required).OtherwiseDefault(), Type = memberType.IsSystemType() || memberType.IsEnum ? memberType.GetXmlName() : _configuration.TypeIdConvention(memberType), IsArray = x.PropertyType.IsArray || x.PropertyType.IsList(), ArrayItemName = description.WhenNotNull(y => y.ArrayItemName).OtherwiseDefault(), Options = GetOptions(x.PropertyType) }); }) .ToList()); }
public bool Matches(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) return true; return !call.HasAttribute<NotValidatedAttribute>() && !call.InputType().HasAttribute<NotValidatedAttribute>(); }
static bool IsNotFubuChain(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) { return(false); } return(call.HandlerType.Assembly != typeof(FubuRegistry).Assembly); }
static bool IsNotSwankChain(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) { return(false); } return(call.HandlerType.Assembly != typeof(BehaviorSource).Assembly); }
public virtual List<StatusCodeDescription> GetDescription(BehaviorChain chain) { var action = chain.FirstCall(); return action.Method.GetCustomAttributes<StatusCodeAttribute>() .Concat(action.HandlerType.GetCustomAttributes<StatusCodeAttribute>()) .Select(x => new StatusCodeDescription { Code = x.Code, Name = x.Name, Comments = x.Comments }).OrderBy(x => x.Code).ToList(); }
public bool Matches(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) { return(true); } return(!call.HasAttribute <NotValidatedAttribute>() && !call.InputType().HasAttribute <NotValidatedAttribute>()); }
public virtual List <MimeTypeDescription> GetDescription(BehaviorChain chain) { var action = chain.FirstCall(); return(action.Method.GetCustomAttributes <MimeTypeAttribute>() .Concat(action.HandlerType.GetCustomAttributes <MimeTypeAttribute>()) .Select(x => new MimeTypeDescription { Direction = x.Type, Name = x.Name }).OrderBy(x => x.Direction).ThenBy(x => x.Name).ToList()); }
public void should_build_action_call_logs() { var call = _chain.FirstCall(); var logs = _graph.Observer.GetLog(call); ClassUnderTest .VisualizerFor(_chain.UniqueId) .Behaviors .Single(b => b.BehaviorType == call.ToString()) .Logs .ShouldEqual(logs); }
public virtual List <HeaderDescription> GetDescription(BehaviorChain chain) { var action = chain.FirstCall(); return(action.Method.GetCustomAttributes <HeaderDescriptionAttribute>() .Concat(action.HandlerType.GetCustomAttributes <HeaderDescriptionAttribute>()) .Select(x => new HeaderDescription { Type = x.Type, Name = x.Name, Comments = x.Comments, Optional = x.Optional }).OrderBy(x => x.Type).ThenBy(x => x.Name).ToList()); }
public static void Modify(BehaviorChain chain) { // Not everything is hard chain.Output.Remove(); if (chain.OfType <InputNode>().Any()) { chain.Input.AddAfter(chain.Output); } else { chain.FirstCall().AddBefore(chain.Output); } }
private void attachMediaHandling(BehaviorChain chain, IConfigurationObserver observer) { var firstAction = chain.FirstCall(); if (firstAction == null) return; observer.RecordCallStatus(firstAction, "Meets criteria {0} for Conneg".ToFormat(_description)); var node = new ConnegNode(){ InputType = chain.InputType(), OutputType = chain.Calls.Where(x => x.HasOutput).Select(x => x.OutputType()).LastOrDefault() }; firstAction.AddBefore(node); }
public static void Modify(BehaviorChain chain) { // Not everything is hard chain.Output.Remove(); if (chain.OfType<InputNode>().Any()) { chain.Input.AddAfter(chain.Output); } else { chain.FirstCall().AddBefore(chain.Output); } }
public void VisitRoute(IRouteDefinition route, BehaviorChain chain) { ActionCall action = chain.FirstCall(); if (action == null) return; if (action.HasInput) { // TODO: throw if route is null; var model = (IModelUrl) route; _registration.AddModel(model); } var actionUrl = new ActionUrl(route, action); _registration.AddAction(actionUrl); }
private Data GetRequest(BehaviorChain chain, EndpointDescription endpoint) { var firstCall = chain.FirstCall(); DataType type = null; List <BodyLineItem> description = null; if (firstCall.HasInput && !chain.Route.AllowsGet() && !chain.Route.AllowsDelete()) { type = _typeGraphFactory.BuildGraph(firstCall.InputType(), chain.FirstCall()); description = _bodyDescriptionFactory.Create(type); } return(_configuration.RequestOverrides.Apply(chain, new Data { Comments = endpoint.RequestComments, Headers = GetHeaders(chain, HttpDirection.Request), MimeTypes = GetMimeTypes(chain, HttpDirection.Request), Body = new Body { Type = type, Description = description } })); }
public FormMode ModeFor(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null || call.HasAttribute<NoFormModeAttribute>()) { return FormMode.None; } if (call.HasInput && call.InputType().HasAttribute<NoFormModeAttribute>()) { return FormMode.None; } var policy = policyFor(chain) ?? FormModePolicy.Default(); return policy.ModeFor(chain); }
public FormMode ModeFor(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null || call.HasAttribute <NoFormModeAttribute>()) { return(FormMode.None); } if (call.HasInput && call.InputType().HasAttribute <NoFormModeAttribute>()) { return(FormMode.None); } var policy = policyFor(chain) ?? FormModePolicy.Default(); return(policy.ModeFor(chain)); }
private List <UrlParameter> GetUrlParameters(BehaviorChain chain) { var action = chain.FirstCall(); var properties = _typeCache.GetPropertiesFor(action.InputType()); return(action.ParentChain().Route.Input.RouteParameters.Select( x => { var property = properties[x.Name]; var description = _memberConvention.GetDescription(property); return _configuration.UrlParameterOverrides.Apply(chain, property, new UrlParameter { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), Type = property.PropertyType.GetXmlName(_configuration.EnumFormat == EnumFormat.AsString), Options = _optionFactory.BuildOptions(property.PropertyType) }); }).ToList()); }
private void attachMediaHandling(BehaviorChain chain, IConfigurationObserver observer) { var firstAction = chain.FirstCall(); if (firstAction == null) { return; } observer.RecordCallStatus(firstAction, "Meets criteria {0} for Conneg".ToFormat(_description)); var node = new ConnegNode() { InputType = chain.InputType(), OutputType = chain.Calls.Where(x => x.HasOutput).Select(x => x.OutputType()).LastOrDefault() }; firstAction.AddBefore(node); }
// This should not do anything if there are conneg nodes public static void ApplyConneg(this BehaviorChain chain) { var inputType = chain.InputType(); if (chain.ConnegInputNode() == null && inputType != null) { var inputNode = new ConnegInputNode(inputType); var action = chain.FirstCall(); action.AddBefore(inputNode); } var actionOutputType = chain.ActionOutputType(); if (chain.ConnegOutputNode() == null && actionOutputType != null && actionOutputType != typeof(void) && actionOutputType != typeof(HttpStatusCode)) { var outputNode = new ConnegOutputNode(actionOutputType); var action = chain.Last(x => x is ActionCall); action.AddAfter(outputNode); } }
private List <QuerystringParameter> GetQuerystringParameters(BehaviorChain chain) { var action = chain.FirstCall(); return(_typeCache.GetPropertiesFor(action.InputType()) .Where(x => x.Value.IsQuerystring(action) && !x.Value.HasAttribute <HideAttribute>() && !x.Value.IsAutoBound()) .Select(x => { var description = _memberConvention.GetDescription(x.Value); return _configuration.QuerystringOverrides.Apply(chain, x.Value, new QuerystringParameter { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), Type = (x.Value.PropertyType.GetListElementType() ?? x.Value.PropertyType).GetXmlName(_configuration.EnumFormat == EnumFormat.AsString), Options = _optionFactory.BuildOptions(x.Value.PropertyType), DefaultValue = description.DefaultValue.WhenNotNull(y => y.ToSampleValueString(_configuration)).OtherwiseDefault(), MultipleAllowed = x.Value.PropertyType.IsArray || x.Value.PropertyType.IsList(), Required = !description.Optional }); }).OrderBy(x => x.Name).ToList()); }
private static IEnumerable <TypeContext> RootInputAndOutputModels(BehaviorChain chain) { var firstCall = chain.FirstCall(); var lastCall = chain.LastCall(); if (firstCall.HasInput && !chain.Route.AllowsGet() && !chain.Route.AllowsDelete()) { var inputType = firstCall.InputType(); inputType = inputType.GetListElementType() ?? inputType; yield return(new TypeContext(inputType, chain: chain)); } if (lastCall.HasOutput) { var outputType = lastCall.OutputType(); outputType = outputType.GetListElementType() ?? outputType; yield return(new TypeContext(outputType)); } }
static bool IsNotSwankChain(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) return false; return call.HandlerType.Assembly != typeof(BehaviorSource).Assembly; }
bool isNotConfigThing(BehaviorChain chain) { return(!_configuration.AppliesToAssemblies.Any() || _configuration.AppliesToAssemblies.Any(y => y == chain.FirstCall().HandlerType.Assembly)); }
static bool IsNotFubuChain(BehaviorChain chain) { var call = chain.FirstCall(); if (call == null) return false; return call.HandlerType.Assembly != typeof (FubuRegistry).Assembly; }
public void should_be_a_PublishEvent_node_directly_after_the_publishing_action() { // diagnostics are in here now. chain.FirstCall().Next.ShouldBeOfType <SendsMessage>() .EventType.ShouldBe(typeof(Message1)); }
public static string FirstCallDescription(this BehaviorChain chain) { var call = chain.FirstCall(); return(call == null ? string.Empty : call.Description); }
bool IsNotConfigThing(BehaviorChain chain) { return (!_configuration.AppliesToAssemblies.Any() || _configuration.AppliesToAssemblies.Any(y => y == chain.FirstCall().HandlerType.Assembly)); }
private List<QuerystringParameter> GetQuerystringParameters(BehaviorChain chain) { var action = chain.FirstCall(); return _typeCache.GetPropertiesFor(action.InputType()) .Where(x => x.Value.IsQuerystring(action) && !x.Value.HasAttribute<HideAttribute>() && !x.Value.IsAutoBound()) .Select(x => { var description = _memberConvention.GetDescription(x.Value); return _configuration.QuerystringOverrides.Apply(chain, x.Value, new QuerystringParameter { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), Type = (x.Value.PropertyType.GetListElementType() ?? x.Value.PropertyType).GetXmlName(_configuration.EnumFormat == EnumFormat.AsString), Options = _optionFactory.BuildOptions(x.Value.PropertyType), DefaultValue = description.DefaultValue.WhenNotNull(y => y.ToSampleValueString(_configuration)).OtherwiseDefault(), MultipleAllowed = x.Value.PropertyType.IsArray || x.Value.PropertyType.IsList(), Required = !description.Optional }); }).OrderBy(x => x.Name).ToList(); }
private List<UrlParameter> GetUrlParameters(BehaviorChain chain) { var action = chain.FirstCall(); var properties = _typeCache.GetPropertiesFor(action.InputType()); return action.ParentChain().Route.Input.RouteParameters.Select( x => { var property = properties[x.Name]; var description = _memberConvention.GetDescription(property); return _configuration.UrlParameterOverrides.Apply(chain, property, new UrlParameter { Name = description.WhenNotNull(y => y.Name).OtherwiseDefault(), Comments = description.WhenNotNull(y => y.Comments).OtherwiseDefault(), Type = property.PropertyType.GetXmlName(_configuration.EnumFormat == EnumFormat.AsString), Options = _optionFactory.BuildOptions(property.PropertyType) }); }).ToList(); }
private Data GetRequest(BehaviorChain chain, EndpointDescription endpoint) { var firstCall = chain.FirstCall(); DataType type = null; List<BodyLineItem> description = null; if (firstCall.HasInput && !chain.Route.AllowsGet() && !chain.Route.AllowsDelete()) { type = _typeGraphFactory.BuildGraph(firstCall.InputType(), chain.FirstCall()); description = _bodyDescriptionFactory.Create(type); } return _configuration.RequestOverrides.Apply(chain, new Data { Comments = endpoint.RequestComments, Headers = GetHeaders(chain, HttpDirection.Request), MimeTypes = GetMimeTypes(chain, HttpDirection.Request), Body = new Body { Type = type, Description = description } }); }