Example #1
0
        public static bool HandleDeprecatedFilePathsException(Exception exception, HttpServerUtilityBase server,
                                                              SubtextApplication application)
        {
            var depecratedException = exception as DeprecatedPhysicalPathsException;

            if (depecratedException != null)
            {
                server.Execute(DeprecatedPhysicalPathsPage, false);
                server.ClearError();
                application.FinishRequest();
                return(true);
            }

            return(false);
        }
        public void BeginApplicationRequest_WithOldAdminDirectory_ThrowsDeprecatedFileExistsException()
        {
            // arrange
            var app = new SubtextApplication();
            var server = new Mock<HttpServerUtilityBase>();
            server.Setup(s => s.MapPath("~/Admin")).Returns(Directory.CreateDirectory("Admin").FullName);
            app.StartApplication(new SubtextRouteMapper(new RouteCollection(), new Mock<IDependencyResolver>().Object),
                                 server.Object);

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

            Assert.AreEqual("~/Admin", exception.InvalidPhysicalPaths[0]);
        }
        public void BeginApplicationRequest_LogsThatTheApplicationHasStartedAndSetsLogInitializedTrue()
        {
            // arrange
            var app = new SubtextApplication();
            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);
        }
        public void StartApplication_SetsLogInitializedToFalse()
        {
            // arrange
            var app = new SubtextApplication();
            var server = new Mock<HttpServerUtilityBase>();

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

            // assert
            Assert.IsFalse(app.LogInitialized);
        }
        public void StartApplication_AddsLoginFileToInvalidPaths_IfLoginFileExistsInWrongPlace()
        {
            // arrange
            var app = new SubtextApplication();
            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<IDependencyResolver>().Object),
                                 server.Object);

            // assert
            Assert.AreEqual("~/login.aspx", app.DeprecatedPhysicalPaths[0]);
        }
        public void StartApplication_AddsHostAdminDirectoryToInvalidPaths_IfHostAdminDirectoryExistsInWrongPlace()
        {
            // arrange
            var app = new SubtextApplication();
            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<IDependencyResolver>().Object),
                                 server.Object);

            // assert
            Assert.AreEqual("~/HostAdmin", app.DeprecatedPhysicalPaths[0]);
        }
        public void OnApplicationError_WithHttpUnhandledExceptionContainingNoInnerException_Transfers()
        {
            // arrange
            var app = new SubtextApplication();
            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);
        }
Example #8
0
        public static bool HandleDeprecatedFilePathsException(Exception exception, HttpServerUtilityBase server,
                                                              SubtextApplication application)
        {
            var depecratedException = exception as DeprecatedPhysicalPathsException;
            if (depecratedException != null)
            {
                server.Execute(DeprecatedPhysicalPathsPage, false);
                server.ClearError();
                application.FinishRequest();
                return true;
            }

            return false;
        }