Пример #1
0
 public BrowseForUnitLibraries(string message, BrowseForNunitDialogType browsingForType, AbstractTestFramework testFramework)
 {
    InitializeComponent();
    txtContent.Text = message;
    this.browsingType = browsingForType;
    this.testFramework = testFramework;
 }
Пример #2
0
 public BrowseForUnitLibraries(string message, BrowseForNunitDialogType browsingForType, AbstractTestFramework testFramework)
 {
     InitializeComponent();
     txtContent.Text    = message;
     this.browsingType  = browsingForType;
     this.testFramework = testFramework;
 }
Пример #3
0
      /// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
      public Connect()
      {
         //Creating the unit test framework object. Default NUnit.
         testFramework = TestFrameworkFactory.CreateNUnitTestFramework(Settings.Default.UnitBinariesDirectory, Settings.Default.UnitConsoleDirectory, Settings.Default.UnitCommandsDirectory);
         testFramework.TestStarted += new AbstractTestFramework.TestStartedDelegate(testFramework_testStartedEvent);
         testFramework.TestEnded += new AbstractTestFramework.TestEndedDelegate(testFramework_testEndedEvent);
         testFramework.BinariesLocationChanged += new AbstractTestFramework.BinariesLocationChangeDelegate(testFramework_BinariesLocationChanged);
         testFramework.ConsoleLocationChanged += new AbstractTestFramework.ConsoleLocationChangeDelegate(testFramework_ConsoleLocationChanged);
         testFramework.CommandsLocationChanged += new AbstractTestFramework.CommandsLocationChangeDelegate(testFramework_CommandsLocationChanged);

           
         //Creating the coverage framework object. Default OpenCover.
         coverageFramework = CodeCoverageFactory.CreateOpenCoverFramework(Settings.Default.CoverageBinariesDirectory, Settings.Default.CoverageBinariesDirectory, Settings.Default.CoverageBinariesDirectory, this.testFramework);
         coverageFramework.CoverageExaminationStarted += new AbstractCodeCoverageFramework.CoverageExaminationStartedDelegate(coverageFramework_CoverageExaminationStarted);
         coverageFramework.CoverageExaminationEnded += new AbstractCodeCoverageFramework.CoverageExaminationEndedDelegate(coverageFramework_CoverageExaminationEnded);
         coverageFramework.BinariesLocationChanged += new AbstractCodeCoverageFramework.BinariesLocationChangeDelegate(coverageFramework_BinariesLocationChanged);
         coverageFramework.ConsoleLocationChanged += new AbstractCodeCoverageFramework.ConsoleLocationChangeDelegate(coverageFramework_ConsoleLocationChanged);
         coverageFramework.CommandsLocationChanged += new AbstractCodeCoverageFramework.CommandsLocationChangeDelegate(coverageFramework_CommandsLocationChanged);
      }
Пример #4
0
      internal static void copyReferences(AbstractTestFramework testFramework, Project parentProject, Project unitTestProject)
      {
         //Add a unit test dll like nunit.framework.dll ref
         string tvTempUnitTestFolderHolder = testFramework.BinariesDirectory;

         if (!tvTempUnitTestFolderHolder.Equals(string.Empty))
         {
            foreach(string dll in testFramework.FrameworkDlls)
            {
               VSLangProj.Reference nunitReferance =
               ProjectManager.AddDllReferenceToProject(unitTestProject, System.IO.Path.Combine(tvTempUnitTestFolderHolder, dll));
            }
         }

         //add original projects outputted dll
         string tvTempOriginalProjectOutputDll =
            UTGManagerAndExaminor.ProjectExaminar.GetProjectOutputFullAssemblyName(parentProject);

         ProjectManager.AddDllReferenceToProject(unitTestProject, tvTempOriginalProjectOutputDll);

         //add original projects refs
         VSLangProj.References references = ProjectManager.GetProjectReferences(parentProject);

         ProjectManager.AddReferencesToProject(references, unitTestProject);
      }
