public void GlobalJsonRemover_NoJson_DoesntCrash()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var solution    = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback);
            var dteSolution = SolutionFactory.ImplementFindProjectItem(path =>
            {
                Assert.Equal(Path.Combine(Directory, "global.json"), path);
                return(null);
            });
            var dte = DteFactory.ImplementSolution(() => dteSolution);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(t =>
            {
                if (typeof(SVsSolution) == t)
                {
                    return(solution);
                }

                if (typeof(DTE) == t)
                {
                    return(dte);
                }

                Assert.False(true);
                throw new InvalidOperationException();
            });

            var remover = new GlobalJsonRemover(serviceProvider, IFileSystemFactory.Create());

            GlobalJsonRemover.Remover = remover;
            Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0));
        }
Example #2
0
        public void GlobalJsonRemover_RemovesJson_WhenExists()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var solution    = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback);
            var projectItem = ProjectItemFactory.Create();
            var dteSolution = SolutionFactory.ImplementFindProjectItem(path =>
            {
                Assert.Equal(Path.Combine(Directory, "global.json"), path);
                return(projectItem);
            });
            var dte = DteFactory.ImplementSolution(() => dteSolution);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(t =>
            {
                if (typeof(SVsSolution) == t)
                {
                    return(solution);
                }

                if (typeof(DTE) == t)
                {
                    return(dte);
                }

                Assert.False(true);
                throw new InvalidOperationException();
            });

            var remover = new GlobalJsonRemover(serviceProvider);

            Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0));
            Mock.Get(projectItem).Verify(p => p.Remove(), Times.Once);
        }
        public void WhenNodeIsNull_NoCommandHandlerIsReturned()
        {
            var extender = new ProjectNodeExtender(GetJoinableTaskContext(), IServiceProviderFactory.ImplementGetService(t => null));

            var commandHandler = extender.ProvideCommandHandler(null !);

            Assert.Null(commandHandler);
        }
Example #4
0
        public void Value_WhenMissingService_ReturnsNull()
        {
            var serviceProvider = IServiceProviderFactory.ImplementGetService(type => null);

            var service = CreateInstance <string, string>(serviceProvider: serviceProvider);

            var result = service.Value;

            Assert.Null(result);
        }
Example #5
0
        public void Value_WhenMissingService_ReturnsNull()
        {
            var threadingService = IProjectThreadingServiceFactory.ImplementVerifyOnUIThread(() => { });
            var serviceProvider  = IServiceProviderFactory.ImplementGetService(type => null);

            var service = CreateInstance <string, string>(serviceProvider: serviceProvider, threadingService: threadingService);

            var result = service.Value;

            Assert.Null(result);
        }
        public void WhenSelectionKindIsWrong_NoCommandHandlerIsReturned()
        {
            var extender = new ProjectNodeExtender(GetJoinableTaskContext(), IServiceProviderFactory.ImplementGetService(t => null));
            var node     = WorkspaceVisualNodeBaseFactory.Implement(
                selectionKind: Guid.Parse("{95D7E5E9-08FA-40FB-9010-2CCEEC6D54C1}"),
                nodeMoniker: "Test.csproj",
                selectionMoniker: "Test.csproj");

            var commandHandler = extender.ProvideCommandHandler(node);

            Assert.Null(commandHandler);
        }
        public void WhenNodeRepresentsAManagedProject_ACommandHandlerIsReturned()
        {
            var extender = new ProjectNodeExtender(GetJoinableTaskContext(), IServiceProviderFactory.ImplementGetService(t => null));
            var node     = WorkspaceVisualNodeBaseFactory.Implement(
                selectionKind: CloudEnvironment.SolutionViewProjectGuid,
                nodeMoniker: "Test.csproj",
                selectionMoniker: "Test.csproj");

            var commandHandler = extender.ProvideCommandHandler(node);

            Assert.NotNull(commandHandler);
        }
        public void Value_WhenMissingService_Throws()
        {
            var threadingService = IProjectThreadingServiceFactory.ImplementVerifyOnUIThread(() => { });
            var serviceProvider  = IServiceProviderFactory.ImplementGetService(type => null);

            var service = CreateInstance <string, string>(serviceProvider: serviceProvider, threadingService: threadingService);

            // We don't really care about the exception, it's an assertion
            Assert.ThrowsAny <Exception>(() => {
                var value = service.Value;
            });
        }
        public void SingleFileGeneratorFactoryAggregator_NoGeneratorId_ReturnsFail()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var manager            = CreateManagerForPath($"Generators\\{PackageGuid.ToString("B").ToUpper()}");
            var serviceProvider    = IServiceProviderFactory.ImplementGetService(type => manager);
            var integrationService = IVsUnconfiguredProjectIntegrationServiceFactory.ImplementProjectTypeGuid(PackageGuid);

            var aggregator = new SingleFileGeneratorFactoryAggregator(serviceProvider, integrationService);

            Assert.Equal(VSConstants.E_FAIL,
                         aggregator.GetGeneratorInformation("ResXCodeFileGenerator", out int actualDesignTime, out int actualSharedDesignTime, out int actualCompileFlag, out Guid actualGuid));
        }
