コード例 #1
0
        public void TestTPDEvents()
        {
            int result = 0;

            SccProviderService target = GetSccProviderServiceInstance;

            solution.SolutionFile = Path.GetTempFileName();
            MockIVsProject project = new MockIVsProject(Path.GetTempFileName());

            solution.AddProject(project);

            Hashtable uncontrolled = new Hashtable();

            uncontrolled[project as IVsSccProject2] = true;
            target.AddProjectsToSourceControl(ref uncontrolled, true);
            // In real live, a QueryEdit call on the project file would be necessary to add/rename/delete items

            // Add a new item and fire the appropriate events
            string pendingAddFile = Path.GetTempFileName();

            VSQUERYADDFILERESULTS[] pSummaryResultAdd = new VSQUERYADDFILERESULTS[1];
            VSQUERYADDFILERESULTS[] rgResultsAdd      = new VSQUERYADDFILERESULTS[1];
            result = target.OnQueryAddFiles(project as IVsProject, 1, new string[] { pendingAddFile }, null, pSummaryResultAdd, rgResultsAdd);
            Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result);
            project.AddItem(pendingAddFile);
            result = target.OnAfterAddFilesEx(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { pendingAddFile }, null);
            Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result);
            Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned");

            // Checkin the pending add file
            target.AddFileToSourceControl(pendingAddFile);

            // Rename the item and verify the file remains is controlled
            string newName = pendingAddFile + ".renamed";

            VSQUERYRENAMEFILERESULTS[] pSummaryResultRen = new VSQUERYRENAMEFILERESULTS[1];
            VSQUERYRENAMEFILERESULTS[] rgResultsRen      = new VSQUERYRENAMEFILERESULTS[1];
            result = target.OnQueryRenameFiles(project as IVsProject, 1, new string[] { pendingAddFile }, new string[] { newName }, null, pSummaryResultRen, rgResultsRen);
            Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result);
            project.RenameItem(pendingAddFile, newName);
            result = target.OnAfterRenameFiles(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { pendingAddFile }, new string[] { newName }, new VSRENAMEFILEFLAGS[] { VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags });
            Assert.AreEqual <int>(VSConstants.S_OK, result);
            Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(pendingAddFile), "Incorrect status returned");
            Assert.AreEqual(SourceControlStatus.scsCheckedIn, target.GetFileStatus(newName), "Incorrect status returned");

            // Mock the UIShell service to answer Cancel to the dialog invocation
            BaseMock mockUIShell = MockUiShellProvider.GetShowMessageBoxCancel();

            serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true);
            // Try to delete the file from project; the delete should not be allowed
            VSQUERYREMOVEFILERESULTS[] pSummaryResultDel = new VSQUERYREMOVEFILERESULTS[1];
            VSQUERYREMOVEFILERESULTS[] rgResultsDel      = new VSQUERYREMOVEFILERESULTS[1];
            result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel);
            Assert.AreEqual <int>(VSConstants.S_OK, result);
            Assert.AreEqual <VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveNotOK, pSummaryResultDel[0]);
            // Mock the UIShell service to answer Yes to the dialog invocation
            serviceProvider.RemoveService(typeof(IVsUIShell));
            mockUIShell = MockUiShellProvider.GetShowMessageBoxYes();
            serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true);
            // Try to delete the file from project; the delete should be allowed this time
            result = target.OnQueryRemoveFiles(project as IVsProject, 1, new string[] { newName }, null, pSummaryResultDel, rgResultsDel);
            Assert.AreEqual <int>(VSConstants.S_OK, result);
            Assert.AreEqual <VSQUERYREMOVEFILERESULTS>(VSQUERYREMOVEFILERESULTS.VSQUERYREMOVEFILERESULTS_RemoveOK, pSummaryResultDel[0]);
            // Remove the file from project
            project.RemoveItem(newName);
            result = target.OnAfterRemoveFiles(1, 1, new IVsProject[] { project as IVsProject }, new int[] { 0 }, new string[] { newName }, null);
            Assert.AreEqual <int>(VSConstants.E_NOTIMPL, result);
        }
