public void Application_Error_InnerExceptionECNException_PageRedirected()
        {
            // Arrange
            var exp = new ECNException(new List <ECNError>
            {
                new ECNError
                {
                    ErrorMessage = TestErrorMessage,
                    Entity       = Entity.Blast,
                    Method       = Method.Get
                }
            });

            SetUpFakes();
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.ValidationError.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain(TestErrorMessage),
                () => _logDictionary[exp].ShouldContain(Entity.Blast.ToString()),
                () => _logDictionary[exp].ShouldContain(Method.Get.ToString()));
        }
        public void Application_Error_WhenDangerousRequest_PageRedirected()
        {
            // Arrange
            var exp = new Exception("A potentially dangerous Request");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.InvalidLink.ToString()),
                () => RedirectUrl.ShouldContain(SampleHostPath));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain($"CustomerID: {1}"),
                () => _logDictionary[exp].ShouldContain($"TestUser"));
        }
        public void Application_Error_WhenHttpExceptionBaseExceptionOtherException_PageRedirected()
        {
            // Arrange
            var exp = new Exception(TestDemoException, new TestHelperException <Exception>());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp.InnerException));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp.InnerException),
                () => _logDictionary[exp.InnerException].ShouldContain(SampleHost),
                () => _logDictionary[exp.InnerException].ShouldContain(SampleHostPath));
        }
        public void Application_Error_InnerExceptionSecurityError_PageRedirected()
        {
            // Arrange
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => new Exception("dummy exception", new SecurityException());

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.SecurityError.ToString());
        }
        public void Application_Error_WhenHttpExceptionBaseExceptionHttpException_PageRedirected()
        {
            // Arrange
            var exp = new TestHelperException <HttpException>();

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.InvalidLink.ToString());
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldBeEmpty();
        }
Exemplo n.º 6
0
        public void Application_Error_InnerExceptionSecurityErrorAndSecurityTypeFeatureNotEnabled_PageRedirected()
        {
            // Arrange
            ShimHttpServerUtility.AllInstances.GetLastError = (u) => new Exception(
                TestDemoException,
                new SecurityException
            {
                SecurityType = SecurityExceptionType.FeatureNotEnabled
            });

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain("/main/featureAccessError.aspx"));
        }
        public void Application_Error_WhenGeneralAspNetException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("ASP.NET session has expired or could not be found");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString());
            RedirectUrl.ShouldContain(SampleHostPath);
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldBeEmpty();
        }
        public void Application_Error_InnerExceptionViewStateException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("demo exception", new ViewStateException());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.Timeout.ToString());
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldNotBeEmpty();
            _logDictionary.ShouldContainKey(exp);
            _logDictionary[exp].ShouldContain(SampleUserAgent);
        }
        public void Application_Error_WhenGeneralException_PageRedirected()
        {
            // Arrange
            var exp = new Exception("does not exist");

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString()),
                () => RedirectUrl.ShouldContain("/error.aspx?"),
                () => RedirectUrl.ShouldContain(SampleHostPath));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldBeEmpty();
        }
        public void Application_Error_WhenUserCurrentSessionException_PageRedirected()
        {
            // Arrange
            var exp = new Exception();

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldNotBeNullOrWhiteSpace();
            RedirectUrl.ShouldContain(ErrorMessage.HardError.ToString());
            RedirectUrl.ShouldContain(SampleHostPath);
            ApplicationState.ShouldNotBeEmpty();
            ApplicationState.ShouldContainKeyAndValue("err", exp);
            _logDictionary.ShouldNotBeEmpty();
            _logDictionary.ShouldContainKey(exp);
            _logDictionary[exp].ShouldContain($"CustomerID: {1}");
            _logDictionary[exp].ShouldContain($"TestUser");
        }
        public void Application_Error_WhenTransactionAbortedException_PageRedirected()
        {
            // Arrange
            var exp = new Exception(TestDemoException, new TransactionAbortedException());

            ShimHttpServerUtility.AllInstances.GetLastError = (u) => exp;
            SetUpFakes();

            // Act
            _privateObject.Invoke(ApplicationErrorMethodName, this, EventArgs.Empty);

            // Assert
            PageRedirect.ShouldBeTrue();
            RedirectUrl.ShouldSatisfyAllConditions(
                () => RedirectUrl.ShouldNotBeNullOrWhiteSpace(),
                () => RedirectUrl.ShouldContain(ErrorMessage.Timeout.ToString()));
            ApplicationState.ShouldSatisfyAllConditions(
                () => ApplicationState.ShouldNotBeEmpty(),
                () => ApplicationState.ShouldContainKeyAndValue("err", exp));
            _logDictionary.ShouldSatisfyAllConditions(
                () => _logDictionary.ShouldNotBeEmpty(),
                () => _logDictionary.ShouldContainKey(exp),
                () => _logDictionary[exp].ShouldContain(SampleUserAgent));
        }