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


C# Services.DefaultServices类代码示例

本文整理汇总了C#中System.Web.Http.Services.DefaultServices的典型用法代码示例。如果您正苦于以下问题:C# DefaultServices类的具体用法?C# DefaultServices怎么用?C# DefaultServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultServices类属于System.Web.Http.Services命名空间,在下文中一共展示了DefaultServices类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Constructor_DefaultServicesInContainer

        public void Constructor_DefaultServicesInContainer()
        {
            // Arrange
            var config = new HttpConfiguration();

            // Act
            var defaultServices = new DefaultServices(config);

            // Assert
            Assert.Null(defaultServices.GetService(typeof(IDocumentationProvider)));
            Assert.Null(defaultServices.GetService(typeof(ITraceWriter)));

            Assert.IsType<DefaultActionValueBinder>(defaultServices.GetService(typeof(IActionValueBinder)));
            Assert.IsType<ApiExplorer>(defaultServices.GetService(typeof(IApiExplorer)));
            Assert.IsType<DefaultAssembliesResolver>(defaultServices.GetService(typeof(IAssembliesResolver)));
            Assert.IsType<DefaultBodyModelValidator>(defaultServices.GetService(typeof(IBodyModelValidator)));
            Assert.IsType<DefaultContentNegotiator>(defaultServices.GetService(typeof(IContentNegotiator)));
            Assert.IsType<ApiControllerActionInvoker>(defaultServices.GetService(typeof(IHttpActionInvoker)));
            Assert.IsType<ApiControllerActionSelector>(defaultServices.GetService(typeof(IHttpActionSelector)));
            Assert.IsType<DefaultHttpControllerActivator>(defaultServices.GetService(typeof(IHttpControllerActivator)));
            Assert.IsType<DefaultHttpControllerSelector>(defaultServices.GetService(typeof(IHttpControllerSelector)));
            Assert.IsType<DefaultHttpControllerTypeResolver>(defaultServices.GetService(typeof(IHttpControllerTypeResolver)));
            Assert.IsType<TraceManager>(defaultServices.GetService(typeof(ITraceManager)));
            Assert.IsType<DataAnnotationsModelMetadataProvider>(defaultServices.GetService(typeof(ModelMetadataProvider)));
            Assert.IsType<ModelValidatorCache>(defaultServices.GetService(typeof(IModelValidatorCache)));
            Assert.IsType<DefaultExceptionHandler>(defaultServices.GetService(typeof(IExceptionHandler)));

            object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray();
            Assert.Equal(2, filterProviders.Length);
            Assert.IsType<ConfigurationFilterProvider>(filterProviders[0]);
            Assert.IsType<ActionDescriptorFilterProvider>(filterProviders[1]);

            object[] modelBinderProviders = defaultServices.GetServices(typeof(ModelBinderProvider)).ToArray();
            Assert.Equal(8, modelBinderProviders.Length);
            Assert.IsType<TypeConverterModelBinderProvider>(modelBinderProviders[0]);
            Assert.IsType<TypeMatchModelBinderProvider>(modelBinderProviders[1]);
            Assert.IsType<KeyValuePairModelBinderProvider>(modelBinderProviders[2]);
            Assert.IsType<ComplexModelDtoModelBinderProvider>(modelBinderProviders[3]);
            Assert.IsType<ArrayModelBinderProvider>(modelBinderProviders[4]);
            Assert.IsType<DictionaryModelBinderProvider>(modelBinderProviders[5]);
            Assert.IsType<CollectionModelBinderProvider>(modelBinderProviders[6]);
            Assert.IsType<MutableObjectModelBinderProvider>(modelBinderProviders[7]);

            object[] validatorProviders = defaultServices.GetServices(typeof(ModelValidatorProvider)).ToArray();
            Assert.Equal(2, validatorProviders.Length);
            Assert.IsType<DataAnnotationsModelValidatorProvider>(validatorProviders[0]);
            Assert.IsType<DataMemberModelValidatorProvider>(validatorProviders[1]);

            object[] valueProviderFactories = defaultServices.GetServices(typeof(ValueProviderFactory)).ToArray();
            Assert.Equal(2, valueProviderFactories.Length);
            Assert.IsType<QueryStringValueProviderFactory>(valueProviderFactories[0]);
            Assert.IsType<RouteDataValueProviderFactory>(valueProviderFactories[1]);

            object[] exceptionLoggers = defaultServices.GetServices(typeof(IExceptionLogger)).ToArray();
            Assert.Equal(0, exceptionLoggers.Length);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:56,代码来源:DefaultServicesTests.cs

示例2: HttpConfiguration

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpConfiguration"/> class.
        /// </summary>
        /// <param name="routes">The <see cref="HttpRouteCollection"/> to associate with this instance.</param>
        public HttpConfiguration(HttpRouteCollection routes)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            _routes = routes;
            Services = new DefaultServices(this);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:14,代码来源:HttpConfiguration.cs

示例3: HttpConfiguration

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpConfiguration"/> class.
        /// </summary>
        /// <param name="routes">The <see cref="HttpRouteCollection"/> to associate with this instance.</param>
        public HttpConfiguration(HttpRouteCollection routes)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            _routes = routes;
            Services = new DefaultServices(this);
            ParameterBindingRules = DefaultActionValueBinder.GetDefaultParameterBinders();
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:15,代码来源:HttpConfiguration.cs

示例4: Insert_GuardClauses

        public void Insert_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(() => defaultServices.Insert(serviceType: null, index: 0, service: new object()), "serviceType");
            Assert.ThrowsArgumentNull(() => defaultServices.Insert(typeof(object), 0, service: null), "service");
            Assert.ThrowsArgument(
                () => defaultServices.Insert(typeof(object), 0, new object()),
                "serviceType",
                "The service type Object is not supported.");
            Assert.ThrowsArgument(
                () => defaultServices.Insert(typeof(IHttpActionInvoker), 0, new object()),
                "service",
                "The type Object must derive from IHttpActionInvoker.");
            Assert.ThrowsArgumentOutOfRange(
                () => defaultServices.Insert(typeof(ValueProviderFactory), -1, new Mock<ValueProviderFactory>().Object),
                "index",
                "Index must be within the bounds of the List.");
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:22,代码来源:DefaultServicesTests.cs

示例5: Add_GuardClauses

        public void Add_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(() => defaultServices.Add(serviceType: null, service: new object()), "serviceType");
            Assert.ThrowsArgumentNull(() => defaultServices.Add(typeof(object), service: null), "service");
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(object), new object()),
                "serviceType",
                "The service type Object is not supported.");
            Assert.ThrowsArgument(
                () => defaultServices.Add(typeof(IHttpActionInvoker), new object()),
                "service",
                "The type Object must derive from IHttpActionInvoker.");
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:18,代码来源:DefaultServicesTests.cs