Пример #5
0
      internal static void HandelCodeClassSelection(AbstractTestFramework testFramework, CodeProperty property, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         Project parentProject = ProjectExaminar.GetCodeClassParentProject((CodeClass)property.Parent);

         Project unitTestProject = ProjectExaminar.GetUnitTestProject(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);

         //We might or might not use this factory, we don't know at this point
         AbstractTestClassFactory testClassFactory = new NUnitTestClassFactory();

         foreach (ProjectItem projectItem in unitTestProject.ProjectItems)
         {
            System.Collections.Generic.List<CodeClass> lstCodeClasses =
                 ProjectItemExaminor.GetCodeClasses(projectItem.FileCodeModel);

            foreach (CodeClass codeClass in lstCodeClasses)
            {
               if (codeClass.Name.Equals(((CodeClass)property.Parent).Name + testFramework.TestClassFixturePostFix))
               {
                  //if found 
                  AbstractTestClass nunitClass = null;

                  if (codeType == UnitTestCodeType.CSharp)
                  {
                     nunitClass = testClassFactory.CreateCSharpTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
                  }
                  else if (codeType == UnitTestCodeType.VB)
                  {
                     nunitClass = testClassFactory.CreateVBTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
                  }

                  nunitClass.GenerateTest(codeClass, property);

                  //we sure expect just one class, the first class we find matching
                  return;
               }
            }
         }

         //if we have reached this point then it means that we have not been able to locate a parent class in our
         //unit test project, then we simply create a class unit test

         OnCodeClassSelection(testFramework, (CodeClass)property.Parent, (CodeElement)property, applicationObject, unitTestProject, codeType);
      }
Пример #6
0
      internal static void HandelCodeClassSelection(AbstractTestFramework testFramework, CodeFunction function, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         Project parentProject = ProjectExaminar.GetCodeClassParentProject((CodeClass)function.Parent);

         Project unitTestProject = ProjectExaminar.GetUnitTestProject(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);

         //We might or might not use this factory, we don't know at this point
         AbstractTestClassFactory testClassFactory = new NUnitTestClassFactory();

         foreach (ProjectItem projectItem in unitTestProject.ProjectItems)
         {
            System.Collections.Generic.List<CodeClass> lstCodeClasses =
                 ProjectItemExaminor.GetCodeClasses(projectItem.FileCodeModel);

            foreach (CodeClass codeClass in lstCodeClasses)
            {
               CodeClass parentClass = (CodeClass)function.Parent;

               string className = codeClass.Name;
               string testClassName = ((CodeClass)function.Parent).Name + testFramework.TestClassFixturePostFix;
               
               //find the parent for function passed in
               //if (codeClass.Name.Equals(((CodeClass)function.Parent).Name + CommonStrings.DEFAULT_STRING_SEPERATOR + UTGHelper.CommonStrings.DEFAULT_UNIT_TEST_CLASS_POSTFIX))
               if (className.Equals(testClassName) == true)
               {
                  //if found 
                  AbstractTestClass nunitClass = null;

                  if (codeType == UnitTestCodeType.CSharp)
                  {
                     nunitClass = testClassFactory.CreateCSharpTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
                  }
                  else if (codeType == UnitTestCodeType.VB)
                  {
                     nunitClass = testClassFactory.CreateVBTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
                  }

                  nunitClass.GenerateTest(codeClass, function);

                  //we sure expect just one class, the first class we find matching
                  return;
               }
            }
         }

         //if we have reached this point then it means that we have not been able to locate a parent class in our
         //unit test project, then we simply create a class unit test

         OnCodeClassSelection(testFramework, (CodeClass)function.Parent, (CodeElement)function, applicationObject, unitTestProject, codeType);
      }