Example #10
0
        public void Value_CachesResult()
        {
            var serviceProvider = IServiceProviderFactory.ImplementGetService(type =>
            {
                return(new object());
            });

            var service = CreateInstance <string, object>(serviceProvider: serviceProvider);

            var result1 = service.Value;
            var result2 = service.Value;

            Assert.Same(result1, result2);
        }
Example #11
0
        public void Value_DoesNotCache()
        {
            var threadingService = IProjectThreadingServiceFactory.ImplementVerifyOnUIThread(() => { });
            var serviceProvider  = IServiceProviderFactory.ImplementGetService(type => {
                return(new object());
            });

            var service = CreateInstance <string, object>(serviceProvider: serviceProvider, threadingService: threadingService);

            var result1 = service.Value;
            var result2 = service.Value;

            Assert.NotSame(result1, result2);
        }
        public void SingleFileGeneratorFactoryAggregator_GivenValidRegistry_OptionalParamsAreOptional()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var manager            = CreateManager();
            var serviceProvider    = IServiceProviderFactory.ImplementGetService(type => manager);
            var integrationService = IVsUnconfiguredProjectIntegrationServiceFactory.ImplementProjectTypeGuid(PackageGuid);

            var aggregator = new SingleFileGeneratorFactoryAggregator(serviceProvider, integrationService);

            Assert.Equal(VSConstants.S_OK,
                         aggregator.GetGeneratorInformation("ResXCodeFileGenerator", out int actualDesignTime, out int actualSharedDesignTime, out int actualCompileFlag, out Guid actualGuid));

            Assert.Equal(0, actualDesignTime);
            Assert.Equal(0, actualSharedDesignTime);
            Assert.Equal(0, actualCompileFlag);
            Assert.Equal(ResXGuid, actualGuid);
        }
        public async Task FrameOpenCloseListener_InitializeEventsAsync_SetsUpWindowFrameEvents()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseWindowEvents(l => 1);

            uint eventsCookie = 2;
            var  solution     = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(eventsCookie);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var listener = new FrameOpenCloseListener(serviceProvider,
                                                      IProjectFileEditorPresenterFactory.Create(),
                                                      new IProjectThreadingServiceMock(),
                                                      UnconfiguredProjectFactory.Create());

            await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create());

            Mock.Get(uiShell).Verify(u => u.AdviseWindowFrameEvents(listener), Times.Once);
            Mock.Get(solution).Verify(s => s.AdviseSolutionEvents(listener, out eventsCookie), Times.Once);
        }
        public void GlobalJsonRemover_AfterRemoval_UnadvisesEvents()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var globalJsonPath = Path.Combine(Directory, "global.json");
            var solution       = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback);
            var projectItem    = ProjectItemFactory.Create();
            var dteSolution    = SolutionFactory.ImplementFindProjectItem(path =>
            {
                Assert.Equal(globalJsonPath, path);
                return(projectItem);
            });
            var dte = DteFactory.ImplementSolution(() => dteSolution);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(t =>
            {
                if (typeof(SVsSolution) == t)
                {
                    return(solution);
                }

                if (typeof(DTE) == t)
                {
                    return(dte);
                }

                Assert.False(true);
                throw new InvalidOperationException();
            });

            var fileSystem = IFileSystemFactory.Create();

            fileSystem.Create(globalJsonPath);

            var remover = new GlobalJsonRemover(serviceProvider, fileSystem)
            {
                SolutionCookie = 1234
            };

            GlobalJsonRemover.Remover = remover;
            Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0));
            Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(1234), Times.Once);
        }
