Example #1
0
            public void AverageColorsOfAddedImagesWillBe0WhenNotInFullTrust()
            {
                var testable = new TestableSpriteContainer();
                var halfvioletHalfGreyImage = new BackgroundImageClass("image1", 0)
                {
                    ImageUrl = "url"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(TestableSpriteContainer.GetHalfvioletHalfGreyImageImage(Color.DarkViolet));
                testable.Mock <IRRConfiguration>().Setup(x => x.IsFullTrust).Returns(false);

                var result = testable.ClassUnderTest.AddImage(halfvioletHalfGreyImage);

                Assert.Equal(0, result.AverageColor);
            }
Example #2
0
            public void ColorCountWillBe0InRestrictedTrust()
            {
                var testable       = new TestableSpriteContainer();
                var fiveColorImage = new BackgroundImageClass("image1", "")
                {
                    ImageUrl = "url"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(TestableSpriteContainer.GetFiveColorImage());
                testable.Mock <IRRConfiguration>().Setup(x => x.IsFullTrust).Returns(false);

                testable.ClassUnderTest.AddImage(fiveColorImage);

                Assert.Equal(0, testable.ClassUnderTest.Colors);
            }
Example #3
0
            public void WillNotDownloadSameUrlTwice()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("image1", 0)
                {
                    ImageUrl = "url", IsSprite = true
                };
                var image2 = new BackgroundImageClass("image2", 0)
                {
                    ImageUrl = "url", IsSprite = true
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                testable.Mock <IWebClientWrapper>().Verify(x => x.DownloadBytes("url"), Times.Once());
            }
Example #4
0
            public void WillNotCacheNonSprites()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("image1", 0)
                {
                    ImageUrl = "url", IsSprite = true
                };
                var image2 = new BackgroundImageClass("image2", 0)
                {
                    ImageUrl = "url2", IsSprite = false
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(testable.Image15X17);
                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url2")).Returns(testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                Assert.True(testable.ClassUnderTest.DownloadedImages.ContainsKey("url"));
                Assert.False(testable.ClassUnderTest.DownloadedImages.ContainsKey("url2"));
            }
Example #5
0
            public void WillCountUniqueColorsOfAddedImages()
            {
                var testable       = new TestableSpriteContainer();
                var fiveColorImage = new BackgroundImageClass("image1", "")
                {
                    ImageUrl = "url"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(TestableSpriteContainer.GetFiveColorImage());
                var fourColorImage = new BackgroundImageClass("image2", "")
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url2")).Returns(TestableSpriteContainer.GetFourColorImage());

                testable.ClassUnderTest.AddImage(fiveColorImage);
                testable.ClassUnderTest.AddImage(fourColorImage);

                Assert.Equal(7, testable.ClassUnderTest.Colors);
            }
Example #6
0
            public void SizeWillBeAggregateOfAddedImages()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1"
                };
                var image2 = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url2")).Returns(
                    testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                Assert.Equal(testable.Image15X17.Length + testable.Image18X18.Length, testable.ClassUnderTest.Size);
            }
Example #7
0
            public void UniqueColorsOfAddedImagesWillBe0WhenNotInFullTrust()
            {
                var testable       = new TestableSpriteContainer();
                var fiveColorImage = new BackgroundImageClass("image1", 0)
                {
                    ImageUrl = "url"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(TestableSpriteContainer.GetFiveColorImage());
                var fourColorImage = new BackgroundImageClass("image2", 0)
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url2")).Returns(TestableSpriteContainer.GetFourColorImage());
                testable.Mock <IRRConfiguration>().Setup(x => x.IsFullTrust).Returns(false);

                testable.ClassUnderTest.AddImage(fiveColorImage);
                testable.ClassUnderTest.AddImage(fourColorImage);

                Assert.Equal(0, testable.ClassUnderTest.Colors);
            }
Example #8
0
            public void HeightWillBeTheTallestOfAddedImages()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1"
                };
                var image2 = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url2")).Returns(
                    testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                Assert.Equal(18, testable.ClassUnderTest.Height);
            }
