Exemplo n.º 1
0
        public void UnwrapHttpUnhandledException_WithHttpUnhandledExceptionContainingNoInnerException_ReturnsNull()
        {
            // act
            Exception exception = SubtextApplication.UnwrapHttpUnhandledException(new HttpUnhandledException());

            // assert
            Assert.IsNull(exception);
        }
Exemplo n.º 2
0
        public void HandleSqlException_ReturnsFalseForNonSqlException()
        {
            // arrange
            var exception = new Exception();

            // act
            bool handled = SubtextApplication.HandleSqlException(exception, null);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 3
0
        public void LogIfCommentException_DoesNothingForNonCommentException()
        {
            // arrange
            var exception = new Exception();
            var log       = new Mock <ILog>();

            log.Setup(l => l.Info(It.IsAny <string>())).Throws(new Exception("Nothing should have been logged"));

            // act, assert
            SubtextApplication.LogIfCommentException(exception, log.Object);
        }
Exemplo n.º 4
0
        UnwrapHttpUnhandledException_WithHttpUnhandledExceptionContainingInnerException_ReturnsInnerException()
        {
            // arrange
            var innerException = new Exception();

            // act
            Exception exception =
                SubtextApplication.UnwrapHttpUnhandledException(new HttpUnhandledException("whatever", innerException));

            // assert
            Assert.AreEqual(innerException, exception);
        }
Exemplo n.º 5
0
        public void StartApplication_SetsLogInitializedToFalse()
        {
            // arrange
            var app    = new SubtextApplication(null);
            var server = new Mock <HttpServerUtilityBase>();

            // act
            app.StartApplication(new SubtextRouteMapper(new RouteCollection(), new Mock <IServiceLocator>().Object),
                                 server.Object);

            // assert
            Assert.IsFalse(app.LogInitialized);
        }
Exemplo n.º 6
0
        public void HandleBadConnectionStringException_IgnoresOtherExceptions()
        {
            // arrange
            var exception = new Exception();
            var server    = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.Transfer(It.IsAny <string>())).Throws(new Exception("Should not have transfered"));

            // act
            bool handled = SubtextApplication.HandleBadConnectionStringException(exception, server.Object);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 7
0
        HandleBadConnectionStringException_WithInvalidOperationExceptionContainingOtherMessages_IgnoresException()
        {
            // arrange
            var exception = new InvalidOperationException("Something or other");
            var server    = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.Transfer(It.IsAny <string>())).Throws(new Exception("Should not have transfered"));

            // act
            bool handled = SubtextApplication.HandleBadConnectionStringException(exception, server.Object);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 8
0
        public void HandleDrepecatedFilePathsException_WithNonDeprecatedPhysicalPathsException_ReturnsFalse()
        {
            // arrange
            var exception   = new Exception();
            var application = new Mock <SubtextApplication>();

            application.Setup(a => a.FinishRequest());

            // act
            bool handled = SubtextApplication.HandleDeprecatedFilePathsException(exception, null, application.Object);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 9
0
        public void StartApplication_AddsHostAdminDirectoryToInvalidPaths_IfHostAdminDirectoryExistsInWrongPlace()
        {
            // arrange
            var app    = new SubtextApplication(null);
            var server = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.MapPath("~/HostAdmin")).Returns(Directory.CreateDirectory("HostAdmin").FullName);

            // act
            app.StartApplication(new SubtextRouteMapper(new RouteCollection(), new Mock <IServiceLocator>().Object),
                                 server.Object);

            // assert
            Assert.AreEqual("~/HostAdmin", app.DeprecatedPhysicalPaths[0]);
        }
Exemplo n.º 10
0
        public void OnApplicationError_WithHttpUnhandledExceptionContainingNoInnerException_Transfers()
        {
            // arrange
            var    app = new SubtextApplication(null);
            string transferLocation = null;
            var    server           = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            app.OnApplicationError(new HttpUnhandledException(), server.Object, new Mock <ILog>().Object, null);

            // assert
            Assert.AreEqual("~/aspx/SystemMessages/error.aspx", transferLocation);
        }
Exemplo n.º 11
0
        public void OnApplicationError_WithUnhandledExceptionAndCustomErrorsEnabled_TransfersToErrorPage()
        {
            // arrange
            string transferLocation = null;
            var    server           = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            SubtextApplication.HandleUnhandledException(new Exception(), server.Object, true /* customErrorEnabled */,
                                                        new Mock <ILog>().Object);

            // assert
            Assert.AreEqual("~/aspx/SystemMessages/error.aspx", transferLocation);
        }
Exemplo n.º 12
0
        public void LogIfCommentException_LogsCommentException()
        {
            // arrange
            var    exception  = new CommentDuplicateException();
            var    log        = new Mock <ILog>();
            string logMessage = null;

            log.Setup(l => l.Info(It.IsAny <string>(), exception)).Callback <object, Exception>(
                (o, e) => logMessage = o.ToString());

            // act
            SubtextApplication.LogIfCommentException(exception, log.Object);

            // assert
            Assert.AreEqual("Comment exception thrown and handled in Global.asax.", logMessage);
        }
Exemplo n.º 13
0
        public void OnApplicationError_WithUnhandledExceptionAndCustomErrorsDisabled_LogsMessage()
        {
            // arrange
            var    log        = new Mock <ILog>();
            string logMessage = null;

            log.Setup(l => l.Error(It.IsAny <object>(), It.IsAny <Exception>())).Callback <object, Exception>(
                (s, e) => logMessage = s.ToString());

            // act
            SubtextApplication.HandleUnhandledException(new Exception(), null, false /* customErrorEnabled */,
                                                        log.Object);

            // assert
            Assert.AreEqual("Unhandled Exception trapped in Global.asax", logMessage);
        }
Exemplo n.º 14
0
        HandleBadConnectionStringException_WithInvalidOperationExceptionMentioningConnectionString_TransfersToBadConnectionStringPage
            ()
        {
            // arrange
            var    exception        = new InvalidOperationException("No ConnectionString Found");
            var    server           = new Mock <HttpServerUtilityBase>();
            string transferLocation = null;

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            bool handled = SubtextApplication.HandleBadConnectionStringException(exception, server.Object);

            // assert
            Assert.IsTrue(handled);
            Assert.AreEqual("~/aspx/SystemMessages/CheckYourConnectionString.aspx", transferLocation);
        }
Exemplo n.º 15
0
        HandleBadConnectionStringException_WithArgumentExceptionContainingInvalidValueForKey_TransfersToBadConnectionStringPage
            ()
        {
            // arrange
            var    exception        = new ArgumentException("Invalid value for key");
            var    server           = new Mock <HttpServerUtilityBase>();
            string transferLocation = null;

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            bool handled = SubtextApplication.HandleBadConnectionStringException(exception, server.Object);

            // assert
            Assert.IsTrue(handled);
            Assert.AreEqual("~/aspx/SystemMessages/CheckYourConnectionString.aspx", transferLocation);
        }
Exemplo n.º 16
0
        public void BeginApplicationRequest_WithOldAdminDirectory_ThrowsDeprecatedFileExistsException()
        {
            // arrange
            var app    = new SubtextApplication(null);
            var server = new Mock <HttpServerUtilityBase>();

            server.Setup(s => s.MapPath("~/Admin")).Returns(Directory.CreateDirectory("Admin").FullName);
            app.StartApplication(new SubtextRouteMapper(new RouteCollection(), new Mock <IServiceLocator>().Object),
                                 server.Object);

            // act, assert
            var exception = UnitTestHelper.AssertThrows <DeprecatedPhysicalPathsException>(() =>
                                                                                           app.BeginApplicationRequest(
                                                                                               new Mock <ILog>().Object));

            Assert.AreEqual("~/Admin", exception.InvalidPhysicalPaths[0]);
        }
Exemplo n.º 17
0
        public void HandleRequestLocationException_IgnoresBlogInactiveExceptionWhenInSystemMessagesDirectory()
        {
            // arrange
            var exception = new BlogInactiveException();
            var response  = new Mock <HttpResponseBase>();

            response.Setup(r => r.Redirect(It.IsAny <string>(), true)).Throws(new Exception("Should not have redirected"));
            var blogRequest = new BlogRequest("", "", new Uri("http://haacked.com/"), false,
                                              RequestLocation.SystemMessages, "/");
            var installManager = new Mock <IInstallationManager>().Object;

            // act
            bool handled = SubtextApplication.HandleRequestLocationException(exception, blogRequest, installManager,
                                                                             response.Object);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 18
0
        HandleSqlException_WithSqlServerCouldNotFindStoredProcedureAndProcNameIsBlog_GetConfig_TransfersToBadConnectionStringPageAndReturnsTrue
            ()
        {
            // arrange

            var    server           = new Mock <HttpServerUtilityBase>();
            string transferLocation = null;

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            bool handled = SubtextApplication.HandleSqlExceptionNumber(
                (int)SqlErrorMessage.CouldNotFindStoredProcedure, "'blog_GetConfig'", server.Object);

            // assert
            Assert.AreEqual("~/aspx/SystemMessages/CheckYourConnectionString.aspx", transferLocation);
            Assert.IsTrue(handled);
        }
Exemplo n.º 19
0
        public void BeginApplicationRequest_LogsThatTheApplicationHasStartedAndSetsLogInitializedTrue()
        {
            // arrange
            var app = new SubtextApplication(null);

            Assert.IsFalse(app.LogInitialized);
            var    log        = new Mock <ILog>();
            string logMessage = null;

            log.Setup(l => l.Info(It.IsAny <string>())).Callback <object>(s => logMessage = s.ToString());

            // act
            app.BeginApplicationRequest(log.Object);

            // assert
            Assert.AreEqual("Subtext Application Started", logMessage);
            Assert.IsTrue(app.LogInitialized);
        }
Exemplo n.º 20
0
        HandleSqlException_WithSqlServerDoesNotExistOrAccessDeniedError_TransfersToBadConnectionStringPageAndReturnsTrue
            ()
        {
            // arrange
            var    server           = new Mock <HttpServerUtilityBase>();
            string transferLocation = null;

            server.Setup(s => s.Transfer(It.IsAny <string>())).Callback <string>(s => transferLocation = s);

            // act
            bool handled =
                SubtextApplication.HandleSqlExceptionNumber((int)SqlErrorMessage.SqlServerDoesNotExistOrAccessDenied, "",
                                                            server.Object);

            // assert
            Assert.AreEqual("~/aspx/SystemMessages/CheckYourConnectionString.aspx", transferLocation);
            Assert.IsTrue(handled);
        }
Exemplo n.º 21
0
        public void StartApplication_AddsLoginFileToInvalidPaths_IfLoginFileExistsInWrongPlace()
        {
            // arrange
            var app    = new SubtextApplication(null);
            var server = new Mock <HttpServerUtilityBase>();

            using (StreamWriter writer = File.CreateText("login.aspx"))
            {
                writer.Write("test");
            }
            server.Setup(s => s.MapPath("~/login.aspx")).Returns(Path.GetFullPath("login.aspx"));

            // act
            app.StartApplication(new SubtextRouteMapper(new RouteCollection(), new Mock <IServiceLocator>().Object),
                                 server.Object);

            // assert
            Assert.AreEqual("~/login.aspx", app.DeprecatedPhysicalPaths[0]);
        }
Exemplo n.º 22
0
        public void HandleRequestLocationException_IgnoresUpgradeLocation()
        {
            // arrange
            var response = new Mock <HttpResponseBase>();

            response.Setup(r => r.Redirect(It.IsAny <string>(), true)).Throws(
                new Exception("Test Failed. Should not have redirected"));
            var blogRequest    = new BlogRequest("", "", new Uri("http://haacked.com/"), false, RequestLocation.Upgrade, "/");
            var installManager = new Mock <IInstallationManager>();

            installManager.Setup(i => i.InstallationActionRequired(It.IsAny <Version>(), It.IsAny <Exception>())).Throws(new InvalidOperationException());

            // act
            bool handled = SubtextApplication.HandleRequestLocationException(new Exception(), blogRequest, installManager.Object,
                                                                             response.Object);

            // assert
            Assert.IsFalse(handled);
        }
Exemplo n.º 23
0
        public void HandleRequestLocationException_WithInstallationActionRequired_RedirectsToInstallDefault()
        {
            // arrange
            var    response         = new Mock <HttpResponseBase>();
            string redirectLocation = null;

            response.Setup(r => r.Redirect(It.IsAny <string>(), true)).Callback <string, bool>(
                (s, endRequest) => redirectLocation = s);
            var blogRequest         = new BlogRequest("", "", new Uri("http://haacked.com/"), false);
            var installationManager = new Mock <IInstallationManager>();

            installationManager.Setup(i => i.InstallationActionRequired(It.IsAny <Version>(), null)).Returns(true);

            // act
            bool handled = SubtextApplication.HandleRequestLocationException(null, blogRequest, installationManager.Object, response.Object);

            // assert
            Assert.AreEqual("~/install/default.aspx", redirectLocation);
            Assert.IsTrue(handled);
        }
Exemplo n.º 24
0
        public void HandleRequestLocationException_HandlesBlogInactiveException()
        {
            // arrange
            var    exception        = new BlogInactiveException();
            var    response         = new Mock <HttpResponseBase>();
            string redirectLocation = null;

            response.Setup(r => r.Redirect(It.IsAny <string>(), true)).Callback <string, bool>(
                (s, endRequest) => redirectLocation = s);
            var blogRequest    = new BlogRequest("", "", new Uri("http://haacked.com/"), false);
            var installManager = new Mock <IInstallationManager>().Object;

            // act
            bool handled = SubtextApplication.HandleRequestLocationException(exception, blogRequest, installManager,
                                                                             response.Object);

            // assert
            Assert.AreEqual("~/SystemMessages/BlogNotActive.aspx", redirectLocation);
            Assert.IsTrue(handled);
        }
Exemplo n.º 25
0
        public void HandleDeprecatedFilePathsException_WithDepecatedPhysicalPathsException_ReturnsFalse()
        {
            // arrange
            var    exception        = new DeprecatedPhysicalPathsException(new[] { "~/Admin" });
            var    server           = new Mock <HttpServerUtilityBase>();
            string transferLocation = null;

            server.Setup(s => s.Execute(It.IsAny <string>(), false)).Callback <string, bool>(
                (s, b) => transferLocation = s);
            var application = new Mock <SubtextApplication>();

            application.Setup(a => a.FinishRequest());

            // act
            bool handled = SubtextApplication.HandleDeprecatedFilePathsException(exception, server.Object,
                                                                                 application.Object);

            // assert
            Assert.AreEqual("~/aspx/SystemMessages/DeprecatedPhysicalPaths.aspx", transferLocation);
            Assert.IsTrue(handled);
        }