Beispiel #1
0
        public void CachesMatchResults()
        {
            // Arrange
            var trigger      = new Mock <IExpirationTrigger>();
            var fileProvider = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css"));

            Mock.Get(fileProvider).Setup(f => f.Watch(It.IsAny <string>())).Returns(trigger.Object);
            var cache = MakeCache();

            Mock.Get(cache).Setup(c => c.Set(
                                      /*key*/ It.IsAny <string>(),
                                      /*value*/ It.IsAny <object>(),
                                      /*options*/ It.IsAny <MemoryCacheEntryOptions>()))
            .Returns(new object())
            .Verifiable();
            var requestPathBase    = PathString.Empty;
            var globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: "**/*.css",
                excludePattern: null);

            // Assert
            Assert.Collection(urlList,
                              url => Assert.Equal("/blank.css", url),
                              url => Assert.Equal("/site.css", url));
            Mock.Get(cache).VerifyAll();
        }
Beispiel #2
0
        public void ReturnsOnlyStaticUrlWhenPatternDoesntFindAnyMatches()
        {
            // Arrange
            var          fileProvider       = MakeFileProvider();
            IMemoryCache cache              = null;
            var          requestPathBase    = PathString.Empty;
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList("/site.css", "**/*.css", excludePattern: null);

            // Assert
            Assert.Collection(urlList, url => Assert.Equal("/site.css", url));
        }
Beispiel #3
0
        public void DedupesStaticUrlAndPatternMatches()
        {
            // Arrange
            var          fileProvider       = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css"));
            IMemoryCache cache              = null;
            var          requestPathBase    = PathString.Empty;
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList("/site.css", "**/*.css", excludePattern: null);

            // Assert
            Assert.Collection(urlList,
                              url => Assert.Equal("/site.css", url),
                              url => Assert.Equal("/blank.css", url));
        }
Beispiel #4
0
        public void OrdersGlobbedMatchResultsCorrectly(string staticUrl, FileNode dirStructure, string[] expectedPaths)
        {
            // Arrange
            var          fileProvider       = MakeFileProvider(dirStructure);
            IMemoryCache cache              = null;
            var          requestPathBase    = PathString.Empty;
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(staticUrl, "**/*.*", excludePattern: null);

            // Assert
            var collectionAssertions = expectedPaths.Select <string, Action <string> >(expected =>
                                                                                       actual => Assert.Equal(expected, actual));

            Assert.Collection(urlList, collectionAssertions.ToArray());
        }
Beispiel #5
0
        public void HandlesCommaSeparatedPatterns(string includePattern, string[] expectedOutput)
        {
            // Arrange
            var          fileProvider       = MakeFileProvider(MakeDirectoryContents("site.css", "blank.js", "site2.txt", "site.js"));
            IMemoryCache cache              = null;
            var          requestPathBase    = PathString.Empty;
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: includePattern,
                excludePattern: null);

            // Assert
            Assert.Equal(expectedOutput, urlList, StringComparer.Ordinal);
        }
Beispiel #6
0
        public void ResolvesMatchedUrlsAgainstPathBase(string pathBase)
        {
            // Arrange
            var          fileProvider       = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css"));
            IMemoryCache cache              = null;
            var          requestPathBase    = new PathString(pathBase);
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: "**/*.css",
                excludePattern: null);

            // Assert
            Assert.Collection(urlList,
                              url => Assert.Equal($"{pathBase}/blank.css", url),
                              url => Assert.Equal($"{pathBase}/site.css", url));
        }
        public void UsesCachedMatchResults()
        {
            // Arrange
            var fileProvider = MakeFileProvider();
            var cache        = MakeCache(new List <string> {
                "/blank.css", "/site.css"
            });
            var requestPathBase    = PathString.Empty;
            var globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: "**/*.css",
                excludePattern: null);

            // Assert
            Assert.Collection(urlList,
                              url => Assert.Equal("/blank.css", url),
                              url => Assert.Equal("/site.css", url));
        }
        public void CachesMatchResults()
        {
            // Arrange
            var trigger      = new Mock <IExpirationTrigger>();
            var fileProvider = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css"));

            Mock.Get(fileProvider).Setup(f => f.Watch(It.IsAny <string>())).Returns(trigger.Object);
            var cache           = MakeCache();
            var cacheSetContext = new Mock <ICacheSetContext>();

            cacheSetContext.Setup(c => c.AddExpirationTrigger(trigger.Object)).Verifiable();
            Mock.Get(cache).Setup(c => c.Set(
                                      /*key*/ It.IsAny <string>(),
                                      /*link*/ It.IsAny <IEntryLink>(),
                                      /*state*/ It.IsAny <object>(),
                                      /*create*/ It.IsAny <Func <ICacheSetContext, object> >()))
            .Returns <string, IEntryLink, object, Func <ICacheSetContext, object> >(
                (key, link, state, create) =>
            {
                cacheSetContext.Setup(c => c.State).Returns(state);
                return(create(cacheSetContext.Object));
            })
            .Verifiable();
            var requestPathBase    = PathString.Empty;
            var globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: "**/*.css",
                excludePattern: null);

            // Assert
            Assert.Collection(urlList,
                              url => Assert.Equal("/blank.css", url),
                              url => Assert.Equal("/site.css", url));
            cacheSetContext.VerifyAll();
            Mock.Get(cache).VerifyAll();
        }
Beispiel #9
0
        public void TrimsLeadingSlashFromPatterns(string leadingSlash)
        {
            // Arrange
            var          fileProvider       = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css"));
            IMemoryCache cache              = null;
            var          requestPathBase    = PathString.Empty;
            var          includePatterns    = new List <string>();
            var          excludePatterns    = new List <string>();
            var          matcher            = MakeMatcher(includePatterns, excludePatterns);
            var          globbingUrlBuilder = new GlobbingUrlBuilder(fileProvider, cache, requestPathBase);

            globbingUrlBuilder.MatcherBuilder = () => matcher;

            // Act
            var urlList = globbingUrlBuilder.BuildUrlList(
                staticUrl: null,
                includePattern: $"{leadingSlash}**/*.css",
                excludePattern: $"{leadingSlash}**/*.min.css");

            // Assert
            Assert.Collection(includePatterns, pattern => Assert.Equal("**/*.css", pattern));
            Assert.Collection(excludePatterns, pattern => Assert.Equal("**/*.min.css", pattern));
        }