Пример #7
0
      //OK
      internal static void OnCodeClassSelection(AbstractTestFramework testFramework, CodeClass codeClass, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         //We can only test public methods
         if (codeClass.Access != vsCMAccess.vsCMAccessPublic)
            return;

         Project parentProject = ProjectExaminar.GetCodeClassParentProject(codeClass);

         Project unitTestProject = ProjectExaminar.GetUnitTestProject(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);

         if (unitTestProject != null && !CanGenerateHandleCodeClass(testFramework.TestClassFixturePostFix, codeClass, unitTestProject)) {
            UTGHelper.ErrorHandler.ShowMessage(CommonUserMessages.MSG_TEST_ALREADY_EXISTS);
            OnGenerationFaliure(applicationObject);
            return;
         }

         string path = ProjectManager.GetUnitTestProjectPath(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);

         path = UTGHelper.IO.GetFilePath(path);

         System.IO.DirectoryInfo newDirectoryInfo;

         string fullPath = System.IO.Path.Combine(path, parentProject.Name + testFramework.TestProjectPostFix);

         try{
            //Another way of doing this would be to try and find this project in current open solution saving us the exception
            newDirectoryInfo =
               System.IO.Directory.CreateDirectory(fullPath);
         }
         catch (Exception ex){
            Logger.LogException(ex);
         }
         finally{
            //Either case we have one by now so lets get its directory information
            newDirectoryInfo = new System.IO.DirectoryInfo(fullPath);
         }

         //If for whatever reason we are still failing then simply quit this 
         if (newDirectoryInfo == null)
         {
            OnGenerationFaliure(applicationObject);

            throw new Exception(string.Format("Unable to create new Directory {0}", System.IO.Path.Combine(path, parentProject.Name + testFramework.TestProjectPostFix)));
         }

         if (unitTestProject == null)
         {
            try{
               unitTestProject = ProjectManager.CreateAndAddUnitTestProject((Solution2)applicationObject.Solution, parentProject.Name + testFramework.TestProjectPostFix, newDirectoryInfo.FullName, codeType/*, license*/);
            }
            catch (Exception ex){
               Logger.LogException(ex);

               OnGenerationFaliure(applicationObject);

               throw;
            }
         }

         //Rethink this bit
         //Since above operation fails in either case then try getting the new Unit Test Project if created and added ok..
         if (unitTestProject == null) {
            unitTestProject = ProjectExaminar.GetUnitTestProject(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);
         }

         if (unitTestProject == null) {
            OnGenerationFaliure(applicationObject);
            throw new Exception("Can not create new UnitTest Project");
         }
 
         AbstractTestClassFactory testClassFactory = new NUnitTestClassFactory();

         AbstractTestClass nunitClass = null;

         if (codeType == UnitTestCodeType.CSharp) {
            nunitClass = testClassFactory.CreateCSharpTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
         }
         else if (codeType == UnitTestCodeType.VB) {
            nunitClass = testClassFactory.CreateVBTestClass(codeClass.Namespace.FullName, codeClass.Name, codeClass.IsAbstract);
         }

         if (!nunitClass.write(newDirectoryInfo.FullName, testFramework.TestClassFixturePostFix)) {
            OnGenerationFaliure(applicationObject);
            return;
         }
        
         //add new class to project
         ProjectItem projectItem = ProjectManager.AddClassToProject(applicationObject, unitTestProject, null, nunitClass.FullName);

         List<CodeClass> lstCodeClasses = ProjectItemExaminor.GetCodeClasses(projectItem.FileCodeModel);

         if (lstCodeClasses == null || lstCodeClasses.Count == 0) {
            OnGenerationFaliure(applicationObject);
            return;
         }

         CodeClass unitTestCodeClass = lstCodeClasses[0];

         //passed this point the actual object will take care of it self.
         nunitClass.GenerateTest(unitTestCodeClass, codeClass);

         //To consider: this should be handled by an object that inherits from project type
         copyReferences(testFramework, parentProject, unitTestProject);

         applicationObject.ItemOperations.OpenFile(nunitClass.FullName, EnvDTE.Constants.vsViewKindAny);
      }
Пример #8
0
      private static void OnCodeClassSelection(AbstractTestFramework testFramework, CodeProperty ce, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         Project parentProject = ProjectExaminar.GetCodeClassParentProject((CodeClass)ce.Parent);

         Project unitTestProject = ProjectExaminar.GetUnitTestProject(parentProject.Name, applicationObject, testFramework.TestProjectPostFix);

         if (unitTestProject == null) {

            OnCodeClassSelection(testFramework, (CodeClass)ce.Parent, (CodeElement)ce, applicationObject, codeType);
            return;
         }

         //In cases where we can not simply generate automatically (definition already exists) we will
         //ask the user for input, wait on input, then async back to the function actual useful handler
         //HandelCodeClassSelection
         if (!CanGenerateHandleCodeProperty(testFramework.TestClassFixturePostFix, (CodeClass)ce.Parent, ce, unitTestProject))
         {
            UTGHelper.UserAlertActionRequired tvUserAlertActionRequired = new UserAlertActionRequired(
               "Property definition already exits! What would you like to do?",
               typeof(CodeProperty),
               (CodeElement)ce,
               ref applicationObject,
               codeType,
               testFramework);

            if (!tvUserAlertActionRequired.IsDisposed)
            {
               tvUserAlertActionRequired.FormClosed += new System.Windows.Forms.FormClosedEventHandler(tvUserAlertActionRequired_FormClosed);

               tvUserAlertActionRequired.Show();
            }
            else
            {
               HandelCodeClassSelection(testFramework, ce, applicationObject, codeType);
            }

            return;
         }

         //otherwise simply call HandelCodeClassSelection
         HandelCodeClassSelection(testFramework, ce, applicationObject, codeType);

      }
