public void WebFormViewEngineSetsViewPageActivator() {
            // Arrange
            Mock<IViewPageActivator> viewPageActivator = new Mock<IViewPageActivator>();
            TestableWebFormViewEngine viewEngine = new TestableWebFormViewEngine(viewPageActivator.Object);

            //Act & Assert
            Assert.AreEqual(viewPageActivator.Object, viewEngine.ViewPageActivator);
        }
        public void CreatePartialViewCreatesWebFormView() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Act
            WebFormView result = (WebFormView)engine.CreatePartialView("partial path");

            // Assert
            Assert.AreEqual("partial path", result.ViewPath);
            Assert.AreEqual(String.Empty, result.MasterPath);
        }
        public void CreateViewCreatesWebFormView() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Act
            WebFormView result = (WebFormView)engine.CreateView("view path", "master path");

            // Assert
            Assert.AreEqual("view path", result.ViewPath);
            Assert.AreEqual("master path", result.MasterPath);
        }
        public void BuildManagerProperty() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            MockBuildManager buildManagerMock = new MockBuildManager(null, null, null);

            // Act
            engine.BuildManager = buildManagerMock;

            // Assert
            Assert.AreEqual(engine.BuildManager, buildManagerMock);
        }
        public void CreateView_PassesViewPageActivator() {
            // Arrange
            Mock<IViewPageActivator> viewPageActivator = new Mock<IViewPageActivator>();
            TestableWebFormViewEngine viewEngine = new TestableWebFormViewEngine(viewPageActivator.Object);

            // Act
            WebFormView result = (WebFormView)viewEngine.CreateView("partial path", "master path");

            // Assert
            Assert.AreEqual(viewEngine.ViewPageActivator, result._viewPageActivator);
        }
        public void FileExistsReturnsFalseWhenBuildManagerReturnsNull() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            MockBuildManager buildManagerMock = new MockBuildManager("some path", typeof(object), null);
            engine.BuildManager = buildManagerMock;

            // Act
            bool notFoundResult = engine.PublicFileExists(null, "some path");

            // Assert
            Assert.IsFalse(notFoundResult);
        }
        public void FileExistsReturnsFalseWhenBuildManagerThrows404() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            object instanceResult = new object();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpException(404, "HTTP message Not Found"));
            engine.BuildManager = buildManagerMock;

            // Act
            bool notFoundResult = engine.PublicFileExists(null, "some other path");

            // Assert
            Assert.IsFalse(notFoundResult);
        }
        public void MasterLocationFormatsProperty() {
            // Arrange
            string[] expected = new string[] {
                "~/Views/{1}/{0}.master",
                "~/Views/Shared/{0}.master"
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            CollectionAssert.AreEqual(expected, engine.MasterLocationFormats);
        }
        public void FileExistsReturnsTrueForExistingPath() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            object instanceResult = new object();
            MockBuildManager buildManagerMock = new MockBuildManager("some path", typeof(object), instanceResult);
            engine.BuildManager = buildManagerMock;

            // Act
            bool foundResult = engine.PublicFileExists(null, "some path");

            // Assert
            Assert.IsTrue(foundResult);
        }
Esempio n. 10
0
        public void FileExistsThrowsWhenBuildManagerThrowsNon404()
        {
            // Arrange
            TestableWebFormViewEngine engine  = new TestableWebFormViewEngine();
            object           instanceResult   = new object();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpException(123, "HTTP random message"));

            engine.BuildManager = buildManagerMock;

            // Act & Assert
            ExceptionHelper.ExpectHttpException(
                () => engine.PublicFileExists(null, "some other path"),
                "HTTP random message",
                123);
        }