Example #15
0
        public void Value_ReturnsGetService()
        {
            object input = new object();

            var threadingService = IProjectThreadingServiceFactory.ImplementVerifyOnUIThread(() => { });
            var serviceProvider  = IServiceProviderFactory.ImplementGetService(type => {
                if (type == typeof(string))
                {
                    return(input);
                }

                return(null);
            });

            var service = CreateInstance <string, object>(serviceProvider: serviceProvider, threadingService: threadingService);

            var result = service.Value;

            Assert.Same(input, result);
        }
        public async Task FrameOpenCloseListener_Dispose_UnsubscribesCorrectly()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c));

            var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var listener = new FrameOpenCloseListener(serviceProvider,
                                                      IProjectFileEditorPresenterFactory.Create(),
                                                      new IProjectThreadingServiceMock(),
                                                      UnconfiguredProjectFactory.Create());

            await listener.InitializeEventsAsync(IVsWindowFrameFactory.Create());

            await listener.DisposeAsync();

            Mock.Get(uiShell).Verify(u => u.UnadviseWindowFrameEvents(1234), Times.Once);
            Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(4321), Times.Once);
        }
        public void FrameOpenCloseListener_QueryUnloadCorrectProjectNoCancel_CallsCloseOnEditor()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c));

            var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var editorState = IProjectFileEditorPresenterFactory.ImplementCloseWindowAsync(true);

            var projPath            = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projPath);
            var hierarchy           = IVsHierarchyFactory.ImplementAsUnconfiguredProject(unconfiguredProject);

            int shouldCancel = -1;

            var listener = new FrameOpenCloseListener(serviceProvider, editorState, new IProjectThreadingServiceMock(), unconfiguredProject);

            Assert.Equal(VSConstants.S_OK, listener.OnQueryUnloadProject(hierarchy, ref shouldCancel));
            Assert.Equal(0, shouldCancel);
            Mock.Get(editorState).Verify(e => e.CanCloseWindowAsync(), Times.Once);
        }
Example #18
0
        public void SingleFileGeneratorFactoryAggregator_GivenValidRegistry_RetrievesData(int designTimeSource, int sharedDesignTimeSource, int compileFlag)
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var manager         = CreateManager(true, designTimeSource, sharedDesignTimeSource, compileFlag);
            var serviceProvider = IServiceProviderFactory.ImplementGetService(type => manager);

            var integrationService = IVsUnconfiguredProjectIntegrationServiceFactory.ImplementProjectTypeGuid(PackageGuid);

            var aggregator = new SingleFileGeneratorFactoryAggregator(serviceProvider, integrationService);

            int  actualDesignTime;
            int  actualSharedDesignTime;
            int  actualCompileFlag;
            Guid actualGuid;

            Assert.Equal(VSConstants.S_OK,
                         aggregator.GetGeneratorInformation("ResXCodeFileGenerator", out actualDesignTime, out actualSharedDesignTime, out actualCompileFlag, out actualGuid));

            Assert.Equal(designTimeSource == 1 ? 1 : 0, actualDesignTime);
            Assert.Equal(sharedDesignTimeSource == 1 ? 1 : 0, actualSharedDesignTime);
            Assert.Equal(compileFlag == 1 ? 1 : 0, actualCompileFlag);
            Assert.Equal(ResXGuid, actualGuid);
        }
Example #19
0
 private static ProjectNodeCommandHandler CreateCommandHandler()
 {
     return(new ProjectNodeCommandHandler(
                GetJoinableTaskContext(),
                IServiceProviderFactory.ImplementGetService(t => null)));
 }