public WebHookRegistrationsControllerTests()
        {
            _regsMock      = new Mock <IWebHookRegistrationsManager>();
            _registrarMock = new Mock <IWebHookRegistrar>();
            _idValidator   = new Mock <IWebHookIdValidator>();

            _principal = new ClaimsPrincipal();
            var services = new Dictionary <Type, object>
            {
                { typeof(IWebHookRegistrationsManager), _regsMock.Object },
                { typeof(IWebHookRegistrar), _registrarMock.Object },
                { typeof(IWebHookIdValidator), _idValidator.Object },
            };

            _config = HttpConfigurationMock.Create(services);
            _config.Routes.Add(WebHookRouteNames.FiltersGetAction, new HttpRoute());

            _request = new HttpRequestMessage(HttpMethod.Get, Address);
            _request.SetConfiguration(_config);
            var requestContext = new HttpRequestContext()
            {
                Configuration = _config,
                Principal     = _principal,
                Url           = new UrlHelper(_request),
            };

            _controllerContext = new HttpControllerContext()
            {
                Configuration  = _config,
                Request        = _request,
                RequestContext = requestContext,
            };
            _controller = new WebHookRegistrationsControllerMock();
            _controller.Initialize(_controllerContext);
        }
        public WebHookRegistrationsControllerTests()
        {
            IPrincipal principal = new ClaimsPrincipal();

            _managerMock = new Mock <IWebHookManager>();
            _storeMock   = new Mock <MemoryWebHookStore> {
                CallBase = true
            };

            _userMock = new Mock <IWebHookUser>();
            _userMock.Setup(u => u.GetUserIdAsync(principal))
            .ReturnsAsync(TestUser);

            _filterProviderMock = new Mock <IWebHookFilterProvider>();
            _filterProviderMock.Setup(p => p.GetFiltersAsync())
            .ReturnsAsync(new Collection <WebHookFilter> {
                new WebHookFilter {
                    Name = FilterName
                }
            });

            _filterManager = new WebHookFilterManager(new[]
            {
                new WildcardWebHookFilterProvider(),
                _filterProviderMock.Object
            });

            _registrar = new Mock <IWebHookRegistrar>();

            var services = new Dictionary <Type, object>
            {
                { typeof(IWebHookManager), _managerMock.Object },
                { typeof(IWebHookStore), _storeMock.Object },
                { typeof(IWebHookUser), _userMock.Object },
                { typeof(IWebHookFilterManager), _filterManager },
                { typeof(IWebHookRegistrar), _registrar.Object }
            };

            _config = HttpConfigurationMock.Create(services);
            _config.Routes.Add(WebHookRouteNames.FiltersGetAction, new HttpRoute());

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address);

            request.SetConfiguration(_config);
            HttpRequestContext requestContext = new HttpRequestContext()
            {
                Configuration = _config,
                Principal     = principal,
                Url           = new UrlHelper(request),
            };

            _controllerContext = new HttpControllerContext()
            {
                Configuration  = _config,
                Request        = new HttpRequestMessage(),
                RequestContext = requestContext,
            };
            _controller = new WebHookRegistrationsControllerMock();
            _controller.Initialize(_controllerContext);
        }
