本文整理汇总了C#中System.Web.Http.Services.DefaultServices.GetServices方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultServices.GetServices方法的具体用法?C# DefaultServices.GetServices怎么用?C# DefaultServices.GetServices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Services.DefaultServices
的用法示例。
在下文中一共展示了DefaultServices.GetServices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: ReplaceRange_ReplacesAllValuesWithTheGivenServices
public void ReplaceRange_ReplacesAllValuesWithTheGivenServices()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
var filterProvider1 = new Mock<IFilterProvider>().Object;
var filterProvider2 = new Mock<IFilterProvider>().Object;
// Act
defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });
// Assert
Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
}
示例3: 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)));
}
示例4: 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)));
}
示例5: 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)));
}
示例6: 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)));
}
示例7: GetServices_CachesResultFromDependencyInjectionContainer
public void GetServices_CachesResultFromDependencyInjectionContainer()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
var mockDependencyResolver = new Mock<IDependencyResolver>();
config.DependencyResolver = mockDependencyResolver.Object;
// Act
defaultServices.GetServices(typeof(IFilterProvider));
defaultServices.GetServices(typeof(IFilterProvider));
// Assert
mockDependencyResolver.Verify(dr => dr.GetServices(typeof(IFilterProvider)), Times.Once());
}
示例8: GetServices_PrependsServiceInDependencyInjectionContainer
public void GetServices_PrependsServiceInDependencyInjectionContainer()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));
var filterProvider = new Mock<IFilterProvider>().Object;
var mockDependencyResolver = new Mock<IDependencyResolver>();
mockDependencyResolver.Setup(dr => dr.GetServices(typeof(IFilterProvider))).Returns(new[] { filterProvider });
config.DependencyResolver = mockDependencyResolver.Object;
// Act
IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
// Assert
Assert.Equal(new[] { filterProvider }.Concat(servicesBefore), servicesAfter);
}
示例9: GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty
public void GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
defaultServices.Clear(typeof(IFilterProvider));
// Act
IEnumerable<object> services = defaultServices.GetServices(typeof(IFilterProvider));
// Assert
Assert.Empty(services);
}
示例10: GetServices_GuardClauses
public void GetServices_GuardClauses()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
// Act & assert
Assert.ThrowsArgumentNull(() => defaultServices.GetServices(serviceType: null), "serviceType");
Assert.ThrowsArgument(
() => defaultServices.GetServices(typeof(object)),
"serviceType",
"The service type Object is not supported.");
}
示例11: 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)));
}
示例12: 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);
}
示例13: 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);
}
示例14: GetService_ReturnsFirstServiceInList
public void GetService_ReturnsFirstServiceInList()
{
// Arrange
var config = new HttpConfiguration();
var defaultServices = new DefaultServices(config);
IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));
// Act
object service = defaultServices.GetService(typeof(IFilterProvider));
// Assert
Assert.Same(servicesBefore.First(), service);
}