本文整理汇总了C#中System.Web.Http.Services.DefaultServices类的典型用法代码示例。如果您正苦于以下问题:C# DefaultServices类的具体用法?C# DefaultServices怎么用?C# DefaultServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultServices类属于System.Web.Http.Services命名空间,在下文中一共展示了DefaultServices类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: InsertRange_GuardClauses
public void InsertRange_GuardClauses()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
// Act & assert
Assert.ThrowsArgumentNull(() => defaultServices.InsertRange(serviceType: null, index: 0, services: new[] { new object() }), "serviceType");
Assert.ThrowsArgumentNull(() => defaultServices.InsertRange(typeof(object), 0, services: null), "services");
Assert.ThrowsArgument(
() => defaultServices.InsertRange(typeof(object), 0, new[] { new object() }),
"serviceType",
"The service type Object is not supported.");
Assert.ThrowsArgument(
() => defaultServices.InsertRange(typeof(IHttpActionInvoker), 0, new[] { new object() }),
"services",
"The type Object must derive from IHttpActionInvoker.");
Assert.ThrowsArgumentOutOfRange(
() => defaultServices.InsertRange(typeof(ValueProviderFactory), -1, new[] { new Mock<ValueProviderFactory>().Object }),
"index",
"Index was out of range. Must be non-negative and less than the size of the collection.");
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:22,代码来源:DefaultServicesTests.cs
示例17: InsertRange_AddsElementAtTheRequestedLocation
public void InsertRange_AddsElementAtTheRequestedLocation()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
var filterProvider1 = new Mock<IFilterProvider>().Object;
var filterProvider2 = new Mock<IFilterProvider>().Object;
var newFilterProvider1 = new Mock<IFilterProvider>().Object;
var newFilterProvider2 = new Mock<IFilterProvider>().Object;
defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });
// Act
defaultServices.InsertRange(typeof(IFilterProvider), 1, new[] { newFilterProvider1, newFilterProvider2 });
// Assert
Assert.Equal(new[] { filterProvider1, newFilterProvider1, newFilterProvider2, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:17,代码来源:DefaultServicesTests.cs
示例18: GetService_ReturnsNullWhenServiceListEmpty
public void GetService_ReturnsNullWhenServiceListEmpty()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
defaultServices.Clear(typeof(IActionValueBinder));
// Act
object service = defaultServices.GetService(typeof(IActionValueBinder));
// Assert
Assert.Null(service);
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:13,代码来源:DefaultServicesTests.cs
示例19: RemoveAll_GuardClauses
public void RemoveAll_GuardClauses()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
// Act & assert
Assert.ThrowsArgumentNull(() => defaultServices.RemoveAll(serviceType: null, match: _ => true), "serviceType");
Assert.ThrowsArgumentNull(() => defaultServices.RemoveAll(typeof(object), match: null), "match");
Assert.ThrowsArgument(
() => defaultServices.RemoveAll(typeof(object), _ => true),
"serviceType",
"The service type Object is not supported.");
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:14,代码来源:DefaultServicesTests.cs
示例20: GetService_PrefersServiceInDependencyInjectionContainer
public void GetService_PrefersServiceInDependencyInjectionContainer()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
var filterProvider = new Mock<IActionValueBinder>().Object;
var mockDependencyResolver = new Mock<IDependencyResolver>();
mockDependencyResolver.Setup(dr => dr.GetService(typeof(IActionValueBinder))).Returns(filterProvider);
config.DependencyResolver = mockDependencyResolver.Object;
// Act
object service = defaultServices.GetService(typeof(IActionValueBinder));
// Assert
Assert.Same(filterProvider, service);
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:16,代码来源:DefaultServicesTests.cs
注:本文中的System.Web.Http.Services.DefaultServices类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论