コード例 #1
0
        public async Task GetLibraryAsync_InvalidLibraryId()
        {
            CdnjsCatalog sut = SetupCatalog();

            await Assert.ThrowsExceptionAsync <InvalidLibraryException>(async() =>
                                                                        await sut.GetLibraryAsync("invalid_id", "invalid_version", CancellationToken.None));
        }
コード例 #2
0
        public void ConvertToAssets_ValidAsset()
        {
            CdnjsCatalog sut  = SetupCatalog();
            string       json = @"{""name"":""jquery"",""filename"":""jquery.min.js"",""version"":""3.3.1"",""description"":""JavaScript library for DOM operations"",
""homepage"":""http://jquery.com/"",""keywords"":[""jquery"",""library"",""ajax"",""framework"",""toolkit"",""popular""],""namespace"":""jQuery"",
""repository"":{""type"":""git"",""url"":""https://github.com/jquery/jquery.git""},""license"":""MIT"",
""author"":{""name"":""jQuery Foundation and other contributors"",""url"":""https://github.com/jquery/jquery/blob/master/AUTHORS.txt""},
""autoupdate"":{""type"":""npm"",""target"":""jquery""},
""assets"":[{""version"":""3.3.1"",""files"":[""core.js"",""jquery.js"",""jquery.min.js"",""jquery.min.map"",""jquery.slim.js"",""jquery.slim.min.js"",""jquery.slim.min.map""]}]}";

            List <Asset> list = sut.ConvertToAssets(json);

            Assert.AreEqual(1, list.Count());
            Asset asset = list[0];

            Assert.AreEqual("3.3.1", asset.Version);

            string[] expectedFiles = new string[] { "core.js", "jquery.js", "jquery.min.js", "jquery.min.map", "jquery.slim.js", "jquery.slim.min.js", "jquery.slim.min.map" };
            Assert.AreEqual(7, asset.Files.Count());
            foreach (string file in expectedFiles)
            {
                Assert.IsTrue(asset.Files.Contains(file));
            }

            Assert.AreEqual("jquery.min.js", asset.DefaultFile);
        }
コード例 #3
0
        public void ConvertToLibraryGroup_InvalidJsonCatalog(string json)
        {
            CdnjsCatalog sut = SetupCatalog();

            IEnumerable <CdnjsLibraryGroup> libraryGroup = sut.ConvertToLibraryGroups(json);

            Assert.IsNull(libraryGroup);
        }
コード例 #4
0
        public void ConvertToLibraryGroup_InvalidJsonCatalog(string json)
        {
            CdnjsCatalog cdnjsCatalog = _catalog as CdnjsCatalog;

            IEnumerable <CdnjsLibraryGroup> libraryGroup = cdnjsCatalog.ConvertToLibraryGroups(json);

            Assert.IsNull(libraryGroup);
        }
コード例 #5
0
        public async Task SearchAsync_NullString()
        {
            CdnjsCatalog sut = Initialize();

            IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(null, 1, CancellationToken.None);

            Assert.AreEqual(1, absolute.Count);
        }
コード例 #6
0
        public async Task SearchAsync_NoHits()
        {
            CdnjsCatalog sut = SetupCatalog();

            IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(@"*9)_-", 1, CancellationToken.None);

            Assert.AreEqual(0, absolute.Count);
        }
コード例 #7
0
        public void ConvertToAssets_InvalidAsset()
        {
            string       json = "abcd";
            CdnjsCatalog sut  = SetupCatalog();

            List <Asset> list = sut.ConvertToAssets(json);

            Assert.IsNull(list);
        }
コード例 #8
0
        public void ConvertToAssets_InvalidAsset()
        {
            string json = "abcd";

            CdnjsCatalog cdnjsCatalog = _catalog as CdnjsCatalog;

            List <Asset> list = cdnjsCatalog.ConvertToAssets(json);

            Assert.IsNull(list);
        }
コード例 #9
0
        public async Task GetLatestVersion_LatestExist()
        {
            CdnjsCatalog sut = SetupCatalog();

            const string libraryName     = "sampleLibrary";
            const string expectedVersion = "3.1.4";
            string       result          = await sut.GetLatestVersion(libraryName, false, CancellationToken.None);

            Assert.AreEqual(expectedVersion, result);
        }
コード例 #10
0
        public async Task GetLatestVersion_PreRelease()
        {
            CdnjsCatalog sut = SetupCatalog();

            const string libraryName = "sampleLibrary";
            const string oldVersion  = "4.0.0-beta.2";
            string       result      = await sut.GetLatestVersion(libraryName, true, CancellationToken.None);

            Assert.AreEqual(oldVersion, result);
        }
コード例 #11
0
        public async Task SearchAsync_MultipleMatches()
        {
            CdnjsCatalog sut = SetupCatalog();

            IReadOnlyList <ILibraryGroup> result = await sut.SearchAsync(term : "test", 5, CancellationToken.None);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("test-library", result.First().DisplayName);
            Assert.AreEqual("test-library2", result.Last().DisplayName);
        }
コード例 #12
0
        public async Task GetLatestVersion_PreRelease()
        {
            CdnjsCatalog sut = Initialize();

            // "[email protected]"
            const string libraryName = "sampleLibrary";
            const string oldVersion  = "4.0.0-beta.1";
            string       result      = await sut.GetLatestVersion(libraryName, true, CancellationToken.None);

            Assert.AreEqual(oldVersion, result);
        }
コード例 #13
0
        public async Task GetLibraryAsync_Success()
        {
            CdnjsCatalog sut = SetupCatalog();

            ILibrary library = await sut.GetLibraryAsync("sampleLibrary", "3.1.4", CancellationToken.None);

            Assert.IsNotNull(library);
            Assert.AreEqual("sampleLibrary", library.Name);
            Assert.AreEqual("3.1.4", library.Version);
            Assert.IsNotNull(library.Files);
        }
コード例 #14
0
        public async Task GetLibraryAsync_WebRequestFailsAndNoCachedMetadata_ThrowsInvalidLibraryId()
        {
            var fakeCacheService = new Mock <ICacheService>();

            fakeCacheService.Setup(x => x.GetContentsFromUriWithCacheFallbackAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Throws(new ResourceDownloadException("Cache download failed."));
            CdnjsCatalog sut = SetupCatalog(fakeCacheService.Object);

            await Assert.ThrowsExceptionAsync <InvalidLibraryException>(async() =>
                                                                        await sut.GetLibraryAsync("invalid_id", "invalid_version", CancellationToken.None));
        }
コード例 #15
0
        public async Task SearchAsync_CacheDownloadFailsWhenNoCacheFileExists_FindsNoMatches()
        {
            var fakeCacheService = new Mock <ICacheService>();

            fakeCacheService.Setup(x => x.GetContentsFromUriWithCacheFallbackAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Throws(new ResourceDownloadException("Cache download failed."));
            CdnjsCatalog sut = SetupCatalog(fakeCacheService.Object);

            IReadOnlyList <ILibraryGroup> result = await sut.SearchAsync("test", 5, CancellationToken.None);

            Assert.AreEqual(0, result.Count);
        }
コード例 #16
0
        public async Task GetLibraryCompletionSetAsync_Names()
        {
            CdnjsCatalog sut = SetupCatalog();

            CompletionSet result = await sut.GetLibraryCompletionSetAsync("test", 0);

            Assert.AreEqual(0, result.Start);
            Assert.AreEqual(4, result.Length);
            Assert.AreEqual(2, result.Completions.Count());
            Assert.AreEqual("test-library", result.Completions.First().DisplayText);
            Assert.AreEqual("[email protected]", result.Completions.First().InsertionText);
        }
コード例 #17
0
        public async Task GetLibraryCompletionSetAsync_Versions()
        {
            CdnjsCatalog sut = SetupCatalog();

            CompletionSet result = await sut.GetLibraryCompletionSetAsync("sampleLibrary@", 14);

            Assert.AreEqual("sampleLibrary@".Length, result.Start);
            Assert.AreEqual(0, result.Length);
            Assert.AreEqual(5, result.Completions.Count());
            Assert.AreEqual("2.0.0", result.Completions.Last().DisplayText);
            Assert.AreEqual("[email protected]", result.Completions.Last().InsertionText);
        }
コード例 #18
0
        public void ConvertToLibraryGroup_ValidJsonCatalog()
        {
            CdnjsCatalog sut  = SetupCatalog();
            string       json = @"{""results"":[{""name"":""1140"",""latest"":""https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.min.css"",
""description"":""The 1140 grid fits perfectly into a 1280 monitor. On smaller monitors it becomes fluid and adapts to the width of the browser.""
,""version"":""2.0""}],""total"":1}";

            IEnumerable <CdnjsLibraryGroup> libraryGroup = sut.ConvertToLibraryGroups(json);

            Assert.AreEqual(1, libraryGroup.Count());
            CdnjsLibraryGroup library = libraryGroup.First();

            Assert.AreEqual("1140", library.DisplayName);
            Assert.AreEqual("The 1140 grid fits perfectly into a 1280 monitor. On smaller monitors it becomes fluid and adapts to the width of the browser.", library.Description);
            Assert.AreEqual("2.0", library.Version);
        }
コード例 #19
0
        public async Task SearchAsync_Success_SingleMatch(string searchTerm, string expectedId)
        {
            CdnjsCatalog sut = SetupCatalog();

            IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(searchTerm, 2, CancellationToken.None);

            Assert.AreEqual(1, absolute.Count);

            IEnumerable <string> versions = await absolute[0].GetLibraryVersions(CancellationToken.None);

            Assert.IsTrue(versions.Any());

            ILibrary library = await sut.GetLibraryAsync(absolute[0].DisplayName, versions.First(), CancellationToken.None);

            Assert.IsTrue(library.Files.Count > 0);
            Assert.AreEqual(expectedId, library.Name);
            Assert.AreEqual(1, library.Files.Count(f => f.Value));
            Assert.IsNotNull(library.Name);
            Assert.IsNotNull(library.Version);
            Assert.AreEqual(CdnjsProvider.IdText, library.ProviderId);
        }