コード例 #1
0
        public void GetCacheDependency_ReturnsFirstNodesCacheDependency()
        {
            var strategy = new ResourceResolverStrategy();

            var nodeCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
            var node = new DummyResourceResolverNode();
            strategy.SetFirst(node);

            node.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcStart) => nodeCacheDependency;
            var resultCacheDependency = strategy.GetCacheDependency(new PathDefinition(), "~/Test", null, DateTime.UtcNow);

            Assert.AreSame(nodeCacheDependency, resultCacheDependency, "GetCacheDependency did not return the instance that is provided by the node in the strategy.");
        }
コード例 #2
0
        public void GetCacheDependency_NoCurrentDependencyCurrentExistsFalse_ReturnsNextCacheDependency()
        {
            var currentNode = new DummyResourceResolverNode();
            var nextNode = new DummyResourceResolverNode();

            currentNode.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcDate) => null;
            currentNode.CurrentExistsMock = (pathDefinition, virtualPath) => false;

            var nextCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
            nextNode.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcDate) => nextCacheDependency;
            nextNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;

            currentNode.SetNext(nextNode);

            var result = currentNode.GetCacheDependency(new PathDefinition(), "~/Test", null, DateTime.UtcNow);
            Assert.IsNotInstanceOfType(result, typeof(AggregateCacheDependency));

            Assert.AreSame(nextCacheDependency, result, "The returned cache dependency is not that of the second node.");
        }
コード例 #3
0
        public void Open_CurrentExistsFalse_ReturnsNextOpenResult()
        {
            var currentNode = new DummyResourceResolverNode();
            var nextNode = new DummyResourceResolverNode();

            currentNode.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcDate) => null;
            var currentStream = new MemoryStream();
            currentNode.CurrentOpenMock = (pathDefinition, virtualPath) => currentStream;
            currentNode.CurrentExistsMock = (pathDefinition, virtualPath) => false;

            var nextCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
            var nextStream = new MemoryStream();
            nextNode.CurrentOpenMock = (pathDefinition, virtualPath) => nextStream;
            nextNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;

            currentNode.SetNext(nextNode);

            var result = currentNode.Open(new PathDefinition(), "~/Test");
            Assert.AreSame(nextStream, result, "The returned stream is not that of the second node.");
        }
コード例 #4
0
        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.");
            }
        }
コード例 #5
0
        public void GetCacheDependency_HasCurrentDependencyCurrentExistsFalse_AggregatesCurrentCacheDependencyWithNext()
        {
            var currentNode = new DummyResourceResolverNode();
            var nextNode = new DummyResourceResolverNode();

            var currentCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
            currentNode.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcDate) => currentCacheDependency;
            currentNode.CurrentExistsMock = (pathDefinition, virtualPath) => false;

            var nextCacheDependency = new CacheDependency(Directory.GetCurrentDirectory());
            nextNode.GetCurrentCacheDependencyMock = (pathDefinition, virtualPath, virtualPathDependencies, utcDate) => nextCacheDependency;
            nextNode.CurrentExistsMock = (pathDefinition, virtualPath) => true;

            currentNode.SetNext(nextNode);

            var result = currentNode.GetCacheDependency(new PathDefinition(), "~/Test", null, DateTime.UtcNow);
            Assert.IsInstanceOfType(result, typeof(AggregateCacheDependency), "Resulting cache dependency is not aggregated.");

            var dependencies = this.GetAggregatedDependencies((AggregateCacheDependency)result);

            Assert.AreEqual(2, dependencies.Count);
            Assert.IsTrue(dependencies.Contains(currentCacheDependency), "The resulting aggregated cache dependency does not contain the dependency of the first node.");
            Assert.IsTrue(dependencies.Contains(nextCacheDependency), "The resulting aggregated cache dependency does not contain the dependency of the second node.");
        }
コード例 #6
0
        public void Open_TwoResolvers_ReturnsFirstResolverStream()
        {
            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);

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

                        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.");
                    }
                }
            }
        }