public static void Main(string[] args)
        {
            AsyncHttpServer server = null;

            try
            {
                server = new AsyncHttpServer();

                RoutingMiddleware routing = new RoutingMiddleware();
                routing.AddRoute <ImageProcessingController>("process/<filter>/<coords>");

                server.AddMiddleware(routing);
                server.Start("http://+:8080/");

                Console.ReadKey(true);
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                LogManager.Flush();
                throw ex;
            }
            finally
            {
                if (server != null)
                {
                    server.Dispose();
                }
            }
        }
Esempio n. 2
0
        public async Task FunctionalTest_RoutingMiddleware_Success()
        {
            HttpContext ctx = new DefaultHttpContext();

            ctx.Request.Host = new HostString(stubHost);

            RoutingMiddleware routingMiddleware = new RoutingMiddleware(_next, new NullTargetingFilterAccessor());

            Mock <IAbstractItemStorageProvider> mockAbstractItemStorageProvider = new Mock <IAbstractItemStorageProvider>();

            AbstractItemStorage abstractItemStorage = BuildAbstractItemStorage();

            mockAbstractItemStorageProvider
            .Setup(x => x.Get())
            .Returns(abstractItemStorage);

            await routingMiddleware.Invoke(ctx, mockAbstractItemStorageProvider.Object);

            Assert.IsNotNull(ctx.Items[RoutingKeys.StartPage]);
            Assert.IsInstanceOfType(ctx.Items[RoutingKeys.StartPage], typeof(StubStartPage));
            Assert.AreEqual(2, ((StubStartPage)ctx.Items[RoutingKeys.StartPage]).Id);

            Assert.IsNotNull(ctx.Items[RoutingKeys.AbstractItemStorage]);
            Assert.IsInstanceOfType(ctx.Items[RoutingKeys.AbstractItemStorage], typeof(AbstractItemStorage));
            Assert.AreEqual(abstractItemStorage, (AbstractItemStorage)ctx.Items[RoutingKeys.AbstractItemStorage]);
        }
Esempio n. 3
0
        public async Task FunctionalTest_RoutingMiddleware_ThrowsDeprecateCacheIsExpiredOrMissingException_NoCache()
        {
            HttpContext ctx = new DefaultHttpContext();

            ctx.Request.Host = new HostString("test.qp.lan");

            RoutingMiddleware routingMiddleware = new RoutingMiddleware(_next, new NullTargetingFilterAccessor());

            StubCacheProvider stubCacheProvider = new StubCacheProvider();
            CacheStubAbstractItemStorageProvider cacheStubAbstractItemStorageProvider = new CacheStubAbstractItemStorageProvider(stubCacheProvider);

            await Assert.ThrowsExceptionAsync <DeprecateCacheIsExpiredOrMissingException>(() => routingMiddleware.Invoke(ctx, cacheStubAbstractItemStorageProvider));
        }
Esempio n. 4
0
        public async Task FunctionalTest_RoutingMiddleware_ThrowsStartPageNotFound_IncorrectDNSBinding()
        {
            HttpContext ctx = new DefaultHttpContext();

            ctx.Request.Host = new HostString("test.qp.lan");

            RoutingMiddleware routingMiddleware = new RoutingMiddleware(_next, new NullTargetingFilterAccessor());

            Mock <IAbstractItemStorageProvider> mockAbstractItemStorageProvider = new Mock <IAbstractItemStorageProvider>();

            AbstractItemStorage abstractItemStorage = BuildAbstractItemStorage();

            mockAbstractItemStorageProvider
            .Setup(x => x.Get())
            .Returns(abstractItemStorage);

            await Assert.ThrowsExceptionAsync <StartPageNotFoundException>(() => routingMiddleware.Invoke(ctx, mockAbstractItemStorageProvider.Object));
        }
Esempio n. 5
0
        public async Task FunctionalTest_RoutingMiddleware_ThrowsStartPageNotFound_NoPage()
        {
            HttpContext ctx = new DefaultHttpContext();

            ctx.Request.Host = new HostString("test.qp.lan");

            RoutingMiddleware routingMiddleware = new RoutingMiddleware(_next, new NullTargetingFilterAccessor());

            Mock <IAbstractItemStorageProvider> mockAbstractItemStorageProvider = new Mock <IAbstractItemStorageProvider>();

            AbstractItemStorage abstractItemStorage = BuildAbstractItemStorage(new AbstractItemPersistentData[]
            {
                new AbstractItemPersistentData {
                    Id = 1, Title = "корневая страница", Alias = "root", Discriminator = typeof(RootPage).Name, IsPage = true, ParentId = null, ExtensionId = null
                },
            });

            mockAbstractItemStorageProvider
            .Setup(x => x.Get())
            .Returns(abstractItemStorage);

            await Assert.ThrowsExceptionAsync <StartPageNotFoundException>(() => routingMiddleware.Invoke(ctx, mockAbstractItemStorageProvider.Object));
        }