当前位置: 首页>>代码示例>>C#>>正文


C# ServiceCollection.WithService方法代码示例

本文整理汇总了C#中ServiceCollection.WithService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.WithService方法的具体用法?C# ServiceCollection.WithService怎么用?C# ServiceCollection.WithService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceCollection的用法示例。


在下文中一共展示了ServiceCollection.WithService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolvedServiceGetResponseEncoder

        public void ResolvedServiceGetResponseEncoder()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("{action}")
                        .Post<Payload>((Payload p) => { });

            ResolvedService service = new ServiceResolver(services).Find(MethodType.Post, "foo");
            EncodingLookupResult result = service.GetResponseEncoder("gzip");
            Assert.IsNotNull(result);
            Assert.AreEqual(EncodingType.Empty, result.EncodingType);
            Assert.AreEqual(new IdentityEncoding(), result.Encoding);

            result = service.GetResponseEncoder("gzip, *");
            Assert.IsNotNull(result);
            Assert.AreEqual(EncodingType.Empty, result.EncodingType);
            Assert.AreEqual(new IdentityEncoding(), result.Encoding);

            services.WithHostEncoding(new GzipDeflateEncoding());
            service = new ServiceResolver(services).Find(MethodType.Post, "foo");
            result = service.GetResponseEncoder("gzip, *");
            Assert.IsNotNull(result);
            Assert.AreEqual(EncodingType.Parse("gzip"), result.EncodingType);
            Assert.AreEqual(new GzipDeflateEncoding(), result.Encoding);

            result = service.GetResponseEncoder("gzip;q=0");
            Assert.IsNotNull(result);
            Assert.AreEqual(EncodingType.Empty, result.EncodingType);
            Assert.AreEqual(new IdentityEncoding(), result.Encoding);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:31,代码来源:ResolvedServiceTests.cs