示例6: ReplaceRange_GuardClauses

        public void ReplaceRange_GuardClauses()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            Assert.ThrowsArgumentNull(() => defaultServices.ReplaceRange(serviceType: null, services: new[] { new object() }), "serviceType");
            Assert.ThrowsArgumentNull(() => defaultServices.ReplaceRange(typeof(object), services: null), "services");
            Assert.ThrowsArgument(
                () => defaultServices.ReplaceRange(typeof(object), new[] { new object() }),
                "serviceType",
                "The service type Object is not supported.");
            Assert.ThrowsArgument(
                () => defaultServices.ReplaceRange(typeof(ValueProviderFactory), new[] { new object() }),
                "services",
                "The type Object must derive from ValueProviderFactory.");
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:18,代码来源:DefaultServicesTests.cs

示例7: RemoteAt_RemovesService

        public void RemoteAt_RemovesService()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.RemoveAt(typeof(IFilterProvider), 1);

            // Assert
            Assert.Equal(new[] { filterProvider1 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:DefaultServicesTests.cs

示例8: RemoveAll_SuccessfulMatch

        public void RemoveAll_SuccessfulMatch()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.RemoveAll(typeof(IFilterProvider), _ => true);

            // Assert
            Assert.Empty(defaultServices.GetServices(typeof(IFilterProvider)));
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:DefaultServicesTests.cs

示例9: Remove_ObjectNotFound

        public void Remove_ObjectNotFound()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            var notPresentFilterProvider = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.Remove(typeof(IFilterProvider), notPresentFilterProvider);

            // Assert
            Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:16,代码来源:DefaultServicesTests.cs

示例10: FindIndex_EmptyServiceListAlwaysReturnsFailure

        public void FindIndex_EmptyServiceListAlwaysReturnsFailure()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            defaultServices.Clear(typeof(IFilterProvider));

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => true);

            // Assert
            Assert.Equal(-1, index);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:13,代码来源:DefaultServicesTests.cs

示例11: FindIndex_FailedFind

        public void FindIndex_FailedFind()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => false);

            // Assert
            Assert.Equal(-1, index);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:12,代码来源:DefaultServicesTests.cs

示例12: Clear_RemovesAllServices

        public void Clear_RemovesAllServices()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            Assert.NotEmpty(defaultServices.GetServices(typeof(IFilterProvider)));

            // Act
            defaultServices.Clear(typeof(IFilterProvider));

            // Assert
            Assert.Empty(defaultServices.GetServices(typeof(IFilterProvider)));
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:13,代码来源:DefaultServicesTests.cs

示例13: AddRange_SkipsNullObjects

        public void AddRange_SkipsNullObjects()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.AddRange(typeof(IFilterProvider), new object[] { null });

            // Assert
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
            Assert.Equal(servicesBefore, servicesAfter);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:14,代码来源:DefaultServicesTests.cs

示例14: AddRange_AddsServicesToEndOfServicesList

        public void AddRange_AddsServicesToEndOfServicesList()
        {
            // Arrange
            var config = new HttpConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider = new Mock<IFilterProvider>().Object;
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.AddRange(typeof(IFilterProvider), new[] { filterProvider });

            // Assert
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
            Assert.Equal(servicesBefore.Concat(new[] { filterProvider }), servicesAfter);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:15,代码来源:DefaultServicesTests.cs

示例15: Class_IsDefaultIAssembliesResolver

        public void Class_IsDefaultIAssembliesResolver()
        {
            var serviceResolver = new DefaultServices(new HttpConfiguration());

            Assert.IsType<DefaultAssembliesResolver>(serviceResolver.GetService(typeof(IAssembliesResolver)));
        }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:6,代码来源:DefaultAssembliesResolverTest.cs


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