public void CreateInstanceUsesRegisteredFactoriesForExistence()
        {
            // Arrange
            var path = "~/index.cshtml";
            var factory1 = new Mock<IVirtualPathFactory>();
            factory1.Setup(c => c.Exists(path)).Returns(false).Verifiable();
            var factory2 = new Mock<IVirtualPathFactory>();
            factory2.Setup(c => c.Exists(path)).Returns(true).Verifiable();
            var factory3 = new Mock<IVirtualPathFactory>();
            factory3.Setup(c => c.Exists(path)).Throws(new Exception("This factory should not be called since the page has already been found in 2"));
            var defaultFactory = new Mock<IVirtualPathFactory>();
            defaultFactory.Setup(c => c.Exists(path)).Throws(new Exception("This factory should not be called since it always called last"));

            var vpfm = new VirtualPathFactoryManager(defaultFactory.Object);
            vpfm.RegisterVirtualPathFactoryInternal(factory1.Object);
            vpfm.RegisterVirtualPathFactoryInternal(factory2.Object);
            vpfm.RegisterVirtualPathFactoryInternal(factory3.Object);

            // Act
            var result = vpfm.Exists(path);

            // Assert
            Assert.True(result);

            factory1.Verify();
            factory2.Verify();
        }
Esempio n. 2
0
        public void CreateInstanceUsesRegisteredFactoriesForExistence()
        {
            // Arrange
            var path     = "~/index.cshtml";
            var factory1 = new Mock <IVirtualPathFactory>();

            factory1.Setup(c => c.Exists(path)).Returns(false).Verifiable();
            var factory2 = new Mock <IVirtualPathFactory>();

            factory2.Setup(c => c.Exists(path)).Returns(true).Verifiable();
            var factory3 = new Mock <IVirtualPathFactory>();

            factory3.Setup(c => c.Exists(path)).Throws(new Exception("This factory should not be called since the page has already been found in 2"));
            var defaultFactory = new Mock <IVirtualPathFactory>();

            defaultFactory.Setup(c => c.Exists(path)).Throws(new Exception("This factory should not be called since it always called last"));

            var vpfm = new VirtualPathFactoryManager(defaultFactory.Object);

            vpfm.RegisterVirtualPathFactoryInternal(factory1.Object);
            vpfm.RegisterVirtualPathFactoryInternal(factory2.Object);
            vpfm.RegisterVirtualPathFactoryInternal(factory3.Object);

            // Act
            var result = vpfm.Exists(path);

            // Assert
            Assert.True(result);

            factory1.Verify();
            factory2.Verify();
        }