示例2: ServiceCollectionErrorService

        public void ServiceCollectionErrorService()
        {
            ServiceCollection services = new ServiceCollection();
            services.WithService("Test", "/");

            services
                .ErrorService((ex) => true)
                .ErrorService((ex, req, res) => true)
                .ErrorService<string>((ex, req, res) => true);

            Assert.AreEqual(3, services.First().Pipeline.ErrorActions.Count);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceCollectionTests.cs

示例3: ServiceCollectionBeforeService

        public void ServiceCollectionBeforeService()
        {
            ServiceCollection services = new ServiceCollection();
            services.WithService("Test", "/");

            services
                .BeforeService(() => true)
                .BeforeService((req, res) => true)
                .BeforeService<string>((req, res) => true);

            Assert.AreEqual(3, services.First().Pipeline.BeforeActions.Count);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceCollectionTests.cs

示例4: ServiceResolverFind

        public void ServiceResolverFind()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("foo/{param}/bar")
                        .Get(() => { });

            ServiceResolver resolver = new ServiceResolver(services);
            Assert.IsNotNull(resolver.Find(MethodType.Get, "foo/baz/bar"));
            Assert.IsNull(resolver.Find(MethodType.Post, "foo/baz/bar"));
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceResolverTests.cs

示例5: ServiceResolverFindRouteTypes

        public void ServiceResolverFindRouteTypes()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("foo/{param}/bar", new { param = typeof(Guid) })
                        .Get(() => { });

            ServiceResolver resolver = new ServiceResolver(services);
            Assert.IsNotNull(resolver.Find(MethodType.Get, "foo/D118CE6F-36BE-4DB4-B0E7-D426809B22FE/bar"));
            Assert.IsNull(resolver.Find(MethodType.Get, "foo/42/bar"));
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceResolverTests.cs

示例6: ServiceResolverExistsForAnyMethodType

        public void ServiceResolverExistsForAnyMethodType()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("foo/{param}/bar")
                        .Get(() => { });

            ServiceResolver resolver = new ServiceResolver(services);
            Assert.IsTrue(resolver.ExistsForAnyMethodType("foo/baz/bar"));
            Assert.IsFalse(resolver.ExistsForAnyMethodType("foo/bar"));
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceResolverTests.cs

示例7: ServiceResolverFindRoutePatterns

        public void ServiceResolverFindRoutePatterns()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("foo/{param}/bar", null, new { param = @"^\d+$" })
                        .Get(() => { });

            ServiceResolver resolver = new ServiceResolver(services);
            Assert.IsNotNull(resolver.Find(MethodType.Get, "foo/42/bar"));
            Assert.IsNull(resolver.Find(MethodType.Get, "foo/baz/bar"));
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:12,代码来源:ServiceResolverTests.cs

示例8: MethodCollectionBeforeEndpoint

        public void MethodCollectionBeforeEndpoint()
        {
            ServiceCollection services = new ServiceCollection();
            EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;
            MethodCollection methods = endpoints.WithEndpoint("endpoint/route") as MethodCollection;

            methods
                .BeforeEndpoint(() => true)
                .BeforeEndpoint((req, res) => true)
                .BeforeEndpoint<string>((req, res) => true);

            Assert.AreEqual(3, endpoints.First().Pipeline.BeforeActions.Count);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:13,代码来源:MethodCollectionTests.cs

示例9: ServiceCollectionWithEndpoint

        public void ServiceCollectionWithEndpoint()
        {
            ServiceCollection services = new ServiceCollection();
            EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;

            services.WithEndpoint("accounts/{id}");
            Assert.AreEqual(1, endpoints.Count());
            Assert.AreEqual(0, endpoints.First().ParameterTypes.Count);

            services.WithEndpoint("foo/{id}/bar", new { id = typeof(long) });
            Assert.AreEqual(2, endpoints.Count());
            Assert.IsTrue(endpoints.Last().ParameterTypes.ContainsKey("id"));
            Assert.AreEqual(typeof(long), endpoints.Last().ParameterTypes["id"]);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:14,代码来源:ServiceCollectionTests.cs

示例10: EndpointCollectionErrorEndpoint

        public void EndpointCollectionErrorEndpoint()
        {
            ServiceCollection services = new ServiceCollection();
            EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;

            endpoints.WithEndpoint("endpoint/route");

            endpoints
                .ErrorEndpoint((ex) => true)
                .ErrorEndpoint((ex, req, res) => true)
                .ErrorEndpoint<string>((ex, req, res) => true);

            Assert.AreEqual(3, endpoints.First().Pipeline.ErrorActions.Count);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:14,代码来源:EndpointCollectionTests.cs

示例11: EndpointCollectionAfterService

        public void EndpointCollectionAfterService()
        {
            ServiceCollection services = new ServiceCollection();
            EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;

            endpoints.WithEndpoint("endpoint/route");

            endpoints
                .AfterService(() => true)
                .AfterService((req, res) => true)
                .AfterService<string>((req, res) => true);

            Assert.AreEqual(3, services.First().Pipeline.AfterActions.Count);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:14,代码来源:EndpointCollectionTests.cs

示例12: ResolvedServiceGetRequestDeserializer

        public void ResolvedServiceGetRequestDeserializer()
        {
            ServiceCollection services = new ServiceCollection();
            services
                .WithService("Test", "/")
                    .WithEndpoint("{action}")
                        .Post<Payload>((Payload p) => { });

            ResolvedService service = new ServiceResolver(services).Find(MethodType.Post, "foo");
            FormatLookupResult result = service.GetRequestDeserializer("application/json");
            Assert.IsNull(result);

            result = service.GetRequestDeserializer(string.Empty);
            Assert.IsNotNull(result);
            Assert.AreEqual(MediaType.Empty, result.MediaType);
            Assert.AreEqual(new PlainTextFormat(), result.Format);

            services.WithHostFormat(new JsonFormat());
            service = new ServiceResolver(services).Find(MethodType.Post, "foo");
            result = service.GetRequestDeserializer("application/json");
            Assert.IsNotNull(result);
            Assert.AreEqual(MediaType.Parse("application/json"), result.MediaType);
            Assert.AreEqual(new JsonFormat(), result.Format);
        }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:24,代码来源:ResolvedServiceTests.cs

示例13: MethodCollectionWithServiceFormat

 public void MethodCollectionWithServiceFormat()
 {
     ServiceCollection services = new ServiceCollection();
     EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;
     MethodCollection methods = endpoints.WithEndpoint("endpoint/route") as MethodCollection;
     methods.WithServiceFormat(new PlainTextFormat());
     Assert.AreEqual(1, services.First().Pipeline.Formats.Count);
 }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:8,代码来源:MethodCollectionTests.cs

示例14: MethodCollectionWithServiceEncoding

 public void MethodCollectionWithServiceEncoding()
 {
     ServiceCollection services = new ServiceCollection();
     EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;
     MethodCollection methods = endpoints.WithEndpoint("endpoint/route") as MethodCollection;
     methods.WithServiceEncoding(new GzipDeflateEncoding());
     Assert.AreEqual(1, services.First().Pipeline.Encodings.Count);
 }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:8,代码来源:MethodCollectionTests.cs

示例15: MethodCollectionWithService

 public void MethodCollectionWithService()
 {
     ServiceCollection services = new ServiceCollection();
     EndpointCollection endpoints = services.WithService("Test", "/") as EndpointCollection;
     MethodCollection methods = endpoints.WithEndpoint("endpoint/route") as MethodCollection;
     methods.WithService("Test1", "/api");
     Assert.AreEqual(2, services.Count);
 }
开发者ID:ChadBurggraf,项目名称:small-fry,代码行数:8,代码来源:MethodCollectionTests.cs


注:本文中的ServiceCollection.WithService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。