/// <summary>
        /// This is a generic endpoint definition generator, you can override it in your test class if you want to send something different.
        /// </summary>
        /// <param name="schemaBuilder"></param>
        /// <returns></returns>
        protected virtual async Task <EndpointClientDefinition> CreateEndpointDefinition(ISchemaBuilder schemaBuilder)
        {
            var endpoint    = new EndpointClientDefinition(typeof(TResult), await schemaBuilder.GetSchema(typeof(TResult)));
            var endpointDoc = new EndpointDoc();

            endpointDoc.RequestSchema = await schemaBuilder.GetSchema(typeof(TInput));

            endpoint.AddLink(new EndpointClientLinkDefinition("Save", endpointDoc, false));
            return(endpoint);
        }
示例#2
0
        protected override async Task <EndpointClientDefinition> CreateEndpointDefinition(ISchemaBuilder schemaBuilder)
        {
            var endpoint    = new EndpointClientDefinition(typeof(EntryPoint), await schemaBuilder.GetSchema(typeof(EntryPoint)));
            var endpointDoc = new EndpointDoc();

            endpointDoc.ResponseSchema = await schemaBuilder.GetSchema(typeof(EntryPoint));

            endpoint.AddLink(new EndpointClientLinkDefinition("self", endpointDoc, false));
            return(endpoint);
        }
示例#3
0
        public async Task <IEnumerable <EndpointClientDefinition> > GetEndpointDefinitions()
        {
            var definitions = new List <EndpointClientDefinition>();

            foreach (var type in resultViewProvider.GetResultViewTypes())
            {
                EndpointClientDefinition clientDef = new EndpointClientDefinition(type, await schemaBuilder.GetSchema(type));
                var customAttrs = type.GetTypeInfo().GetCustomAttributes();
                foreach (var link in customAttrs)
                {
                    var actionLink = link as HalActionLinkAttribute;
                    if (actionLink != null)
                    {
                        var doc = await endpointDocBuilder.GetDoc(actionLink.GroupName, actionLink.Method, actionLink.UriTemplate.Substring(1));

                        clientDef.AddLink(new EndpointClientLinkDefinition(actionLink.Rel, doc, actionLink.DocsOnly));
                    }
                    else
                    {
                        var declaredLink = link as DeclareHalLinkAttribute;
                        if (declaredLink != null)
                        {
                            EndpointDoc doc;
                            if (declaredLink.LinkedToControllerRel)
                            {
                                doc = await endpointDocBuilder.GetDoc(declaredLink.GroupName, declaredLink.Method, declaredLink.UriTemplate.Substring(1));
                            }
                            else
                            {
                                doc = new EndpointDoc();
                            }

                            //If the link is response only, send only the response
                            if (declaredLink.ResponseOnly)
                            {
                                var oldDoc = doc;
                                doc = new EndpointDoc();
                                doc.ResponseSchema = oldDoc.ResponseSchema;
                            }

                            clientDef.AddLink(new EndpointClientLinkDefinition(declaredLink.Rel, doc, false));
                        }
                    }
                }
                definitions.Add(clientDef);
            }
            return(definitions);
        }
 public EndpointClientLinkDefinition(String rel, EndpointDoc doc, bool docsOnly)
 {
     this.Rel         = rel;
     this.EndpointDoc = doc;
     this.DocsOnly    = docsOnly;
 }