public void HandleError_IsCustomErrorEnabledTrue_SetsNonSensitiveErrorMessage()
        {
            var contextStub = MockRepository.GenerateStub <HttpContextBase>();

            contextStub.Stub(_ => _.Items).Return(new Hashtable());
            contextStub.Stub(_ => _.IsCustomErrorEnabled).Return(true);

            var requstStub = MockRepository.GenerateStub <HttpRequestBase>();

            requstStub.Stub(_ => _.ApplicationPath).Return("Application/Path");
            contextStub.Stub(_ => _.Request).Return(requstStub);

            var handler          = new SmartPageAsyncPostBackErrorHandler(contextStub);
            var exceptionMessage = "The error";

            Assert.That(() => handler.HandleError(new ApplicationException(exceptionMessage)), Throws.TypeOf <AsyncUnhandledException>());

            var message = contextStub.Items[ControlHelper.AsyncPostBackErrorMessageKey];

            Assert.That(message, Is.StringStarting(@"

            <span><h1>"));
            Assert.That(message, Is.Not.StringContaining(exceptionMessage));
            Assert.That(message, Is.StringContaining("Application/Path"));
            Assert.That(message, Is.StringEnding(@"<br/>

    "));
        }
        public void HandleError_SetsAsyncErrorInformation()
        {
            var contextStub = MockRepository.GenerateStub <HttpContextBase>();

            contextStub.Stub(_ => _.Items).Return(new Hashtable());

            var handler = new SmartPageAsyncPostBackErrorHandler(contextStub);

            Assert.That(() => handler.HandleError(new ApplicationException("The error")), Throws.TypeOf <AsyncUnhandledException>());

            Assert.That(contextStub.Items[ControlHelper.AsyncPostBackErrorKey], Is.True);
            Assert.That(contextStub.Items[ControlHelper.AsyncPostBackErrorHttpCodeKey], Is.EqualTo(500));
            Assert.That(contextStub.Items[ControlHelper.AsyncPostBackErrorMessageKey], Is.Not.Empty);
        }
        public void HandleError_IsCustomErrorEnabledFalse_SetsAspNetDetailedErrorMessage()
        {
            var contextStub = MockRepository.GenerateStub <HttpContextBase>();

            contextStub.Stub(_ => _.Items).Return(new Hashtable());
            contextStub.Stub(_ => _.IsCustomErrorEnabled).Return(false);

            var handler = new SmartPageAsyncPostBackErrorHandler(contextStub);

            Assert.That(() => handler.HandleError(new ApplicationException("The error")), Throws.TypeOf <AsyncUnhandledException>());

            var message = contextStub.Items[ControlHelper.AsyncPostBackErrorMessageKey];

            Assert.That(message, Is.StringStarting(@"

            <span><H1>"));
            Assert.That(message, Is.StringContaining("[ApplicationException: The error]"));
            Assert.That(message, Is.StringEnding(@"<br>

    "));
        }