Esempio n. 1
0
        /// <summary>
        ///     Обработать исключения типа FigureException
        /// </summary>
        /// <param name="exception">Исключение</param>
        private void HandleFigureException(FigureException exception)
        {
            _errorProvider.Clear();
            Control control;

            switch (exception.FigureError.Key)
            {
            case "sizeX":
                control = _textBoxBaseX;
                break;

            case "sizeY":
                control = _textBoxBaseY;
                break;

            case "sizeZ":
                control = _textBoxBaseZ;
                break;

            case "heightWallsX":
                control = _textBoxHeightWallsX;
                break;

            case "heightWallsY":
                control = _textBoxHeightWallsY;
                break;

            case {} key when key.StartsWith("wallX"):
            {
                var number = int.Parse(key.Substring(5));
                control = _wallsX[number - 1];
                break;
            }

            case {} key when key.StartsWith("wallY"):
            {
                var number = int.Parse(key.Substring(5));
                control = _wallsY[number - 1];
                break;
            }

            default:
                MessageBox.Show(exception.FigureError.Message,
                                string.Empty,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);

                return;
            }

            _errorProvider.SetError(control, exception.FigureError.Message);
        }
        public void FigureErrorTest_PropertiesShouldReturnValidData()
        {
            const string key     = "key";
            const string message = "msg";

            var exception = new FigureException(key, message);

            Assert.AreEqual(key, exception.FigureError.Key);
            Assert.AreEqual(message, exception.FigureError.Message);

            var figureError = new FigureError();

            exception.FigureError = figureError;
            Assert.AreEqual(figureError, exception.FigureError);

            exception.FigureError = null;
            Assert.IsNull(exception.FigureError);
        }