Example #9
0
            public void WidthWillBeAggregateOfAddedImageWidthsPlusOnePixelEach()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1"
                };
                var image2 = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url2")).Returns(
                    testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                Assert.Equal(35, testable.ClassUnderTest.Width);
            }
Example #10
0
            public void WillReturnAllImages()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1"
                };
                var image2 = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url2"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url2")).Returns(
                    testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);
                testable.ClassUnderTest.AddImage(image2);

                Assert.Contains(image1, testable.ClassUnderTest.Select(x => x.CssClass));
                Assert.Contains(image2, testable.ClassUnderTest.Select(x => x.CssClass));
            }
Example #11
0
            public void HeightWillBeSizeOfBackgroundClassIfDifferentThanImageHeight(int height)
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1", Height = height
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(
                    testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(height, testable.ClassUnderTest.Height);
            }
Example #12
0
            public void WidthWillBeSizeOfBackgroundClassPluOneIfDifferentThanImageWidth(int width)
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1", Width = width
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(width + 1, testable.ClassUnderTest.Width);
            }
Example #13
0
            public void WillCalculateAverageColorsOfAddedImages()
            {
                var testable = new TestableSpriteContainer();
                var halfvioletHalfGreyImage = new BackgroundImageClass("image1", "")
                {
                    ImageUrl = "url"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(TestableSpriteContainer.GetHalfvioletHalfGreyImageImage(Color.DarkViolet));
                var color1 = Color.DarkViolet.ToArgb();
                var color2 = Color.DimGray.ToArgb();

                var result = testable.ClassUnderTest.AddImage(halfvioletHalfGreyImage);

                Assert.Equal((color1 + color2) / 2, result.AverageColor);
            }
Example #14
0
            public void WillAutoCorrectHeightIfHeightAndOffsetAreGreaterThanOriginal()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1", Height = 10, YOffset = new Position()
                    {
                        PositionMode = PositionMode.Unit, Offset = -10
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(10, testable.ClassUnderTest.Height);
            }
Example #15
0
            public void WillThrowInvalidOperationExceptionIfCloningThrowsOutOfMemory()
            {
                var testable       = new TestableSpriteContainer();
                var fiveColorImage = new BackgroundImageClass("image1", "")
                {
                    ImageUrl = "url", Width = 15, XOffset = new Position()
                    {
                        Offset = -16, Direction = Direction.Left
                    }, OriginalImageUrl = "originalUrl"
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url")).Returns(testable.Image15X17);

                var ex = Record.Exception(() => testable.ClassUnderTest.AddImage(fiveColorImage)) as InvalidOperationException;

                Assert.NotNull(ex);
                Assert.Contains("originalUrl", ex.Message);
            }
Example #16
0
            public void WillAutoCorrectWidthIfWidthAndOffsetAreGreaterThanOriginal()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1", ExplicitWidth = 10, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Unit, Offset = -10
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(Xunit => Xunit.DownloadBytes("url1")).Returns(
                    testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(11, testable.ClassUnderTest.Width);
            }
Example #17
0
            public void HorizontalyCenteredImagesLargerThanWidthWillBeCentered()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1", Width = 10, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Direction, Direction = Direction.Center
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);

                var image  = testable.ClassUnderTest.First();
                var image2 = new Bitmap(new MemoryStream(testable.Image18X18));

                Assert.Equal(image2.Clone(new Rectangle(4, 0, 10, 18), image2.PixelFormat).GraphicsImage(), image.Image.Clone(new Rectangle(0, 0, 10, 18), image2.PixelFormat), new BitmapPixelComparer(true));
            }
Example #18
0
            public void HorizontalyCenteredImagesWillBeCenteredInClonedImageSentToWriter()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1", ExplicitWidth = 30, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Direction, Direction = Direction.Center
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);

                var image  = testable.ClassUnderTest.First();
                var image2 = new Bitmap(new MemoryStream(testable.Image18X18));

                Assert.Equal(image2.GraphicsImage(), image.Image.Clone(new Rectangle(6, 0, 18, 18), image2.PixelFormat), new BitmapPixelComparer(true));
            }
