Пример #1
0
        public static void CheckSql(this UnitTestGenerator tg)
        {
            var fr = tg.For <Sql>();

            fr.Text();
            fr.Parameters();
        }
Пример #2
0
        protected override async void GenerateEditorTxt(object sender, EventArgs e)
        {
            DisableUIStuff();
            var promptValue1 = _classNameCombo1.Text;

            _classNameCombo1.DroppedDown = false;

            if (string.IsNullOrWhiteSpace(promptValue1))
            {
                ShowError("Class name blank");
            }

            var selectedClass = _classes.FirstOrDefault(x => x.FullName == promptValue1);

            if (selectedClass == null)
            {
                ShowError("Class not found");
            }

            _editor.Text = @"        . . . . o o o o o
               _____      o       ____________
      ____====  ]OO|_n_n__][.     |Generating|
     [________]_|__|________)<    |Unit Tests|
      oo    oo  'oo OOOO-| oo\\_  ~~~~~|~~~~~~
  +--+--+--+--+--+--+--+--+-$1-+--+--+--+--+

";

            var genner = new UnitTestGenerator(selectedClass, _dte, _editor);

            _editor.Text = await genner.Gen(selectedClass, _opts);

            EnableUIStuff();
        }
Пример #3
0
        public void GenerateUnitTestsLogic(List <string> projClasses)
        {
            var dte = (DTE2)Microsoft.VisualStudio.Shell.ServiceProvider
                      .GlobalProvider.GetService(typeof(EnvDTE.DTE));
            var selectedProjectName = GetSelectedProjectName(dte);
            var unitTestProjectName = string.Format("{0}_Tests", selectedProjectName);

            // discover solution/project types and create an object factory
            var solutionFullPath = GetSolutionFullPath(dte);

            // generate unit tests for the analyzed project
            var    generatedTestClassesDirectory = CreateUnitTestsProject(dte, unitTestProjectName);
            string packagesPath = GetSolutionPackagesFolder(dte);

            var unitTestGenerator = new UnitTestGenerator(generatedTestClassesDirectory,
                                                          packagesPath, selectedProjectName);
            List <string> testClasses = unitTestGenerator.GenerateUnitTestsForClass(solutionFullPath,
                                                                                    unitTestProjectName, projClasses);

            // add test classes to project
            string csprojPath = string.Format(@"{0}\\{1}\\{2}{3}", GetSolutionPath(dte),
                                              unitTestProjectName, unitTestProjectName, ".csproj");

            var p = new Microsoft.Build.Evaluation.Project(csprojPath);

            foreach (string generatedTestClass in testClasses)
            {
                p.AddItem("Compile", generatedTestClass);
            }
            p.Save();
        }
Пример #4
0
 public static void CheckOrm(this UnitTestGenerator tg)
 {
     tg.For <Commands.Add.Add>().Basic();
     tg.For <Commands.Delete.Delete>().Basic();
     tg.For <Commands.DeletePk.DeletePk>().Basic();
     tg.For <Commands.Update.Update>().Basic();
 }
Пример #5
0
        public void Generate(TestData data)
        {
            var template = new UnitTestGenerator();

            template.Session = new Dictionary <string, object>();
            template.Session.Add("data", data);
            template.Initialize();
            var code = template.TransformText();

            OutputUnitTest(code);
        }
Пример #6
0
        public static GenerationOutput GenerateUnitTest(this Trace trace, string className, string ns, Action <UnitTestGenerator> config = null)
        {
            UnitTestGenerator tg = new UnitTestGenerator();

            config(tg);

            var generator = new CSharpUnitTestGenerator(className, ns);

            generator.Before();
            tg.Proceed(trace.Commands, generator);
            generator.After();
            return(new GenerationOutput(generator));
        }
Пример #7
0
        public async void GenerateCode()
        {
            var unitTestGenerator = new UnitTestGenerator();

            try
            {
                IsGenerating = true;
                await unitTestGenerator.GenerateUnitTestsAsync(DllPath,
                                                               UseMsTest?TestFrameworks.MsTest : TestFrameworks.NUnit, MockFrameworks.Moq, OutputDirectory);
            }
            catch (Exception ex)
            {
                _dialogService.ShowInfoDialog($"Failed to generate unit tests: {ex.Message}");
                return;
            }
            finally
            {
                IsGenerating = false;
            }

            _dialogService.ShowInfoDialog("Generated unit tests successfully!");
        }
Пример #8
0
 public static void Basics(this UnitTestGenerator tg)
 {
     tg.For <CommandBase>().Basic();
     tg.For <Comment>().Basic();
 }