Exemplo n.º 1
0
 public void ThrowsComponentsCantBeLinkedExceptionIfComponentsAreOfIncorrectType()
 {
     BSManager.AddComponentWithNameAndRectangle(inputComponentName, new Rectangle(0, 0, width, height));
     BSManager.AddComponentWithNameAndRectangle(preprocessorComponentName, new Rectangle(width + distanceBetweenRects, 0, width, height));
     BSManager.LinkComponentsAtPoints(new Point(rnd.Next(width + distanceBetweenRects, 2 * width + distanceBetweenRects), rnd.Next(height)),
                                      new Point(rnd.Next(width), rnd.Next(height)));
 }
        public void MyTestInitialize()
        {
            Rectangle componentRectangle  = new Rectangle(0, 0, width, height);
            string    randomComponentName = BSManager.ComponentsNamesDict.Keys.ElementAt(rnd.Next(BSManager.ComponentsNamesDict.Keys.Count));

            BSManager.AddComponentWithNameAndRectangle(randomComponentName, componentRectangle);
        }
        public void ThrowsArgumentException()
        {
            Mock <BSBaseComponent> componentMock = new Mock <BSBaseComponent>();
            Mock <BSBaseComponent> successorMock = new Mock <BSBaseComponent>();

            BSManager.AddComponent(componentMock.Object);
            BSManager.AddPredecessorForComponent(componentMock.Object, successorMock.Object);
        }
 private void mainPictureBox_MouseDown(object sender, MouseEventArgs e)
 {
     dragStartingPoint = e.Location;
     if (BSManager.ExistsSuitableInputComponentAtPoint(dragStartingPoint))
     {
         imageBeforeDrag = new Bitmap((sender as PictureBox).Image);
     }
 }
 private void MainForm_Load(object sender, EventArgs e)
 {
     _AddComponentsImages();
     _ConfigureMainDrawingArea();
     arrowDrawingPen.EndCap       = LineCap.ArrowAnchor;
     arrowDrawingPen.CustomEndCap = new AdjustableArrowCap(5, 7);
     BSManager.RegisterRunFinishedDelegate(new RunFinishedDelegate(SimulationFinished));
     BSManager.RegisterRunAbortedDelegate(new RunAbortedDelegate(SimulationAborted));
 }
        public void ReturnsEmptyList()
        {
            Mock <BSBaseComponent> componentMock = new Mock <BSBaseComponent>();

            BSManager.AddComponent(componentMock.Object);
            IList <BSBaseComponent> receivedSuccessors = BSManager.SuccessorsForComponent(componentMock.Object);

            Assert.AreEqual(0, receivedSuccessors.Count);
        }
Exemplo n.º 7
0
 public void AddsNewComponentSuccessfully()
 {
     foreach (int i in Enumerable.Range(1, new Random().Next(10)))
     {
         Mock <BSBaseComponent> componentMock = new Mock <BSBaseComponent>();
         BSManager.AddComponent(componentMock.Object);
         Assert.AreEqual(i, BSManager.Components.Count);
         Assert.IsTrue(BSManager.Components.Contains(componentMock.Object));
     }
 }
        public void WorksCorrectlyIfComponentExists()
        {
            const int numOfTries = 50;

            for (int i = 0; i < numOfTries; ++i)
            {
                Point pointInsideRect = new Point(rnd.Next(width), rnd.Next(height));
                Assert.IsTrue(BSManager.ExistsComponentAtPoint(pointInsideRect));
            }
        }
        public void ThrowsKeyNotFoundException()
        {
            Random rnd = new Random();
            string notPresentKey;

            while (BSManager.ComponentsNamesDict.ContainsKey(notPresentKey = Convert.ToString(rnd.Next())))
            {
                ;
            }
            BSManager.AddComponentWithNameAndRectangle(notPresentKey, new Rectangle());
        }
 private void mainPictureBox_DragDrop(object sender, DragEventArgs e)
 {
     if (null != draggedImg)
     {
         Point     mousePos      = (sender as Control).PointToClient(new Point(e.X, e.Y));
         Rectangle componentRect = new Rectangle(mousePos.X - draggedImg.Width / 2, mousePos.Y - draggedImg.Height / 2, draggedImg.Width, draggedImg.Height);
         _DrawComponentOnPictureBoxInRectangle(e, draggedImg, (sender as PictureBox), componentRect);
         BSManager.AddComponentWithNameAndRectangle(e.Data.GetData(DataFormats.StringFormat) as string, componentRect);
         draggedImg = null;
     }
 }
        public void WorksCorrectlyIfNoComponentMatches()
        {
            const int numOfTries = 50;
            int       j;

            for (int i = 0; i < numOfTries; ++i)
            {
                j = rnd.Next(2);
                Point pointOutsideRect = new Point(rnd.Next(width) + width * j, rnd.Next(height) + height * (1 - j));
                Assert.IsFalse(BSManager.ExistsComponentAtPoint(pointOutsideRect));
            }
        }
        public void AddsPredecessorsSuccessfully()
        {
            Mock <BSBaseComponent> componentMock   = new Mock <BSBaseComponent>();
            Mock <BSBaseComponent> predecessorMock = new Mock <BSBaseComponent>();

            BSManager.AddComponent(componentMock.Object);
            BSManager.AddComponent(predecessorMock.Object);
            BSManager.AddPredecessorForComponent(componentMock.Object, predecessorMock.Object);
            IList <BSBaseComponent> receivedPredecessors = BSManager.PredecessorsForComponent(componentMock.Object);

            Assert.IsTrue(receivedPredecessors.Contains(predecessorMock.Object));
            Assert.AreEqual(1, receivedPredecessors.Count);
        }
 private void runToolStripButton_Click(object sender, EventArgs e)
 {
     try
     {
         transparentImage = ImgUtils.SetImgOpacity(mainPictureBox.Image, 0.3F);
         realImage        = mainPictureBox.Image;
         SwitchSimulationVisualization(true);
         BSManager.Run();
     }
     catch (ComponentsArentReadyException exc)
     {
         MessageBox.Show(exc.Message, "Не усі компоненти корректно налаштовані!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         SwitchSimulationVisualization(false);
     }
 }
 private void mainPictureBox_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         contextMenuStrip.Items.Clear();
         if (BSManager.ExistsComponentAtPoint(e.Location))
         {
             contextMenuStrip.Items.Add("Налаштувати", null, new EventHandler((obj, arg) => BSManager.UserDoubleClickedOnPoint(e.Location)));
             contextMenuStrip.Items.Add(new ToolStripSeparator());
         }
         AddGeneralHelpItemToContextMenuStrip(contextMenuStrip, "Це головна робоча область. Перетягніть сюди усі потрібні елементи (із списку елементів " +
                                              "зліва), з'єднайте їх потрібним чином і натисніть кнопку 'Запустити' на панелі згори (або просто клавішу F5). Це призведе до запуску побудованої " +
                                              "схеми на виконання. Для налаштування будь-якого елемента двічі натисніть лівою кнопкою миші на ньому, або один раз правою кнопкою, і виберіть 'Налаштувати'.");
         contextMenuStrip.Show((sender as Control).PointToScreen(e.Location));
     }
 }
