示例#1
0
        public void Test_OnBeginRequest()
        {
            string url = "https://magick.codeplex.com/";

            MagickModule        module  = CreateFileModule();
            TestHttpContextBase context = new TestHttpContextBase(url);

            module.OnBeginRequest(context);

            Assert.AreEqual(1, context.Items.Count);
            Assert.AreEqual(url, context.Items.Values.Cast <object>().First().ToString());
        }
示例#2
0
        public void Test_OnPostAuthorizeRequestFile()
        {
            MagickModule        module  = CreateFileModule();
            TestHttpContextBase context = new TestHttpContextBase();

            module.OnBeginRequest(context);
            module.OnPostAuthorizeRequest(context);

            Assert.IsNull(context.RemapedHandler);

            TestFileUrlResolver.Result = new TestFileUrlResolverResult();

            module.OnPostAuthorizeRequest(context);
            Assert.IsNull(context.RemapedHandler);

            TestFileUrlResolver.Result.FileName = "c:\foo.bar";

            module.OnPostAuthorizeRequest(context);
            Assert.IsNull(context.RemapedHandler);

            string tempFile = Path.GetTempFileName();

            try
            {
                TestFileUrlResolver.Result.FileName = tempFile;

                module.OnPostAuthorizeRequest(context);
                Assert.IsNull(context.RemapedHandler);

                TestFileUrlResolver.Result.Format = MagickFormat.Stegano;

                module.OnPostAuthorizeRequest(context);
                Assert.IsNull(context.RemapedHandler);

                TestFileUrlResolver.Result.Format = MagickFormat.Tiff;

                module.OnPostAuthorizeRequest(context);
                Assert.IsNull(context.RemapedHandler);

                TestFileUrlResolver.Result.Format = MagickFormat.Svg;

                module.OnPostAuthorizeRequest(context);
                Assert.IsNotNull(context.RemapedHandler);
                Assert.AreEqual(context.RemapedHandler.GetType(), typeof(GzipHandler));
            }
            finally
            {
                Cleanup.DeleteFile(tempFile);
            }
        }
示例#3
0
        public void Test_OnPostMapRequestHandlerStream()
        {
            MagickModule module = CreateStreamModule();

            module.Init(new TestHttpApplication());

            TestHttpContextBase context = new TestHttpContextBase();

            module.OnBeginRequest(context);
            module.OnPostMapRequestHandler(context);

            Assert.IsNull(context.Handler);

            TestStreamUrlResolver.Result = true;

            module.OnPostMapRequestHandler(context);
            Assert.IsNotNull(context.Handler);
            Assert.AreEqual(context.Handler.GetType(), typeof(ImageOptimizerHandler));
        }
示例#4
0
        public void Test_OnPostMapRequestHandlerFile()
        {
            MagickModule module = CreateFileModule();

            module.Init(new TestHttpApplication());

            TestHttpContextBase context = new TestHttpContextBase();

            module.OnBeginRequest(context);
            module.OnPostMapRequestHandler(context);

            Assert.IsNull(context.Handler);

            string tempFile = Path.GetTempFileName();

            try
            {
                TestFileUrlResolver.Result = new TestFileUrlResolverResult()
                {
                    FileName = tempFile,
                    Format   = MagickFormat.Jpg,
                };

                module.OnPostMapRequestHandler(context);
                Assert.IsNotNull(context.Handler);
                Assert.AreEqual(context.Handler.GetType(), typeof(ImageOptimizerHandler));

                TestFileUrlResolver.ScriptResult = new TestScriptData()
                {
                    OutputFormat = MagickFormat.Tiff,
                    Script       = XElement.Parse("<test/>").CreateNavigator(),
                };

                module.OnPostMapRequestHandler(context);
                Assert.IsNotNull(context.Handler);
                Assert.AreEqual(context.Handler.GetType(), typeof(MagickScriptHandler));
            }
            finally
            {
                Cleanup.DeleteFile(tempFile);
            }
        }