public void AddOverlay_WhenOverlayIsNotNull_AddsTheOverlay()
        {
            var overlayManager = new OverlayManager();
            var overlay = new StubOverlay();

            overlayManager.AddOverlay(overlay);

            Assert.AreElementsEqual(new[] { overlay }, overlayManager.Overlays);
        }
        public void AddOverlay_WhenOverlayIsNotNullAndIsPresent_RemovesTheOverlay()
        {
            var overlayManager = new OverlayManager();
            var overlay = new StubOverlay();
            overlayManager.AddOverlay(overlay);

            overlayManager.RemoveOverlay(overlay);

            Assert.Count(0, overlayManager.Overlays);
        }
        public void PaintOverlays_PaintsAllOverlaysAndRestoresGraphicsContextForEachOne()
        {
            var overlayManager = new OverlayManager();
            var overlay1 = new OverlayThatChangesInterpolationMode();
            var overlay2 = new OverlayThatChangesInterpolationMode();
            overlayManager.AddOverlay(overlay1);
            overlayManager.AddOverlay(overlay2);

            using (Bitmap bitmap = new Bitmap(32, 32))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    var request = new OverlayPaintRequest(graphics, new Rectangle(0, 0, 32, 32), 0, 0);

                    overlayManager.PaintOverlays(request);

                    Assert.Multiple(() =>
                    {
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, graphics.InterpolationMode);

                        Assert.IsTrue(overlay1.WasPainted);
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, overlay1.OldInterpolationMode);

                        Assert.IsTrue(overlay2.WasPainted);
                        Assert.AreEqual(InterpolationMode.HighQualityBilinear, overlay2.OldInterpolationMode);
                    });
                }
            }
        }
        public void AddOverlay_WhenOverlayIsNull_Throws()
        {
            var overlayManager = new OverlayManager();

            Assert.Throws<ArgumentNullException>(() => overlayManager.AddOverlay(null));
        }
        public void ToOverlay_ReturnsACompositeOverlay()
        {
            var overlayManager = new OverlayManager();
            var overlay = new OverlayThatChangesInterpolationMode();
            overlayManager.AddOverlay(overlay);

            Overlay compositeOverlay = overlayManager.ToOverlay();

            var compositeOverlayManager = new OverlayManager();
            compositeOverlayManager.AddOverlay(compositeOverlay);
            using (Bitmap bitmap = new Bitmap(32, 32))
                compositeOverlayManager.PaintOverlaysOnImage(bitmap, 0, 0);
            Assert.IsTrue(overlay.WasPainted);
        }
        public void Paint()
        {
            var overlayManager = new OverlayManager();
            var overlay = new CaptionOverlay()
            {
                Text = "This is some text.",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Bottom
            };
            overlayManager.AddOverlay(overlay);

            using (Bitmap bitmap = CreateBitmapWithBackground())
            {
                overlayManager.PaintOverlaysOnImage(bitmap, 0, 0);

                TestLog.WriteLine("Image should contain 'This is some text.' centered at the bottom.");
                TestLog.EmbedImage("Image", bitmap);
            }
        }