public void SuccessfulBuild()
        {
            try
            {
                DynamicIconOptionsBuilder builder = new DynamicIconOptionsBuilder();
                DynamicIconOptions        options = builder.UseDefaultBackground("C0FFEE")
                                                    .UseDefaultForeground("DEADB0")
                                                    .UseDefaultFormat(IconFormat.Ico)
                                                    .UseFontName("Arial")
                                                    .UseMinimumSize(128)
                                                    .UseDefaultSize(256)
                                                    .UseMaximumSize(512)
                                                    .UseRoute("/route")
                                                    .Build();

                Assert.AreEqual("C0FFEE", options.DefaultBackground);
                Assert.AreEqual("DEADB0", options.DefaultForeground);
                Assert.AreEqual(IconFormat.Ico, options.Format);
                Assert.AreEqual("Arial", options.FontName);
                Assert.AreEqual(128, options.MinimumSize);
                Assert.AreEqual(256, options.DefaultSize);
                Assert.AreEqual(512, options.MaximumSize);
                Assert.AreEqual("/route", options.Route);
            }
            catch
            {
                throw;
            }
        }
        public void InvalidMaximumSize()
        {
            DynamicIconOptions options = new DynamicIconOptions();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                options.MaximumSize = DynamicIconMiddleware.MAXIMUM_SIZE + 1;
            });
        }
        public void InvalidFormat()
        {
            DynamicIconOptions options = new DynamicIconOptions();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                options.Format = 0;
            });
        }
        public void DefaultOptions()
        {
            DynamicIconOptions options = new DynamicIconOptions();

            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_BACKGROUND, options.DefaultBackground);
            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_FOREGROUND, options.DefaultForeground);
            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_FORMAT, options.Format);
            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_FONT, options.FontName);
            Assert.AreEqual(DynamicIconMiddleware.MINIMUM_SIZE, options.MinimumSize);
            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_SIZE, options.DefaultSize);
            Assert.AreEqual(DynamicIconMiddleware.MAXIMUM_SIZE, options.MaximumSize);
            Assert.AreEqual(DynamicIconMiddleware.DEFAULT_ROUTE, options.Route);
        }
        public void InvalidRoute()
        {
            DynamicIconOptions options = new DynamicIconOptions();

            Assert.ThrowsException <ArgumentNullException>(() =>
            {
                options.Route = null;
            });

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                options.Route = String.Empty;
            });
        }
Ejemplo n.º 6
0
        public void LongText()
        {
            Assert.ThrowsExceptionAsync <InvalidOperationException>(async() =>
            {
                DynamicIconOptions options       = new DynamicIconOptions();
                DynamicIconMiddleware middleware = new DynamicIconMiddleware(next: (innerHttpContext) =>
                {
                    innerHttpContext.Response.StatusCode = 204;
                    return(Task.CompletedTask);
                }, options);

                HttpContext context = CreateContext("https://localhost/images/dynamicicon?t=TooLong");
                await middleware.InvokeAsync(context);
            });
        }
Ejemplo n.º 7
0
        public async Task DifferentRoute()
        {
            DynamicIconOptions    options    = new DynamicIconOptions();
            DynamicIconMiddleware middleware = new DynamicIconMiddleware(next: (innerHttpContext) =>
            {
                innerHttpContext.Response.StatusCode = 204;
                return(Task.CompletedTask);
            }, options);

            HttpContext context = CreateContext("https://localhost/alternate/route");
            await middleware.InvokeAsync(context);

            Assert.AreEqual(204, context.Response.StatusCode);

            context.Response.Body.Dispose();
        }
Ejemplo n.º 8
0
        public async Task DefaultOptions()
        {
            DynamicIconOptions options = new DynamicIconOptions();

            options.DefaultSize = 128;
            options.FontName    = DynamicIconMiddleware.InstalledFonts.First();

            DynamicIconMiddleware middleware = new DynamicIconMiddleware(next: (innerHttpContext) =>
            {
                innerHttpContext.Response.StatusCode = 204;
                return(Task.CompletedTask);
            }, options);

            HttpContext context = CreateContext("https://localhost/images/dynamicicon?t=DI");
            await middleware.InvokeAsync(context);

            Assert.AreEqual(200, context.Response.StatusCode);
            Assert.AreEqual("image/png", context.Response.ContentType);
            Assert.IsTrue(IsValidImage(context.Response.Body, options.DefaultSize));

            context.Response.Body.Dispose();
        }
        public void ValidOptions()
        {
            DynamicIconOptions options = new DynamicIconOptions()
            {
                Route             = "/route",
                MinimumSize       = 128,
                DefaultSize       = 256,
                MaximumSize       = 512,
                DefaultBackground = "C0FFEE",
                DefaultForeground = "DEADB0",
                Format            = IconFormat.Ico,
                FontName          = "Arial"
            };

            Assert.AreEqual("C0FFEE", options.DefaultBackground);
            Assert.AreEqual("DEADB0", options.DefaultForeground);
            Assert.AreEqual(IconFormat.Ico, options.Format);
            Assert.AreEqual("Arial", options.FontName);
            Assert.AreEqual(128, options.MinimumSize);
            Assert.AreEqual(256, options.DefaultSize);
            Assert.AreEqual(512, options.MaximumSize);
            Assert.AreEqual("/route", options.Route);
        }