Exemplo n.º 15
0
        public void LinksComponentsSuccessfullyIfEverythingIsGood()
        {
            BSManager.AddComponentWithNameAndRectangle(inputComponentName, new Rectangle(0, 0, width, height));
            BSBaseComponent input = BSManager.Components[0];

            BSManager.AddComponentWithNameAndRectangle(preprocessorComponentName, new Rectangle(width + distanceBetweenRects, 0, width, height));
            BSBaseComponent preprocessor = BSManager.Components[1];

            BSManager.LinkComponentsAtPoints(new Point(rnd.Next(width), rnd.Next(height)),
                                             new Point(rnd.Next(width + distanceBetweenRects, 2 * width + distanceBetweenRects), rnd.Next(height)));
            IList <BSBaseComponent> actualSuccs = BSManager.SuccessorsForComponent(input), actualPreds = BSManager.PredecessorsForComponent(preprocessor);

            Assert.AreEqual(1, actualSuccs.Count); Assert.AreEqual(1, actualPreds.Count);
            Assert.AreSame(preprocessor, actualSuccs[0]);
            Assert.AreSame(input, actualPreds[0]);
        }
        public void AddsNewComponentCorrectly()
        {
            Random             rnd = new Random();
            string             randomComponentName           = BSManager.ComponentsNamesDict.Keys.ElementAt(rnd.Next(BSManager.ComponentsNamesDict.Keys.Count));
            IComponentsFactory correspondingComponentFactory = BSManager.ComponentsNamesDict[randomComponentName];
            Rectangle          componentRectangle            = new Rectangle(rnd.Next(), rnd.Next(), rnd.Next(), rnd.Next());
            BSBaseComponent    expectedComp = correspondingComponentFactory.NewComponent(componentRectangle);

            BSManager.AddComponentWithNameAndRectangle(randomComponentName, componentRectangle);
            IList <BSBaseComponent> actualCompsList = BSManager.Components;

            Assert.AreEqual(1, actualCompsList.Count);
            BSBaseComponent actualComp = actualCompsList.First();

            Assert.AreEqual(expectedComp.GetType(), actualComp.GetType());
            Assert.AreEqual(componentRectangle, actualComp.OnScreenRectangle);
        }
 private void mainPictureBox_MouseUp(object sender, MouseEventArgs e)
 {
     if (imageBeforeDrag != null)
     {
         try
         {
             BSManager.LinkComponentsAtPoints(dragStartingPoint, e.Location);
         }
         catch (Exception exc)
         {
             if (exc is ComponentsCantBeLinkedException || exc is ArgumentException)
             {
                 (sender as PictureBox).Image = imageBeforeDrag;
             }
             else
             {
                 throw;
             }
         }
     }
     imageBeforeDrag = null;
 }
 public void MyTestCleanup()
 {
     BSManager.ClearComponentsList();
 }
 private void mainPictureBox_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     BSManager.UserDoubleClickedOnPoint(e.Location);
 }
Exemplo n.º 20
0
 public void ThrowsArgumentNullException()
 {
     BSManager.AddComponent(null);
 }
        public void ThrowsKeyNotFoundException()
        {
            Mock <BSBaseComponent> componentMock = new Mock <BSBaseComponent>();

            BSManager.SuccessorsForComponent(componentMock.Object);
        }
 public void ThrowsArgumentNullException()
 {
     BSManager.AddComponentWithNameAndRectangle(null, new Rectangle());
 }