Ejemplo n.º 1
0
        /// <summary>
        /// Checks the recorded errors up to this point in the test and fails the test if there are errors
        /// at the given <paramref name="expectedErrorLevel"/>
        /// </summary>
        /// <param name="expectedErrorLevel"></param>
        protected void AssertNoErrors(ExpectedErrorType expectedErrorLevel)
        {
            switch (expectedErrorLevel)
            {
            case ExpectedErrorType.KilledForm:
                Assert.IsEmpty(ItemActivator.Results.KilledForms);
                break;

            case ExpectedErrorType.Fatal:
                Assert.IsEmpty(ItemActivator.Results.FatalCalls);
                break;

            case ExpectedErrorType.FailedCheck:

                //there must have been something checked that failed with the provided message
                if (_checkResults != null)
                {
                    Assert.IsEmpty(_checkResults.Messages.Where(m => m.Result == CheckResult.Fail));
                }
                break;

            case ExpectedErrorType.ErrorProvider:
                Assert.IsEmpty(GetAllErrorProviderErrorsShown());

                break;

            case ExpectedErrorType.GlobalErrorCheckNotifier:

                Assert.IsEmpty(((ToMemoryCheckNotifier)_itemActivator.GlobalErrorCheckNotifier).Messages);

                break;

            case ExpectedErrorType.Any:
                AssertNoErrors(ExpectedErrorType.KilledForm);
                AssertNoErrors(ExpectedErrorType.Fatal);
                AssertNoErrors(ExpectedErrorType.FailedCheck);
                AssertNoErrors(ExpectedErrorType.ErrorProvider);
                AssertNoErrors(ExpectedErrorType.GlobalErrorCheckNotifier);
                break;

            default:
                throw new ArgumentOutOfRangeException("expectedErrorLevel");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks that the given <paramref name="expectedContainsText"/> was displayed to the user at the
        /// given <paramref name="expectedErrorLevel"/>
        /// </summary>
        /// <param name="expectedErrorLevel">The error level to be checked.  Do not pass 'Any'</param>
        /// <param name="expectedContainsText"></param>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="expectedErrorLevel"/> is not supported e.g. Any</exception>
        protected void AssertErrorWasShown(ExpectedErrorType expectedErrorLevel, string expectedContainsText)
        {
            switch (expectedErrorLevel)
            {
            case ExpectedErrorType.KilledForm:
                Assert.IsTrue(ItemActivator.Results.KilledForms.Values.Any(v => v.Message.Contains(expectedContainsText)), "Failed to find expected Exception, Exceptions were:\r\n" + string.Join(Environment.NewLine, ItemActivator.Results.KilledForms.Values.Select(v => v.ToString())));
                break;

            case ExpectedErrorType.Fatal:
                Assert.IsTrue(ItemActivator.Results.FatalCalls.Any(c => c.Message.Contains(expectedContainsText)));
                break;

            case ExpectedErrorType.FailedCheck:

                if (_checkResults == null)
                {
                    throw new Exception("Could not check for Checks error because control did not register an ICheckable");
                }

                AssertFailedCheck(_checkResults, expectedContainsText);

                break;

            case ExpectedErrorType.GlobalErrorCheckNotifier:

                AssertFailedCheck((ToMemoryCheckNotifier)_itemActivator.GlobalErrorCheckNotifier, expectedContainsText);
                break;

            case ExpectedErrorType.ErrorProvider:

                Assert.IsTrue(GetAllErrorProviderErrorsShown().Any(m => m.Contains(expectedContainsText)));

                break;

            default:
                throw new ArgumentOutOfRangeException("expectedErrorLevel");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks that the given <paramref name="expectedContainsText"/> was displayed to the user at the
        /// given <paramref name="expectedErrorLevel"/>
        /// </summary>
        /// <param name="expectedErrorLevel">The error level to be checked.  Do not pass 'Any'</param>
        /// <param name="expectedContainsText"></param>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="expectedErrorLevel"/> is not supported e.g. Any</exception>
        protected void AssertErrorWasShown(ExpectedErrorType expectedErrorLevel, string expectedContainsText)
        {
            switch (expectedErrorLevel)
            {
            case ExpectedErrorType.KilledForm:
                Assert.IsTrue(ItemActivator.Results.KilledForms.Values.Any(v => v.Message.Contains(expectedContainsText)), "Failed to find expected Exception, Exceptions were:\r\n" + string.Join(Environment.NewLine, ItemActivator.Results.KilledForms.Values.Select(v => v.ToString())));
                break;

            case ExpectedErrorType.Fatal:
                Assert.IsTrue(ItemActivator.Results.FatalCalls.Any(c => c.Message.Contains(expectedContainsText)));
                break;

            case ExpectedErrorType.FailedCheck:

                if (_checkResults == null)
                {
                    throw new Exception("Could not check for Checks error because control did not register an ICheckable");
                }

                //there must have been something checked that failed with the provided message
                Assert.IsTrue(_checkResults.Messages.Any(m =>
                                                         m.Message.Contains(expectedContainsText) ||
                                                         (m.Ex != null && m.Ex.Message.Contains(expectedContainsText)) &&
                                                         m.Result == CheckResult.Fail));

                break;

            case ExpectedErrorType.ErrorProvider:

                Assert.IsTrue(GetAllErrorProviderErrorsShown().Any(m => m.Contains(expectedContainsText)));

                break;

            default:
                throw new ArgumentOutOfRangeException("expectedErrorLevel");
            }
        }