public void Exists_NoNodes_ReturnsFalse()
        {
            using (new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType<IResourceResolverStrategy, ResourceResolverStrategy>(new ContainerControlledLifetimeManager());
                ObjectFactory.Resolve<IResourceResolverStrategy>().SetFirst(null);

                var resolver = new ResourceResolver();

                var result = resolver.Exists(new PathDefinition(), "~/Test");
                Assert.IsFalse(result, "Resolver returned true for Exists when for all nodes Exists is false.");
            }
        }
        public void Exists_SecondNodeExists_ReturnsTrue()
        {
            using (new ObjectFactoryContainerRegion())
            {
                ObjectFactory.Container.RegisterType<IResourceResolverStrategy, ResourceResolverStrategy>(new ContainerControlledLifetimeManager());

                var firstNode = new DummyResourceResolverNode();
                firstNode.CurrentExistsMock = (pathDefinition, virtualPath) => false;

                var secondNode = new DummyResourceResolverNode();
                secondNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;

                ObjectFactory.Resolve<IResourceResolverStrategy>()
                    .SetFirst(firstNode)
                    .SetNext(secondNode);

                var resolver = new ResourceResolver();
                var result = resolver.Exists(new PathDefinition(), "~/Test");

                Assert.IsTrue(result, "Resolver returned false for Exists while there is one node for which the resource exits.");
            }
        }
        public void Open_TwoResolvers_ReturnsFirstResolverStream()
        {
            //Arrange
            using (new ObjectFactoryContainerRegion())
            {
                using (var ms1 = new MemoryStream())
                {
                    using (var ms2 = new MemoryStream())
                    {
                        ObjectFactory.Container.RegisterType<IResourceResolverStrategy, ResourceResolverStrategy>(new ContainerControlledLifetimeManager());

                        var firstNode = new DummyResourceResolverNode();
                        firstNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;
                        firstNode.CurrentOpenMock = (pathDefinition, virtualPath) => ms1;

                        var secondNode = new DummyResourceResolverNode();
                        secondNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;
                        secondNode.CurrentOpenMock = (pathDefinition, virtualPath) => ms2;

                        ObjectFactory.Resolve<IResourceResolverStrategy>()
                            .SetFirst(firstNode)
                            .SetNext(secondNode);

                        //Act
                        var resolver = new ResourceResolver();
                        var result = resolver.Open(new PathDefinition(), "~/Test");

                        //Assert
                        Assert.AreNotSame(ms2, result, "The stream for the second node was returned while the first one was expected.");
                        Assert.AreSame(ms1, result, "The stream for the first node was not returned.");
                    }
                }
            }
        }
        public void GetCacheDependency_ReturnsStrategysGetCacheDependncyResult()
        {
            using (new ObjectFactoryContainerRegion())
            {
                //Arrange
                ObjectFactory.Container.RegisterType<IResourceResolverStrategy, DummyResolverStrategy>(new ContainerControlledLifetimeManager());
                var strategy = (DummyResolverStrategy)ObjectFactory.Resolve<IResourceResolverStrategy>();

                var strategyCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
                strategy.GetCacheDependencyMock = (definition, virtualPath, virtualPathDependencies, utcStart) => strategyCacheDependency;

                //Act
                var resolver = new ResourceResolver();
                var result = resolver.GetCacheDependency(new PathDefinition(), "~/Test", null, DateTime.UtcNow);

                //Assert
                Assert.AreSame(strategyCacheDependency, result, "GetCacheDependency did not return the dependency that was provided by the resource resolver strategy.");
            }
        }