Пример #9
0
      public static void OnCodeElementSelection(AbstractTestFramework testFramework, CodeElement ce, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         OnGenerationStart(applicationObject);

         if (ce is CodeNamespace)
         {
            ErrorHandler.ShowMessage(string.Format("You have selected the namesapce {0}! Currently there are no features which support namespaces.", ((CodeNamespace)ce).FullName));
         }
         //else if (codeClass != null)
         else if (ce is CodeClass)
         {
            if ( ((CodeClass)ce).Access != vsCMAccess.vsCMAccessPublic)
               return;

            OnCodeClassSelection(testFramework, (CodeClass)ce, applicationObject, codeType);
         }
         //else if (codeFunction != null)
         else if (ce is CodeFunction)
         {
            if ( ((CodeFunction)ce).Access != vsCMAccess.vsCMAccessPublic)
               return;

            OnCodeClassSelection(testFramework, (CodeFunction)ce, applicationObject, codeType);
         }
         else if (ce is CodeEnum)
         {
            if ( ((CodeEnum)ce).Access != vsCMAccess.vsCMAccessPublic)
               return;

            ErrorHandler.ShowMessage(string.Format("You have selected the Enum {0}!", ((CodeEnum)ce).FullName));
         }
         else if (ce is CodeStruct)
         {
            ErrorHandler.ShowMessage(string.Format("You have selected the Structure {0}!", ((CodeStruct)ce).FullName));
         }
         else if (ce is CodeProperty)
         {
            if ( ((CodeProperty)ce).Access != vsCMAccess.vsCMAccessPublic)
               return;

            OnCodeClassSelection(testFramework, (CodeProperty)ce, applicationObject, codeType);
         }
         else
         {
            ErrorHandler.ShowMessage(UTGHelper.CommonErrors.ERR_ILLEGAL_TEXT_SELECTION);
         }
      }
Пример #10
0
      public static void OnCodeElementSelection(AbstractTestFramework testFramework, Project project, DTE2 applicationObject, UnitTestCodeType codeType)
      {
         try
         {
            foreach (ProjectItem pItem in project.ProjectItems)
            {
               try
               {
                 
                  foreach (CodeElement tvCodeElementOutter in pItem.FileCodeModel.CodeElements)
                  {
                     if (tvCodeElementOutter is CodeNamespace)
                     {
                        try
                        {
                           foreach (CodeElement tvCodeElement in ((CodeNamespace)tvCodeElementOutter).Members)
                           {
                              if (tvCodeElement != null &&
                                 tvCodeElement is CodeClass
                                 )
                              {
                                 try
                                 {
                                    if( ((CodeClass)tvCodeElement).Access == vsCMAccess.vsCMAccessPublic)
                                       OnCodeClassSelection(testFramework, (CodeClass)tvCodeElement, applicationObject, codeType/*, license*/);
                                 }
                                 catch (Exception ex)
                                 {
                                    Logger.LogException(ex);

                                    //ignore
                                    UTGHelper.ErrorHandler.HandleException(ex);
                                    return;
                                 }
                              }
                           }
                        }
                        catch (Exception ex)
                        {
                           //ignore this 
                           Logger.LogException(ex);

                        }
                     }
                     else if (tvCodeElementOutter is CodeClass)
                     {
                        try
                        {
                           if (((CodeClass)tvCodeElementOutter).Access == vsCMAccess.vsCMAccessPublic)
                              OnCodeClassSelection(testFramework, (CodeClass)tvCodeElementOutter, applicationObject, codeType/*, license*/);
                        }
                        catch (Exception ex)
                        {
                           Logger.LogException(ex);

                           //ignore
                           UTGHelper.ErrorHandler.HandleException(ex);
                           return;
                        }
                     }

                  }//if (tvCodeElementOutter is CodeNamespace)
               }
               catch (Exception ex)
               {
                  //ignore this on;
                  Logger.LogException(ex);
               }

            }//foreach (ProjectItem pItem in project.ProjectItems)

         }//first try
         catch (Exception ex)
         {
            //ignore this on;throw;
            Logger.LogException(ex);
         }
      }
Пример #11
0
 internal OpenCoverFramework(string binariesDirectoryPath, string consoleDirectoriesPath, string commandsDirectoryPath, AbstractTestFramework testFramework)
 {
    this.binariesDirectory = binariesDirectoryPath;
    this.consoleDirectory = consoleDirectoriesPath;
    this.commandsDirectory = commandsDirectoryPath;
    this.testFramework = testFramework;
 }
Пример #12
0
 public static AbstractCodeCoverageFramework CreateOpenCoverFramework(string binariesDirectoryPath, string consoleDirectoriesPath, string commandsDirectoryPath, AbstractTestFramework testFramework)
 {
    return new OpenCoverFramework(binariesDirectoryPath, consoleDirectoriesPath, commandsDirectoryPath, testFramework);
 }