예제 #1
0
        public bool ProcessFile(string fileInputPath, string fileOutputPath)
        {
            Canvas canvas;
            List <Tuple <char, string[]> > parameters = _fileReader.ReadFile(fileInputPath);

            if (!parameters.Any(p => p.Item1 == 'C'))
            {
                Console.WriteLine("There is no canvas in the input file");
                return(false);
            }
            else
            {
                var canvasParameter = parameters.FirstOrDefault(p => p.Item1 == 'C');
                canvas = _canvasService.CreateCanvas(int.Parse(canvasParameter.Item2[0]), int.Parse(canvasParameter.Item2[1]));
                parameters.Remove(canvasParameter);
                _fileWriter.ClearFile(fileOutputPath);
                _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
            }

            foreach (var parameter in parameters)
            {
                switch (parameter.Item1)
                {
                case 'L':
                {
                    Line line = new Line(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                         new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _lineService.CreateShape(ref canvas, line);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'R':
                {
                    Rectangle rectangle = new Rectangle(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                        new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _rectangleService.CreateShape(ref canvas, rectangle);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'B':
                {
                    _bucketFillService.FillCanvas(ref canvas,
                                                  new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                  char.Parse(parameter.Item2[2]));
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;
                }
            }
            return(true);
        }
예제 #2
0
        public void FileWriter_DrawShapeIntoFile_Test()
        {
            // Given
            string outputFilePath   = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{@"\Resource\OutputTest.txt"}";
            string templateFilePath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{@"\Resource\OutputTemplateTest.txt"}";
            Canvas canvas           = new Canvas(4, 4);

            canvas.Matrix[0, 0] = '-';
            canvas.Matrix[0, 1] = '-';
            canvas.Matrix[0, 2] = '-';
            canvas.Matrix[0, 3] = '-';
            canvas.Matrix[3, 0] = '-';
            canvas.Matrix[3, 1] = '-';
            canvas.Matrix[3, 2] = '-';
            canvas.Matrix[3, 3] = '-';
            canvas.Matrix[1, 0] = '|';
            canvas.Matrix[2, 0] = '|';
            canvas.Matrix[1, 3] = '|';
            canvas.Matrix[2, 3] = '|';

            // When
            _fileWriter.DrawShapeIntoFile(canvas, outputFilePath);

            //Then
            Assert.IsTrue(CompareFiles(outputFilePath, templateFilePath));
        }