public void btnSkipSave_ClickTest() { DlgQuerySaveCheckedInFile target = new DlgQuerySaveCheckedInFile("Dummy.txt"); MethodInfo method = typeof(DlgQuerySaveCheckedInFile).GetMethod("btnSkipSave_Click", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(target, new object[] { null, null }); Assert.AreEqual(target.Answer, DlgQuerySaveCheckedInFile.qscifSkipSave); }
/// <summary> /// Called by editors and projects before saving the files /// The function allows the source control systems to take the necessary actions (checkout, flip attributes) /// to make the file writable in order to allow the file saving to continue /// </summary> public int QuerySaveFiles([InAttribute] uint rgfQuerySave, [InAttribute] int cFiles, [InAttribute] string[] rgpszMkDocuments, [InAttribute] uint[] rgrgf, [InAttribute] VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pdwQSResult) { // Initialize output variables // It's a bit unfortunate that we have to return only one set of flags for all the files involved in the operation // The last file will win setting this flag pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK; // In non-UI mode attempt to silently flip the attributes of files or check them out // and allow the save, because the user cannot be asked what to do with the file if (_sccProvider.InCommandLineMode()) { rgfQuerySave = rgfQuerySave | (uint)tagVSQuerySaveFlags.QSF_SilentMode; } try { for (int iFile = 0; iFile < cFiles; iFile++) { SourceControlStatus status = GetFileStatus(rgpszMkDocuments[iFile]); bool fileExists = File.Exists(rgpszMkDocuments[iFile]); bool isFileReadOnly = false; if (fileExists) { isFileReadOnly = ((File.GetAttributes(rgpszMkDocuments[iFile]) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly); } switch (status) { case SourceControlStatus.scsCheckedIn: DlgQuerySaveCheckedInFile dlgAskCheckout = new DlgQuerySaveCheckedInFile(rgpszMkDocuments[iFile]); if ((rgfQuerySave & (uint)tagVSQuerySaveFlags.QSF_SilentMode) != 0) { // When called in silent mode, attempt the checkout // (The alternative is to deny the save, return QSR_NoSave_NoisyPromptRequired and expect for a non-silent call) dlgAskCheckout.Answer = DlgQuerySaveCheckedInFile.qscifCheckout; } else { dlgAskCheckout.ShowDialog(); } switch (dlgAskCheckout.Answer) { case DlgQueryEditCheckedInFile.qecifCheckout: // Checkout the file, and since it cannot fail, allow the save to continue CheckoutFileAndRefreshProjectGlyphs(rgpszMkDocuments[iFile]); pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK; break; case DlgQuerySaveCheckedInFile.qscifForceSaveAs: pdwQSResult = (uint)tagVSQuerySaveResult.QSR_ForceSaveAs; break; case DlgQuerySaveCheckedInFile.qscifSkipSave: pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Continue; break; default: pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Cancel; break; } break; case SourceControlStatus.scsCheckedOut: // fall through case SourceControlStatus.scsUncontrolled: if (fileExists && isFileReadOnly) { // Make the file writable and allow the save File.SetAttributes(rgpszMkDocuments[iFile], FileAttributes.Normal); } // Allow the save now pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK; break; } } } catch (Exception) { // If an exception was caught, do not allow the save pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Cancel; } return VSConstants.S_OK; }
public void ConstructorTest() { DlgQuerySaveCheckedInFile target = new DlgQuerySaveCheckedInFile("Dummy.txt"); Assert.IsNotNull(target, "DlgQuerySaveCheckedInFile cannot be created"); }