Пример #1
0
 /// <summary>
 /// Creates a new file containing the missing steps and adds them to the visual studio
 /// solution. Then displays a message conveying whether it succeeded.
 /// </summary>
 private void WriteStepsToFile(IStepDefinitionSkeletonProvider skeletonProvider, List<StepInstance> missingSteps)
 {
     //Store info on file
     StepDefSkeletonInfo info = new StepDefSkeletonInfo(_suggestedStepDefName,
                                                        _defaultNamespace);
     //Generate the skeleton for the new file
     string skeleton = skeletonProvider.GetFileSkeleton(missingSteps, info);
     string file;
     try
     {
         //Try to write the skeleton to a file
         file = _handler.WriteToFile(skeleton, false, _suggestedStepDefName, _featurePath);
     }
     catch (FileHandlerException fileHandlerException)
     {
         //If the file already existed, ask to overwrite
         var overwrite = MessageBox.Show(fileHandlerException.Message, MessageBoxHeader,
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         //If they have selected to overwrite then add again, this time allowing overwrites
         if (overwrite == DialogResult.Yes)
             file = _handler.WriteToFile(skeleton, true, _suggestedStepDefName, _featurePath);
         else
             throw new FileGeneratorException("Cancelled creating step definition file.");
     }
     //Add the file generated to the visual studio solution
     if (!_handler.AddToSolution(_sln, _featurePath, file))
         MessageBox.Show(
             "A step defintion file has been created but it could not be added to an existing visual studio project",
             MessageBoxHeader, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     else
         MessageBox.Show("Success! A step definition file has been generated",
                         MessageBoxHeader);
 }