public void Initialize() { _authorizationProvider = new Mock <IAuthorizationProvider>(); _dependencyResolverMock = new Mock <IDependencyResolver>(); _personProvider = new Mock <IPersonProvider>(); var linkBuilderFactory = new LinkBuilderFactory(); _authorizationProvider.Setup(p => p.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true); _dependencyResolverMock.Setup(p => p.GetService(It.IsAny <Type>())).Returns(_personProvider.Object); var idFromExpressionProcessor = new IdFromExpressionProcessor(_dependencyResolverMock.Object); var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor(); var templateArgumentsProcessor = new TemplateArgumentsProcessor(); var configurationMock = new Mock <IHttpConfiguration>(MockBehavior.Strict); var properties = new ConcurrentDictionary <object, object>(); configurationMock.SetupGet(c => c.Properties).Returns(() => properties); Container = HateoasContainerFactory.Create(configurationMock.Object); LinkFactory = new LinkFactory( linkBuilderFactory, _authorizationProvider.Object, idFromExpressionProcessor, argumentsDefinitionsProcessor, templateArgumentsProcessor); var linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(new InMemoryCache <int, MethodInfo>()); ConfigurationProvider = new ConfigurationProvider(configurationMock.Object, LinkFactory, linksForFuncProvider, new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >()); Enumerable = new List <Person> { new Person() { Id = Guid.Parse("ae213c3e-9ce8-489f-a5ff-5422b55bba44"), HouseId = Guid.Parse("a7a52c3d-a5ef-47ff-97db-176f4b2609e4"), }, new Person() { Id = Guid.Parse("6153d85e-8233-4d9f-b583-a78d2ba8d3d1"), HouseId = Guid.Parse("9042e54f-dee6-45c9-8d9e-048026f5d5fa"), }, }; // this link is added to check if it is ignored Container.Register <Person>("some-extra-link").Get <PersonController>(); Container.Register <Car>("some-extra-link").Get <CarController>(); }
public static void Startup <TRegistrationClass>( TRegistrationClass registrationClass, IHttpConfiguration configuration, IAuthorizationProvider authorizationProvider = null, IDependencyResolver dependencyResolver = null, IList <IMessageSerializer> messageSerializers = null) where TRegistrationClass : IHateoasRegistrationProfile { var linkBuilderFactory = new LinkBuilderFactory(); // todo: this is not very clean; user dependencyresolver etc if (authorizationProvider == null) { var httpContextWrapper = new HttpContextWrapper(HttpContext.Current); authorizationProvider = new WebApiAuthorizationProvider(httpContextWrapper); } var idFromExpressionProcessor = new IdFromExpressionProcessor(dependencyResolver); var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor(); var templateArgumentsProcessor = new TemplateArgumentsProcessor(); var linkFactory = new LinkFactory( linkBuilderFactory: linkBuilderFactory, authorizationProvider: authorizationProvider, idFromExpressionProcessor: idFromExpressionProcessor, argumentsDefinitionsProcessor: argumentsDefinitionsProcessor, templateArgumentsProcessor: templateArgumentsProcessor ); var inMemoryGenericLinksForMethodsCache = new InMemoryCache <int, MethodInfo>(); var linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(inMemoryGenericLinksForMethodsCache); var getLinksForMethodCache = new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >(); var configurationProvider = new ConfigurationProvider(configuration, linkFactory, linksForFuncProvider, getLinksForMethodCache); var responseProvider = new ResponseProvider(configurationProvider); var handler = new HateoasHttpHandler(responseProvider, messageSerializers ?? new List <IMessageSerializer>()); configuration.MessageHandlers.Add(handler); var container = HateoasContainerFactory.Create(configuration); registrationClass.Register(container); }
public void BaseTestInitialize() { // registration _httpConfiguration = new HttpConfiguration(); _httpConfigurationWrapper = new HttpConfigurationWrapper(_httpConfiguration); _authorizationProviderMock = new Mock <IAuthorizationProvider>(MockBehavior.Strict); _authorizationProviderMock.Setup(a => a.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true); _dependencyResolver = new Mock <IDependencyResolver>(MockBehavior.Strict); RegistrationClass = new TestRegistrationClass(); // request & response Request = new HttpRequestMessage(HttpMethod.Get, "http://hateoas.net"); Request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json")); Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, _httpConfigurationWrapper.HttpConfiguration); Response = new HttpResponseMessage(HttpStatusCode.OK); // handling var idFromExpressionProcessor = new IdFromExpressionProcessor(_dependencyResolver.Object); var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor(); var templateArgumentsProcessor = new TemplateArgumentsProcessor(); var inMemoryGenericLinksForMethodsCache = new InMemoryCache <int, MethodInfo>(); _linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(inMemoryGenericLinksForMethodsCache); var linkBuilderFactory = new LinkBuilderFactory(); _linkFactory = new LinkFactory( linkBuilderFactory: linkBuilderFactory, authorizationProvider: _authorizationProviderMock.Object, idFromExpressionProcessor: idFromExpressionProcessor, argumentsDefinitionsProcessor: argumentsDefinitionsProcessor, templateArgumentsProcessor: templateArgumentsProcessor ); _getLinksForMethodCache = new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >(); _configurationProvider = new ConfigurationProvider(_httpConfigurationWrapper, _linkFactory, _linksForFuncProvider, _getLinksForMethodCache); _responseProvider = new ResponseProvider(_configurationProvider); }
public void Initialize() { _authorizationProvider = new Mock <IAuthorizationProvider>(); _dependencyResolverMock = new Mock <IDependencyResolver>(); _personProvider = new Mock <IPersonProvider>(); var linkBuilderFactory = new LinkBuilderFactory(); _authorizationProvider.Setup(p => p.IsAuthorized(It.IsAny <MethodInfo>())).Returns(true); _dependencyResolverMock.Setup(p => p.GetService(It.IsAny <Type>())).Returns(_personProvider.Object); var idFromExpressionProcessor = new IdFromExpressionProcessor(_dependencyResolverMock.Object); var argumentsDefinitionsProcessor = new ArgumentDefinitionsProcessor(); var templateArgumentsProcessor = new TemplateArgumentsProcessor(); var configurationMock = new Mock <IHttpConfiguration>(MockBehavior.Strict); var properties = new ConcurrentDictionary <object, object>(); configurationMock.SetupGet(c => c.Properties).Returns(() => properties); Container = HateoasContainerFactory.Create(configurationMock.Object); LinkFactory = new LinkFactory( linkBuilderFactory, _authorizationProvider.Object, idFromExpressionProcessor, argumentsDefinitionsProcessor, templateArgumentsProcessor); var linksForFuncProvider = new ConfigurationProviderGetLinksForFuncProvider(new InMemoryCache <int, MethodInfo>()); ConfigurationProvider = new ConfigurationProvider(configurationMock.Object, LinkFactory, linksForFuncProvider, new InMemoryCache <Type, Func <ConfigurationProvider, object, IEnumerable <IHateoasLink> > >()); Entity = new Person() { Id = Guid.Parse("ae213c3e-9ce8-489f-a5ff-5422b55bba44"), HouseId = Guid.Parse("a7a52c3d-a5ef-47ff-97db-176f4b2609e4"), }; }