示例#3
0
        public WebHookRegistrationsControllerTests()
        {
            _resolverMock = new Mock <IDependencyResolver>();
            _managerMock  = new Mock <IWebHookManager>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
            .Returns(_managerMock.Object)
            .Verifiable();

            _store = new MemoryWebHookStore();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookStore)))
            .Returns(_store)
            .Verifiable();

            _user = new WebHookUser();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
            .Returns(_user)
            .Verifiable();

            _filterProviderMock = new Mock <IWebHookFilterProvider>();
            _filterManager      = new WebHookFilterManager(new[]
            {
                new WildcardWebHookFilterProvider(),
                _filterProviderMock.Object
            });
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookFilterManager)))
            .Returns(_filterManager)
            .Verifiable();

            _config = new HttpConfiguration();
            _config.DependencyResolver = _resolverMock.Object;

            ClaimsIdentity identity = new ClaimsIdentity();
            Claim          claim    = new Claim(ClaimTypes.Name, TestUser);

            identity.AddClaim(claim);
            IPrincipal principal = new ClaimsPrincipal(identity);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address);

            request.SetConfiguration(_config);
            HttpRequestContext requestContext = new HttpRequestContext()
            {
                Configuration = _config,
                Principal     = principal,
                Url           = new UrlHelper(request),
            };

            _controllerContext = new HttpControllerContext()
            {
                Configuration  = _config,
                Request        = new HttpRequestMessage(),
                RequestContext = requestContext,
            };
            _controller = new WebHookRegistrationsControllerMock();
            _controller.Initialize(_controllerContext);
        }
        public WebHookRegistrationsControllerTests()
        {
            IPrincipal principal = new ClaimsPrincipal();

            _managerMock = new Mock<IWebHookManager>();
            _storeMock = new Mock<MemoryWebHookStore> { CallBase = true };

            _userMock = new Mock<IWebHookUser>();
            _userMock.Setup(u => u.GetUserIdAsync(principal))
                .ReturnsAsync(TestUser);

            _filterProviderMock = new Mock<IWebHookFilterProvider>();
            _filterProviderMock.Setup(p => p.GetFiltersAsync())
                .ReturnsAsync(new Collection<WebHookFilter> { new WebHookFilter { Name = FilterName } });

            _filterManager = new WebHookFilterManager(new[]
            {
                new WildcardWebHookFilterProvider(),
                _filterProviderMock.Object
            });

            _registrarMock = new Mock<IWebHookRegistrar>();
            _idValidatorMock = new Mock<IWebHookIdValidator>();

            var services = new Dictionary<Type, object>
            {
                { typeof(IWebHookManager), _managerMock.Object },
                { typeof(IWebHookStore), _storeMock.Object },
                { typeof(IWebHookUser), _userMock.Object },
                { typeof(IWebHookFilterManager), _filterManager },
                { typeof(IWebHookRegistrar), _registrarMock.Object },
                { typeof(IWebHookIdValidator), _idValidatorMock.Object },
            };
            _config = HttpConfigurationMock.Create(services);
            _config.Routes.Add(WebHookRouteNames.FiltersGetAction, new HttpRoute());

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address);
            request.SetConfiguration(_config);
            HttpRequestContext requestContext = new HttpRequestContext()
            {
                Configuration = _config,
                Principal = principal,
                Url = new UrlHelper(request),
            };

            _controllerContext = new HttpControllerContext()
            {
                Configuration = _config,
                Request = new HttpRequestMessage(),
                RequestContext = requestContext,
            };
            _controller = new WebHookRegistrationsControllerMock();
            _controller.Initialize(_controllerContext);
        }
        public WebHookRegistrationsControllerTests()
        {
            _resolverMock = new Mock<IDependencyResolver>();
            _managerMock = new Mock<IWebHookManager>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
                .Returns(_managerMock.Object)
                .Verifiable();

            _store = new MemoryWebHookStore();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookStore)))
                .Returns(_store)
                .Verifiable();

            _user = new WebHookUser();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            _filterProviderMock = new Mock<IWebHookFilterProvider>();
            _filterManager = new WebHookFilterManager(new[]
            {
                new WildcardWebHookFilterProvider(),
                _filterProviderMock.Object
            });
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookFilterManager)))
                .Returns(_filterManager)
                .Verifiable();

            _config = new HttpConfiguration();
            _config.DependencyResolver = _resolverMock.Object;

            ClaimsIdentity identity = new ClaimsIdentity();
            Claim claim = new Claim(ClaimTypes.Name, TestUser);
            identity.AddClaim(claim);
            IPrincipal principal = new ClaimsPrincipal(identity);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address);
            request.SetConfiguration(_config);
            HttpRequestContext requestContext = new HttpRequestContext()
            {
                Configuration = _config,
                Principal = principal,
                Url = new UrlHelper(request),
            };

            _controllerContext = new HttpControllerContext()
            {
                Configuration = _config,
                Request = new HttpRequestMessage(),
                RequestContext = requestContext,
            };
            _controller = new WebHookRegistrationsControllerMock();
            _controller.Initialize(_controllerContext);
        }