コード例 #2
0
        public void QueryEditQuerySaveTest()
        {
            uint pfEditVerdict;
            uint prgfMoreInfo;
            uint pdwQSResult;
            int  result;

            SccProviderService target = GetSccProviderServiceInstance;

            // check the functions that are not implemented
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.BeginQuerySaveBatch());
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.EndQuerySaveBatch());
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.DeclareReloadableFile("", 0, null));
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.DeclareUnreloadableFile("", 0, null));
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.OnAfterSaveUnreloadableFile("", 0, null));
            Assert.AreEqual((int)VSConstants.S_OK, (int)target.IsReloadable("", out result));
            Assert.AreEqual(1, result, "Not the right return value from IsReloadable");

            // Create a basic service provider

            IVsShell shell = MockShellProvider.GetShellForCommandLine() as IVsShell;

            serviceProvider.AddService(typeof(IVsShell), shell, true);

            // Command line tests
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_ReportOnly, 1, new string[] { "Dummy.txt" }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)0, prgfMoreInfo, "QueryEdit failed.");

            result = target.QuerySaveFile("Dummy.txt", 0, null, out pdwQSResult);
            Assert.AreEqual(VSConstants.S_OK, result, "QuerySave failed.");
            Assert.AreEqual((uint)tagVSQuerySaveResult.QSR_SaveOK, pdwQSResult, "QueryEdit failed.");

            serviceProvider.RemoveService(typeof(SVsShell));

            // UI mode tests
            shell = MockShellProvider.GetShellForUI() as IVsShell;
            serviceProvider.AddService(typeof(SVsShell), shell, true);

            // Edit of an uncontrolled file that doesn't exist on disk
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_ReportOnly, 1, new string[] { "Dummy.txt" }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)0, prgfMoreInfo, "QueryEdit failed.");

            // Mock a solution with a project and a file
            solution.SolutionFile = Path.GetTempFileName();
            MockIVsProject project = new MockIVsProject(Path.GetTempFileName());

            solution.AddProject(project);
            // Add only the project to source control.
            Hashtable uncontrolled = new Hashtable();

            uncontrolled[project as IVsSccProject2] = true;
            target.AddProjectsToSourceControl(ref uncontrolled, false);
            // Check that solution file is not controlled
            Assert.AreEqual(SourceControlStatus.scsUncontrolled, target.GetFileStatus(solution.SolutionFile), "Incorrect status returned");
            // Make the solution read-only on disk
            File.SetAttributes(solution.SolutionFile, FileAttributes.ReadOnly);

            // QueryEdit in report mode for uncontrolled readonly file
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_ReportOnly, 1, new string[] { solution.SolutionFile }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditNotOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)(tagVSQueryEditResultFlags.QER_EditNotPossible | tagVSQueryEditResultFlags.QER_ReadOnlyNotUnderScc), prgfMoreInfo, "QueryEdit failed.");

            // QueryEdit in silent mode for uncontrolled readonly file
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_SilentMode, 1, new string[] { solution.SolutionFile }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditNotOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)(tagVSQueryEditResultFlags.QER_NoisyPromptRequired), (uint)(tagVSQueryEditResultFlags.QER_NoisyPromptRequired) & prgfMoreInfo, "QueryEdit failed.");

            // Mock the UIShell service to answer Yes to the dialog invocation
            BaseMock mockUIShell = MockUiShellProvider.GetShowMessageBoxYes();

            serviceProvider.AddService(typeof(IVsUIShell), mockUIShell, true);

            // QueryEdit for uncontrolled readonly file: allow the edit and make the file read-write
            result = target.QueryEditFiles(0, 1, new string[] { solution.SolutionFile }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)0, prgfMoreInfo, "QueryEdit failed.");
            Assert.AreEqual <FileAttributes>(FileAttributes.Normal, File.GetAttributes(solution.SolutionFile), "File was not made writable");
            serviceProvider.RemoveService(typeof(IVsUIShell));

            // QueryEdit in report mode for controlled readonly file
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_ReportOnly, 1, new string[] { project.ProjectFile }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditNotOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)(tagVSQueryEditResultFlags.QER_EditNotPossible | tagVSQueryEditResultFlags.QER_ReadOnlyUnderScc), prgfMoreInfo, "QueryEdit failed.");

            // QueryEdit in silent mode for controlled readonly file: should allow the edit and make the file read-write
            result = target.QueryEditFiles((uint)tagVSQueryEditFlags.QEF_SilentMode, 1, new string[] { project.ProjectFile }, null, null, out pfEditVerdict, out prgfMoreInfo);
            Assert.AreEqual(VSConstants.S_OK, result, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResult.QER_EditOK, pfEditVerdict, "QueryEdit failed.");
            Assert.AreEqual((uint)tagVSQueryEditResultFlags.QER_MaybeCheckedout, prgfMoreInfo, "QueryEdit failed.");
            Assert.AreEqual <FileAttributes>(FileAttributes.Normal, File.GetAttributes(solution.SolutionFile), "File was not made writable");
            serviceProvider.RemoveService(typeof(IVsUIShell));
        }