Esempio n. 11
0
        public void AreaViewLocationFormatsProperty()
        {
            // Arrange
            string[] expected = new string[] {
                "~/Areas/{2}/Views/{1}/{0}.aspx",
                "~/Areas/{2}/Views/{1}/{0}.ascx",
                "~/Areas/{2}/Views/Shared/{0}.aspx",
                "~/Areas/{2}/Views/Shared/{0}.ascx",
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            CollectionAssert.AreEqual(expected, engine.AreaViewLocationFormats);
        }
Esempio n. 12
0
        public void FileExistsReturnsFalseWhenBuildManagerThrows404AndViewFileDoesNotExist()
        {
            // Arrange
            TestableWebFormViewEngine engine  = new TestableWebFormViewEngine();
            object           instanceResult   = new object();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpException(404, "HTTP message Not Found"));

            engine.BuildManager = buildManagerMock;
            engine.PublicVirtualPathProvider = new Mock <VirtualPathProvider>().Object;

            // Act
            bool notFoundResult = engine.PublicFileExists(null, "some other path");

            // Assert
            Assert.IsFalse(notFoundResult);
        }
        public void FileExtensionsProperty()
        {
            // Arrange
            string[] expected = new string[]
            {
                "aspx",
                "ascx",
                "master",
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.Equal(expected, engine.FileExtensions);
        }
        public void ViewLocationFormatsProperty()
        {
            // Arrange
            string[] expected = new string[]
            {
                "~/Views/{1}/{0}.aspx",
                "~/Views/{1}/{0}.ascx",
                "~/Views/Shared/{0}.aspx",
                "~/Views/Shared/{0}.ascx"
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.Equal(expected, engine.ViewLocationFormats);
        }
Esempio n. 15
0
        public void FileExistsThrowsWhenBuildManagerThrows404ButViewFileExists()
        {
            // Arrange
            Mock <VirtualPathProvider> mockVpp = new Mock <VirtualPathProvider>();

            mockVpp.Expect(o => o.FileExists("some path")).Returns(true);

            TestableWebFormViewEngine engine           = new TestableWebFormViewEngine();
            MockBuildManager          buildManagerMock = new MockBuildManager(new HttpException(404, "HTTP message Not Found"));

            engine.BuildManager = buildManagerMock;
            engine.PublicVirtualPathProvider = mockVpp.Object;

            // Act & assert
            ExceptionHelper.ExpectHttpException(
                delegate {
                engine.PublicFileExists(null, "some path");
            }, "HTTP message Not Found", 404);
        }
        public void FileExtensionsProperty()
        {
            // Arrange
            string[] expected = new string[]
            {
                "aspx",
                "ascx",
                "master",
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.Equal(expected, engine.FileExtensions);
        }
        public void MasterLocationFormatsProperty() {
            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.AreEqual(2, engine.MasterLocationFormats.Length);
            Assert.AreEqual("~/Views/{1}/{0}.master", engine.MasterLocationFormats[0]);
            Assert.AreEqual("~/Views/Shared/{0}.master", engine.MasterLocationFormats[1]);
        }
        public void AreaViewLocationFormatsProperty()
        {
            // Arrange
            string[] expected = new string[]
            {
                "~/Areas/{2}/Views/{1}/{0}.aspx",
                "~/Areas/{2}/Views/{1}/{0}.ascx",
                "~/Areas/{2}/Views/Shared/{0}.aspx",
                "~/Areas/{2}/Views/Shared/{0}.ascx",
            };

            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.Equal(expected, engine.AreaViewLocationFormats);
        }
        public void ViewLocationFormatsProperty() {
            // Act
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();

            // Assert
            Assert.AreEqual(4, engine.ViewLocationFormats.Length);
            Assert.AreEqual("~/Views/{1}/{0}.aspx", engine.ViewLocationFormats[0]);
            Assert.AreEqual("~/Views/{1}/{0}.ascx", engine.ViewLocationFormats[1]);
            Assert.AreEqual("~/Views/Shared/{0}.aspx", engine.ViewLocationFormats[2]);
            Assert.AreEqual("~/Views/Shared/{0}.ascx", engine.ViewLocationFormats[3]);
        }
        public void FileExistsThrowsWhenBuildManagerThrowsHttpParseException() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpParseException());
            engine.BuildManager = buildManagerMock;

            // Act & assert
            ExceptionHelper.ExpectException<HttpParseException>(
                delegate {
                    engine.PublicFileExists(null, "some path");
                });
        }
        public void FileExistsThrowsWhenBuildManagerThrowsNon404() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            object instanceResult = new object();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpException(123, "HTTP random message"));
            engine.BuildManager = buildManagerMock;

            // Act & Assert
            ExceptionHelper.ExpectHttpException(
                () => engine.PublicFileExists(null, "some other path"),
                "HTTP random message",
                123);
        }
        public void FileExistsThrowsWhenBuildManagerThrowsNonHttpException() {
            // Arrange
            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            MockBuildManager buildManagerMock = new MockBuildManager(new InvalidOperationException("Some exception message."));
            engine.BuildManager = buildManagerMock;

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    engine.PublicFileExists(null, "some path");
                }, "Some exception message.");
        }
        public void FileExistsThrowsWhenBuildManagerThrows404ButViewFileExists() {
            // Arrange
            Mock<VirtualPathProvider> mockVpp = new Mock<VirtualPathProvider>();
            mockVpp.Expect(o => o.FileExists("some path")).Returns(true);

            TestableWebFormViewEngine engine = new TestableWebFormViewEngine();
            MockBuildManager buildManagerMock = new MockBuildManager(new HttpException(404, "HTTP message Not Found"));
            engine.BuildManager = buildManagerMock;
            engine.PublicVirtualPathProvider = mockVpp.Object;

            // Act & assert
            ExceptionHelper.ExpectHttpException(
                delegate {
                    engine.PublicFileExists(null, "some path");
                }, "HTTP message Not Found", 404);
        }