public void Test_PatternCreator_GetEmbroidery()
        {
            var mockCanvasConverter = new Mock<ICanvasConverter>();
            var mockPatternMapGenerator = new Mock<IPatternMapGenerator>();
            var mockDecoratorCompositions = new Mock<IDecoratorsComposition>();

            mockPatternMapGenerator.Setup(map => map.Generate(It.IsAny<Canvas>(), It.IsAny<Settings>())).Returns(new Canvas(3, 3));
            mockCanvasConverter.Setup(conv => conv.ConvertBitmapToCanvas(It.IsAny<Bitmap>())).Returns(new Canvas(4, 3));
            mockDecoratorCompositions.Setup(decor => decor.Decorate(It.IsAny<Canvas>(), It.IsAny<Canvas>(), It.IsAny<Settings>()));

            Settings settings = new Settings();
            settings.CellsCount = 3;
            settings.Coefficient = 2;
            settings.Palette = new Palette(new Color[]{Color.Red, Color.Blue});
            settings.DecoratorsComposition = mockDecoratorCompositions.Object;

            EmbroideryCreator creator = new EmbroideryCreator();
            creator.CanvasConverter = mockCanvasConverter.Object;
            creator.PatternMapGenerator = mockPatternMapGenerator.Object;

            Bitmap image = new Bitmap(4, 3);

            creator.GetEmbroidery(image, settings);

            mockCanvasConverter.Verify(conv => conv.ConvertBitmapToCanvas(image));
            mockPatternMapGenerator.Verify(pat => pat.Generate(It.IsAny<Canvas>(), settings));
            mockDecoratorCompositions.Verify(decor => decor.Decorate(It.IsAny<Canvas>(), It.IsAny<Canvas>(), settings));
            mockCanvasConverter.Verify(conv => conv.ConvertCanvasToBitmap(It.IsAny<Canvas>()));
        }
        public static Bitmap CreateEmbroidery(Bitmap image, int resolutionCoefficient, int cellsCount, Color[] palette, char[] symbols, Color symbolColor, GridType type)
        {
            IKernel kernel = new StandardKernel(new PropertiesModel());

            var patternMapGenerator = kernel.Get<IPatternMapGenerator>();
            var canvasConverter = kernel.Get<ICanvasConverter>();

            var patternCreator = new EmbroideryCreator()
            {
                PatternMapGenerator = patternMapGenerator,
                CanvasConverter = canvasConverter,
            };

            Settings settings = new Settings()
            {
                CellsCount = cellsCount,
                Coefficient = resolutionCoefficient,
                Palette = new Palette(palette),
                Symbols = symbols,
                SymbolColor = symbolColor,
                GridType = type,
                DecoratorsComposition = new DecoratorsComposition()
            };

            if (settings.Palette != null)
                settings.DecoratorsComposition.AddDecorator(new CellsDecorator());
            if (settings.Symbols != null)
                settings.DecoratorsComposition.AddDecorator(new SymbolsDecorator());
            if (settings.GridType != Core.GridType.None)
                settings.DecoratorsComposition.AddDecorator(new GridDecorator());

            Bitmap result = patternCreator.GetEmbroidery(image, settings);

            return result;
        }
        public void Test_PatternCreator_GetEmbroideryException1()
        {
            Settings settings = new Settings();

            EmbroideryCreator creator = new EmbroideryCreator();

            Bitmap image = new Bitmap(4, 2);
            creator.GetEmbroidery(image, settings);
        }
        public void Test_PatternCretor_GetEmbroideryException2()
        {
            Settings settings = new Settings()
            {
                CellsCount = 1,
                Coefficient = 0
            };

            EmbroideryCreator creator = new EmbroideryCreator();

            Bitmap image = new Bitmap(5, 3);
            creator.GetEmbroidery(image, settings);
        }
Esempio n. 5
0
        public void Test_Calculate_PossibleResolutions_Coefficient()
        {
            EmbroideryCreator calculate = new EmbroideryCreator();

            Dictionary<string, int> actual = calculate.PossibleResolutions(new Bitmap(11, 7), 3, 3, 5);

            Dictionary<string, int> expected = new Dictionary<string, int>();
            int startWidth = 3;
            int startHeight = 2;

            for (int i = 3; i <= 5; i++)
                expected.Add(new Resolution(i * startWidth, i * startHeight).ToString(), i);

            Assert.IsTrue(expected.Count == actual.Count);

            Assert.AreEqual(DictionaryToString(expected), DictionaryToString(actual));
        }
Esempio n. 6
0
 public void Test_Calculate_PossibleResolutions_CoefficientException6()
 {
     EmbroideryCreator calculate = new EmbroideryCreator();
     calculate.PossibleResolutions(new Bitmap(11, 7), 3, 4, 3);
 }
Esempio n. 7
0
 public void Test_Calculate_PossibleResolutions_CoefficientException1()
 {
     EmbroideryCreator calculate = new EmbroideryCreator();
     calculate.PossibleResolutions(new Bitmap(1, 1), -1, 3, 5);
 }
Esempio n. 8
0
 public void Test_Calculate_PossibleResolutions_CountException4()
 {
     EmbroideryCreator calculate = new EmbroideryCreator();
     calculate.PossibleResolutions(new Bitmap(11, 2), 3, 0);
 }
Esempio n. 9
0
 public void Test_Calculate_PossibleResolutions_CountException1()
 {
     EmbroideryCreator calculate = new EmbroideryCreator();
     calculate.PossibleResolutions(new Bitmap(10, 3), 0, 5);
 }