public void ShouldAddCircleToRepository()
        {
            var shape = new Circle();

            var shapeRepository = new ShapeRepository();

            shapeRepository.AddShape(shape);
            var shapes = shapeRepository.GetShapes();

            CollectionAssert.Contains(shapes, shape);
        }
Beispiel #2
0
        private void Scene_MouseDown(object sender, MouseEventArgs e)
        {
            if (penSettings.CBPenColor.SelectedItem == null ||
                penSettings.PenTypeComboBox.SelectedItem == null ||
                penSettings.CBPenWidth.SelectedItem == null)
            {
                MessageBox.Show("First choose pen settings!");
                return;
            }
            if (createFigure.CBCreateFigure.SelectedItem == null || createFigure.textBox1.Text == " ")
            {
                MessageBox.Show("First choos form to display");
            }
            if (e.Button == MouseButtons.Right)
            {
                foreach (var shapeToSearch in this.ShapesRepo.shapes)
                {
                    if (shapeToSearch.IsInside(e.Location))
                    {
                        this.shapeattributes = new ShapeAttributes(shapeToSearch);
                        shapeattributes.Show();
                        break;
                    }
                }
            }
            else
            {
                if (!ExceptionArea(e))
                {
                    return;
                }

                MyPoint point = new MyPoint(e.X, e.Y);

                Shape shape = CreateShape(point);
                ShapesRepo.AddShape(shape);

                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream("temporary.txt",
                                                      FileMode.Create,
                                                      FileAccess.Write,
                                                      FileShare.None);
                formatter.Serialize(stream, this.ShapesRepo);
                stream.Close();
            }
            Invalidate();
        }
Beispiel #3
0
        private void CBFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            var newListToDisplay = new List <Shape>();

            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream("temporary.txt",
                                                  FileMode.Open,
                                                  FileAccess.Read,
                                                  FileShare.Read);

            this.ShapesRepo = (ShapeRepository)formatter.Deserialize(stream);
            stream.Close();
            Invalidate();

            if (CBFilter.SelectedIndex == 0)
            {
                foreach (var shape in this.ShapesRepo.shapes.OrderBy(x => x.CalculateSurface()).Take(10))
                {
                    newListToDisplay.Add(shape);
                }
            }
            else if (CBFilter.SelectedIndex == 1)
            {
                foreach (var shape in this.ShapesRepo.shapes.OrderBy(x => x.Perimeter()).Take(10))
                {
                    newListToDisplay.Add(shape);
                }
            }
            else if (CBFilter.SelectedIndex == 2)
            {
                newListToDisplay = this.ShapesRepo.shapes.Where(x => x.GetType().Name == "Circle").ToList();
            }
            else if (CBFilter.SelectedIndex == 3)
            {
                newListToDisplay = this.ShapesRepo.shapes.Where(x => x.GetType().Name == "Triangle").ToList();
            }
            else if (CBFilter.SelectedIndex == 4)
            {
                newListToDisplay = this.ShapesRepo.shapes.Where(x => x.GetType().Name == "Square").ToList();
            }
            else if (CBFilter.SelectedIndex == 5)
            {
                newListToDisplay = this.ShapesRepo.shapes.Where(x => x.GetType().Name == "Rectangle").ToList();
            }
            else if (CBFilter.SelectedIndex == 6)
            {
                Invalidate();
                return;
            }

            for (int i = 0; i < ShapesRepo.shapes.Count; i++)
            {
                ShapesRepo.shapes.RemoveAt(i);
                i--;
            }

            for (int i = 0; i < newListToDisplay.Count; i++)
            {
                ShapesRepo.AddShape(newListToDisplay[i]);
            }
            Invalidate();
            // Refresh();
        }