Example #19
0
            public void RightPositionedImagesWillBeRightAlligned()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1", Width = 30, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Direction, Direction = Direction.Right
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                var image  = testable.ClassUnderTest.First();
                var image2 = new Bitmap(new MemoryStream(testable.Image15X17));

                Assert.Equal(image2.GraphicsImage(), image.Image.Clone(new Rectangle(15, 0, 15, 17), image2.PixelFormat), new BitmapPixelComparer(true));
            }
Example #20
0
            public void WillClipLeftEdgeOfBackgroundClassWhenOffsetIsNegative()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl      = "url1",
                    ExplicitWidth = 5,
                    XOffset       = new Position()
                    {
                        PositionMode = PositionMode.Unit, Offset = -5
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                var bitMap = new Bitmap(new MemoryStream(testable.Image15X17));

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(bitMap.Clone(new Rectangle(5, 0, 5, 17), bitMap.PixelFormat).GraphicsImage(),
                             testable.ClassUnderTest.First().Image, new BitmapPixelComparer(true));
            }
Example #21
0
            public void WillNotClipUpperEdgeOfBackgroundClassWhenOffsetIsPositive()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", "http://server/content/style.css")
                {
                    ImageUrl = "url1",
                    Height   = 5,
                    YOffset  = new Position()
                    {
                        PositionMode = PositionMode.Percent, Offset = 50
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(
                    testable.Image15X17);
                var bitMap = new Bitmap(new MemoryStream(testable.Image15X17));

                testable.ClassUnderTest.AddImage(image1);

                Assert.Equal(bitMap.Clone(new Rectangle(0, 0, 15, 5), bitMap.PixelFormat).GraphicsImage(),
                             testable.ClassUnderTest.First().Image, new BitmapPixelComparer(true));
            }
Example #22
0
            public void BottomPositionedImagesLargerThanHeightWillBeBottomAlligned()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1", ExplicitWidth = 10, ExplicitHeight = 10, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Direction, Direction = Direction.Right
                    }, YOffset = new Position()
                    {
                        PositionMode = PositionMode.Direction, Direction = Direction.Bottom
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(testable.Image15X17);

                testable.ClassUnderTest.AddImage(image1);

                var image  = testable.ClassUnderTest.First();
                var image2 = new Bitmap(new MemoryStream(testable.Image15X17));

                Assert.Equal(image2.Clone(new Rectangle(5, 7, 10, 10), image2.PixelFormat).GraphicsImage(), image.Image.Clone(new Rectangle(0, 0, 10, 10), image2.PixelFormat), new BitmapPixelComparer(true));
            }
Example #23
0
            public void PositivelyXOffsetImagesLargerThanWidthWillBeCorrectlyPositioned()
            {
                var testable = new TestableSpriteContainer();
                var image1   = new BackgroundImageClass("", 0)
                {
                    ImageUrl = "url1", ExplicitWidth = 10, ExplicitHeight = 10, XOffset = new Position()
                    {
                        PositionMode = PositionMode.Unit, Offset = 2
                    }, YOffset = new Position()
                    {
                        PositionMode = PositionMode.Unit, Offset = 0
                    }
                };

                testable.Mock <IWebClientWrapper>().Setup(x => x.DownloadBytes("url1")).Returns(testable.Image18X18);

                testable.ClassUnderTest.AddImage(image1);

                var image  = testable.ClassUnderTest.First();
                var image2 = new Bitmap(new MemoryStream(testable.Image18X18));

                Assert.Equal(image2.Clone(new Rectangle(0, 0, 8, 7), image2.PixelFormat).GraphicsImage(), image.Image.Clone(new Rectangle(2, 0, 8, 7), image2.PixelFormat), new BitmapPixelComparer(true));
            }