System.Data.Tests.ConstraintTest.SetConstraintNameNullOrEmptyExceptions C# (CSharp) Method

SetConstraintNameNullOrEmptyExceptions() private method

private SetConstraintNameNullOrEmptyExceptions ( ) : void
return void
        public void SetConstraintNameNullOrEmptyExceptions()
        {
            bool exceptionCaught = false;
            string name = null;

            _table.Constraints.Add(_constraint1);

            for (int i = 0; i <= 1; i++)
            {
                exceptionCaught = false;
                if (0 == i)
                    name = null;
                if (1 == i)
                    name = string.Empty;

                try
                {
                    //Next line should throw ArgumentException
                    //Because ConstraintName can't be set to null
                    //or empty while the constraint is part of the
                    //collection
                    _constraint1.ConstraintName = name;
                }
                catch (ArgumentException)
                {
                    exceptionCaught = true;
                }
                catch
                {
                    Assert.False(true);
                }

                Assert.True(exceptionCaught);
            }
        }