public void Indexer_Index_Negative()
        {
            Form form = new Form();

            form.ShowInTaskbar = false;
            form.Controls.Add(_dataGridView);
            form.Show();

            DataGridViewCellCollection cells = _dataGridView.Rows [0].Cells;

            try
            {
                DataGridViewCell cell = cells [-1];
                Assert.Fail("#A1:" + cell);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Index was out of range. Must be non-negative
                // and less than the size of the collection
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#A2");
                Assert.IsNull(ex.InnerException, "#A3");
                Assert.IsNotNull(ex.Message, "#A4");
                Assert.IsNotNull(ex.ParamName, "#A5");
                Assert.AreEqual("index", ex.ParamName, "#A6");
            }

            try
            {
                cells [-1] = new MockDataGridViewCell();
                Assert.Fail("#B1");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Index was out of range. Must be non-negative
                // and less than the size of the collection
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#B2");
                Assert.IsNull(ex.InnerException, "#B3");
                Assert.IsNotNull(ex.Message, "#B4");
                Assert.IsNotNull(ex.ParamName, "#B5");
                Assert.AreEqual("index", ex.ParamName, "#B6");
            }
        }
コード例 #2
0
		public void Indexer_Index_Negative ()
		{
			Form form = new Form ();
			form.ShowInTaskbar = false;
			form.Controls.Add (_dataGridView);
			form.Show ();

			DataGridViewCellCollection cells = _dataGridView.Rows [0].Cells;

			try {
				DataGridViewCell cell = cells [-1];
				Assert.Fail ("#A1:" + cell);
			} catch (ArgumentOutOfRangeException ex) {
				// Index was out of range. Must be non-negative
				// and less than the size of the collection
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("index", ex.ParamName, "#A6");
			}

			try {
				cells [-1] = new MockDataGridViewCell ();
				Assert.Fail ("#B1");
			} catch (ArgumentOutOfRangeException ex) {
				// Index was out of range. Must be non-negative
				// and less than the size of the collection
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("index", ex.ParamName, "#B6");
			}
		}