public async Task GetLibraryCompletionSetAsync_ReturnsCompletionWithLatestVersion() { //Arrange var packageSearch = new Mock <INpmPackageSearch>(); var infoFactory = new Mock <INpmPackageInfoFactory>(); var testPkgInfo = new NpmPackageInfo(name: "testPkg", description: "description", latestVersion: "1.2.3"); var packages = new List <NpmPackageInfo>() { testPkgInfo }; packageSearch.Setup(p => p.GetPackageNamesAsync(It.Is <string>(s => string.Equals(s, "testPkg")), It.IsAny <CancellationToken>())) .Returns(Task.FromResult((IEnumerable <NpmPackageInfo>)packages)); infoFactory.Setup(p => p.GetPackageInfoAsync(It.Is <string>(s => string.Equals(s, "testPkg")), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(testPkgInfo)); UnpkgCatalog sut = SetupCatalog(packageSearch: packageSearch.Object, infoFactory: infoFactory.Object); //Act CompletionSet result = await sut.GetLibraryCompletionSetAsync("testPkg", 7); //Assert Assert.AreEqual(1, result.Completions.Count()); Assert.AreEqual("testPkg", result.Completions.First().DisplayText); Assert.AreEqual("[email protected]", result.Completions.First().InsertionText); }
public async Task SearchAsync_NullString() { UnpkgCatalog sut = SetupCatalog(); IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(null, 1, CancellationToken.None); Assert.AreEqual(0, absolute.Count); }
public async Task SearchAsync_EmptyString_DoesNotPerformSearch() { UnpkgCatalog sut = SetupCatalog(); IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync("", 1, CancellationToken.None); Assert.AreEqual(0, absolute.Count); }
public async Task GetLibraryCompletionSetAsync_ScopedPackageNameisSingleAt_ReturnsNoCompletions() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("@", 1); Assert.AreEqual(0, result.Start); Assert.AreEqual(1, result.Length); Assert.AreEqual(0, result.Completions.Count()); Assert.AreEqual(CompletionSortOrder.AsSpecified, result.CompletionType); }
public async Task GetLibraryAsync_Success() { Mocks.WebRequestHandler handler = new Mocks.WebRequestHandler().SetupFiles("[email protected]"); UnpkgCatalog sut = SetupCatalog(handler); ILibrary library = await sut.GetLibraryAsync("fakeLib", "1.0.0", CancellationToken.None); Assert.IsNotNull(library); Assert.AreEqual("fakeLib", library.Name); Assert.AreEqual("1.0.0", library.Version); }
[Ignore] // TODO: GetLatestVersion currently doesn't distinguish stable and pre-release versions public async Task GetLatestVersion_PreRelease() { const string libraryName = "fakeLibrary"; Mocks.WebRequestHandler handler = new Mocks.WebRequestHandler().SetupVersions("fakeLibrary"); UnpkgCatalog sut = SetupCatalog(handler); string result = await sut.GetLatestVersion(libraryName, true, CancellationToken.None); Assert.AreEqual("2.0.0-beta", result); }
public async Task SearchAsync_NoHits() { // The search service is surprisingly flexible for finding full-text matches, so this // gibberish string was determined manually. string searchTerm = "*9(_-zv_"; UnpkgCatalog sut = SetupCatalog(); IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(searchTerm, 1, CancellationToken.None); Assert.AreEqual(0, absolute.Count); }
public async Task GetLibraryCompletionSetAsync_EmptyString() { UnpkgCatalog sut = SetupCatalog(); CancellationToken token = CancellationToken.None; CompletionSet result = await sut.GetLibraryCompletionSetAsync(string.Empty, 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(0, result.Length); Assert.AreEqual(0, result.Completions.Count()); }
public async Task GetLatestVersion_WebResponseFailedButNoCachedFile_ReturnsNull() { var fakeCache = new Mock <ICacheService>(); fakeCache.SetupBlockRequests(); UnpkgCatalog sut = SetupCatalog(fakeCache.Object); string result = await sut.GetLatestVersion("fakeLibrary", false, CancellationToken.None); Assert.IsNull(result); }
public async Task GetLibraryCompletionSetAsync_ScopesWithNameAndVersions_CursorInNameSubstring() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("@types/[email protected]", 8); Assert.AreEqual(0, result.Start); Assert.AreEqual(17, result.Length); Assert.AreEqual(1, result.Completions.Count()); Assert.IsTrue(result.Completions.First().InsertionText.StartsWith("@types/node")); }
public async Task GetLibraryCompletionSetAsync_ScopesWithNameAndTrailingAt_CursorAtName() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("@types/react@", 6); Assert.AreEqual(0, result.Start); Assert.AreEqual(13, result.Length); Assert.IsTrue(result.Completions.Count() > 0); Assert.IsTrue(result.Completions.First().InsertionText.StartsWith("@types/react")); Assert.AreEqual(CompletionSortOrder.AsSpecified, result.CompletionType); }
public async Task GetLatestVersion_LatestExist() { const string libraryName = "fakeLibrary"; var fakeCache = new Mock <ICacheService>(); fakeCache.SetupPackageVersions(libraryName); UnpkgCatalog sut = SetupCatalog(fakeCache.Object); string result = await sut.GetLatestVersion(libraryName, false, CancellationToken.None); Assert.AreEqual("1.0.0", result); }
public async Task GetLibraryCompletionSetAsync_Names() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("jquery", 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(6, result.Length); Assert.AreEqual(100, result.Completions.Count()); Assert.AreEqual("jquery", result.Completions.First().DisplayText); Assert.IsTrue(result.Completions.First().InsertionText.StartsWith("jquery")); }
public async Task SearchAsync_Success() { string searchTerm = "jquery"; UnpkgCatalog sut = SetupCatalog(); IReadOnlyList <ILibraryGroup> absolute = await sut.SearchAsync(searchTerm, 1, CancellationToken.None); Assert.AreEqual(100, absolute.Count); IEnumerable <string> libraryVersions = await absolute[0].GetLibraryVersions(CancellationToken.None); Assert.IsTrue(libraryVersions.Any()); }
public async Task GetLibraryCompletionSetAsync_EmptyString() { var mockRequestHandler = new Mock <IWebRequestHandler>(); UnpkgCatalog sut = SetupCatalog(mockRequestHandler.Object); CompletionSet result = await sut.GetLibraryCompletionSetAsync(string.Empty, 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(0, result.Length); Assert.AreEqual(0, result.Completions.Count()); mockRequestHandler.Verify(m => m.GetStreamAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Never); }
[Ignore] // Enable it after version completion sorting is committed. public async Task GetLibraryCompletionSetAsync_Versions() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("jquery@", 7); Assert.AreEqual(7, result.Start); Assert.AreEqual(0, result.Length); Assert.IsTrue(result.Completions.Count() > 0); Assert.AreEqual("1.5.1", result.Completions.Last().DisplayText); Assert.AreEqual("[email protected]", result.Completions.Last().InsertionText); }
public async Task GetLibraryCompletionSetAsync_ScopesWithName() { UnpkgCatalog sut = SetupCatalog(); CompletionSet result = await sut.GetLibraryCompletionSetAsync("@types/node", 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(11, result.Length); Assert.AreEqual(25, result.Completions.Count()); Assert.AreEqual("@types/node", result.Completions.First().DisplayText); Assert.IsTrue(result.Completions.First().InsertionText.StartsWith("@types/node")); }
public async Task GetLibraryAsync_RequestFilesFailsWithNoCache_BlowsUp() { var webRequestHandler = new Mock <IWebRequestHandler>(); webRequestHandler.Setup(x => x.GetStreamAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .Throws(new ResourceDownloadException("Cache download blocked.")); var fakeCache = new Mock <ICacheService>(); fakeCache.SetupBlockRequests(); UnpkgCatalog sut = SetupCatalog(fakeCache.Object); await Assert.ThrowsExceptionAsync <InvalidLibraryException>(async() => await sut.GetLibraryAsync("fakeLibrary", "1.1.1", CancellationToken.None)); }
public async Task GetLibraryCompletionSetAsync_LibraryNameWithLeadingAndTrailingWhitespace() { UnpkgCatalog sut = SetupCatalog(); CancellationToken token = CancellationToken.None; CompletionSet result = await sut.GetLibraryCompletionSetAsync(" jquery ", 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(12, result.Length); Assert.AreEqual(100, result.Completions.Count()); Assert.AreEqual("jquery", result.Completions.First().DisplayText); Assert.IsTrue(result.Completions.First().InsertionText.StartsWith("jquery")); }
public async Task GetLibraryAsync_Success() { var fakeCache = new Mock <ICacheService>(); fakeCache.SetupLibraryFiles("fakeLib"); UnpkgCatalog sut = SetupCatalog(fakeCache.Object); ILibrary library = await sut.GetLibraryAsync("fakeLib", "1.0.0", CancellationToken.None); Assert.IsNotNull(library); Assert.AreEqual("fakeLib", library.Name); Assert.AreEqual("1.0.0", library.Version); }
public async Task GetLibraryCompletionSetAsync_EmptyString_MakesNoWebRequest() { var mockPackageSearch = new Mock <INpmPackageSearch>(); var mockPackageInfo = new Mock <INpmPackageInfoFactory>(); UnpkgCatalog sut = SetupCatalog(packageSearch: mockPackageSearch.Object, infoFactory: mockPackageInfo.Object); CompletionSet result = await sut.GetLibraryCompletionSetAsync(string.Empty, 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(0, result.Length); Assert.AreEqual(0, result.Completions.Count()); mockPackageInfo.VerifyNoOtherCalls(); mockPackageSearch.VerifyNoOtherCalls(); }
public async Task GetLibraryCompletionSetAsync_Names() { var mockSearch = new Mock <INpmPackageSearch>(); mockSearch.Setup(m => m.GetPackageNamesAsync("jquery", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new[] { new NpmPackageInfo("fakePackage1", "", "1.0.0") }.AsEnumerable())); UnpkgCatalog sut = SetupCatalog(packageSearch: mockSearch.Object); CompletionSet result = await sut.GetLibraryCompletionSetAsync("jquery", 0); Assert.AreEqual(0, result.Start); Assert.AreEqual(6, result.Length); CollectionAssert.AreEquivalent(new[] { "fakePackage1" }, result.Completions.Select(c => c.DisplayText).ToList()); }
public async Task SearchAsync_Success() { string searchTerm = "jquery"; var mockSearch = new Mock <INpmPackageSearch>(); NpmPackageInfo[] expectedResult = new[] { new NpmPackageInfo("fakepackage", "", "1.0.0") }; mockSearch.Setup(m => m.GetPackageNamesAsync("jquery", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(expectedResult.AsEnumerable())); UnpkgCatalog sut = SetupCatalog(packageSearch: mockSearch.Object); IReadOnlyList <ILibraryGroup> result = await sut.SearchAsync(searchTerm, 1, CancellationToken.None); Assert.AreEqual(1, result.Count); Assert.AreEqual("fakepackage", result[0].DisplayName); }
public async Task GetLibraryCompletionSetAsync_ScopesWithName() { var mockSearch = new Mock <INpmPackageSearch>(); mockSearch.Setup(m => m.GetPackageNamesAsync("@types/node", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new[] { new NpmPackageInfo("fakePackage1", "", "1.0.0") }.AsEnumerable())); UnpkgCatalog sut = SetupCatalog(packageSearch: mockSearch.Object); (string searchTerm, int caretPos) = ExtractCaret("|@types/node"); CompletionSet result = await sut.GetLibraryCompletionSetAsync(searchTerm, caretPos); Assert.AreEqual(0, result.Start); Assert.AreEqual(11, result.Length); CollectionAssert.AreEquivalent(new[] { "fakePackage1" }, result.Completions.Select(c => c.DisplayText).ToList()); }
public async Task GetLibraryCompletionSetAsync_ScopesWithNameAndVersions_CursorInNameSubstring() { var mockSearch = new Mock <INpmPackageSearch>(); // TODO: do we really not strip the version out here? Seems like we should... mockSearch.Setup(m => m.GetPackageNamesAsync("@types/[email protected]", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new[] { new NpmPackageInfo("fakePackage1", "", "1.0.0") }.AsEnumerable())); UnpkgCatalog sut = SetupCatalog(packageSearch: mockSearch.Object); (string nameStart, int caretPos) = ExtractCaret("@types/no|[email protected]"); CompletionSet result = await sut.GetLibraryCompletionSetAsync(nameStart, caretPos); Assert.AreEqual(0, result.Start); Assert.AreEqual(17, result.Length); CollectionAssert.AreEquivalent(new[] { "fakePackage1" }, result.Completions.Select(c => c.DisplayText).ToList()); }
public async Task GetLibraryCompletionSetAsync_ScopesWithNameAndTrailingAt_CursorAtName() { var mockSearch = new Mock <INpmPackageSearch>(); // TODO: we should strip the trailing @ from the name mockSearch.Setup(m => m.GetPackageNamesAsync("@types/react@", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new[] { new NpmPackageInfo("fakePackage1", "", "1.0.0") }.AsEnumerable())); UnpkgCatalog sut = SetupCatalog(packageSearch: mockSearch.Object); (string nameStart, int caretPos) = ExtractCaret("@types/r|eact@"); CompletionSet result = await sut.GetLibraryCompletionSetAsync(nameStart, caretPos); Assert.AreEqual(0, result.Start); Assert.AreEqual(13, result.Length); Assert.AreEqual(CompletionSortOrder.AsSpecified, result.CompletionType); CollectionAssert.AreEquivalent(new[] { "fakePackage1" }, result.Completions.Select(c => c.DisplayText).ToList()); }
public async Task GetLibraryCompletionSetAsync_ScopesWithNameAndTrailingAt_CursorAtVersions() { var mockPackageInfoFactory = new Mock <INpmPackageInfoFactory>(); mockPackageInfoFactory.Setup(m => m.GetPackageInfoAsync("@types/react", It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new NpmPackageInfo("fakepackage", "", "2.0.0", new List <SemanticVersion> { SemanticVersion.Parse("1.0.0"), SemanticVersion.Parse("2.0.0") }))); UnpkgCatalog sut = SetupCatalog(infoFactory: mockPackageInfoFactory.Object); (string nameStart, int caretPos) = ExtractCaret("@types/react@|"); CompletionSet result = await sut.GetLibraryCompletionSetAsync(nameStart, caretPos); Assert.AreEqual(13, result.Start); Assert.AreEqual(0, result.Length); Assert.AreEqual(CompletionSortOrder.Version, result.CompletionType); CollectionAssert.AreEqual(new[] { "2.0.0", "1.0.0", "latest" }, result.Completions.Select(c => c.DisplayText).ToList()); }
public async Task GetLatestVersion_Prerelease() { const string libraryName = "fakeLibrary"; var versions = new List <SemanticVersion>() { SemanticVersion.Parse("2.0.0-beta"), SemanticVersion.Parse("1.0.0"), }; var fakeCache = new Mock <ICacheService>(); fakeCache.SetupPackageVersions(libraryName); var fakePackageInfoFactory = new Mock <INpmPackageInfoFactory>(); fakePackageInfoFactory.Setup(f => f.GetPackageInfoAsync(It.Is <string>(s => s == libraryName), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new NpmPackageInfo(libraryName, "test package", "1.0.0", versions))); UnpkgCatalog sut = SetupCatalog(fakeCache.Object, infoFactory: fakePackageInfoFactory.Object); string result = await sut.GetLatestVersion(libraryName, includePreReleases : true, CancellationToken.None); Assert.AreEqual("2.0.0-beta", result); }
public async Task GetLibraryAsync_InvalidLibraryId() { UnpkgCatalog sut = SetupCatalog(); await Assert.ThrowsExceptionAsync <InvalidLibraryException>(async() => await sut.GetLibraryAsync("invalid_id", "invalid_version", CancellationToken.None)); }