Exemple #1
0
        public async Task PerformSearch_CaretPositionBeyondSearchTextLength_Throws()
        {
            var host    = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var testObj = new LocationSearchService(host);

            _ = await testObj.PerformSearch("test", 5);
        }
Exemple #2
0
        public async Task PerformSearch_NegativeCaretPosition_Throws()
        {
            var host    = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var testObj = new LocationSearchService(host);

            _ = await testObj.PerformSearch("", -2);
        }
Exemple #3
0
        public async Task UninstallAsync_DeletesFilesFromDisk()
        {
            IHostInteraction mockInteraction = new Mocks.HostInteraction();
            var mockTaskStatusCenterService  = new Mock <ITaskStatusCenterService>();

            mockTaskStatusCenterService.Setup(m => m.CreateTaskHandlerAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(new Mock <ITaskHandler>().Object));
            var mockDependencies = new Dependencies(mockInteraction, new IProvider[]
            {
                new Mocks.Provider(mockInteraction)
                {
                    Id      = "testProvider",
                    Catalog = new Mocks.LibraryCatalog(),
                    Result  = new LibraryOperationResult
                    {
                        InstallationState = new LibraryInstallationState
                        {
                            ProviderId      = "testProvider",
                            Files           = new [] { "test.js" },
                            DestinationPath = "testDestination",
                        }
                    },
                    SupportsLibraryVersions = true,
                }
            });
            var mockDependenciesFactory = new Mock <IDependenciesFactory>();

            mockDependenciesFactory.Setup(m => m.FromConfigFile(It.IsAny <string>()))
            .Returns(mockDependencies);
            LibraryIdToNameAndVersionConverter.Instance.Reinitialize(mockDependencies);

            string manifestContents = @"{
    ""version"": ""1.0"",
    ""libraries"": [
        {
            ""library"": ""[email protected]"",
            ""provider"": ""testProvider"",
            ""destination"": ""testDestination""
        }
    ]
}";

            byte[] manifestBytes = Encoding.Default.GetBytes(manifestContents);

            string configFilePath = Path.Combine(mockInteraction.WorkingDirectory, "libman.json");
            await mockInteraction.WriteFileAsync("libman.json", () => new MemoryStream(manifestBytes), default(LibraryInstallationState), CancellationToken.None);

            await mockInteraction.WriteFileAsync(@"testDestination\test.js", () => new MemoryStream(manifestBytes), default(LibraryInstallationState), CancellationToken.None);

            var solutionEvents = new DefaultSolutionEvents(new Mock <IVsSolution>().Object);

            var ut = new LibraryCommandService(mockDependenciesFactory.Object, mockTaskStatusCenterService.Object, solutionEvents);
            await ut.UninstallAsync(configFilePath, "test", "1.0", "testProvider", CancellationToken.None);

            Assert.IsFalse(File.Exists(Path.Combine(mockInteraction.WorkingDirectory, "testDestination", "test.js")));
        }
Exemple #4
0
        public async Task PerformSearch_NullSearchText_TreatAsEmpty()
        {
            var    host         = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var    testObj      = new LocationSearchService(host);
            string searchString = null;

            CompletionSet result = await testObj.PerformSearch(searchString, 0);

            Assert.AreEqual(3, result.Completions.Count());
        }
Exemple #5
0
        public async Task PerformSearch_SearchTextContainsSeparator_ReturnSubdirectoriesOnly()
        {
            var    host         = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var    testObj      = new LocationSearchService(host);
            string searchString = "RootFolder2/";

            CompletionSet result = await testObj.PerformSearch(searchString, searchString.Length);

            Assert.AreEqual(1, result.Completions.Count());
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "RootFolder2/SubFolder/"));
        }
Exemple #6
0
        public async Task PerformSearch_SearchTextDoesNotContainSeparator_FilterSearchResults()
        {
            var    host         = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var    testObj      = new LocationSearchService(host);
            string searchString = "Root";

            CompletionSet result = await testObj.PerformSearch(searchString, searchString.Length);

            Assert.AreEqual(2, result.Completions.Count());
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "RootFolder1/"));
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "RootFolder2/"));
        }
Exemple #7
0
        public async Task PerformSearch_EmptySearchText_ReturnsContentsOfWorkingDirectory()
        {
            var    host         = new Mocks.HostInteraction(TestDirectoryRoot, null);
            var    testObj      = new LocationSearchService(host);
            string searchString = "";

            CompletionSet result = await testObj.PerformSearch(searchString, searchString.Length);

            Assert.AreEqual(3, result.Completions.Count());
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "RootFolder1/"));
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "RootFolder2/"));
            Assert.IsTrue(result.Completions.Any(c => c.InsertionText == "DifferentlyNamedFolder/"));
        }