public TestSuiteGenerator(TestSuite tSuite, UnitTestCodeWriter unitTestCodeWriter, String namespaceToUse = null, String classAttribute = null)
        {
            this.TestSuite = tSuite;

            CalculateRequiredNamespaces(tSuite);

            UnitTestCodeWriter = unitTestCodeWriter;
            NamespaceToUse = namespaceToUse;
            ClassAttribute = classAttribute;
        }
Esempio n. 2
0
        private void AddTestSuiteToProject(TestSuite testSuite, Project testProject)
        {
            var unitTestsWriter = new NUnitUnitTestCodeWriter();
            var testSuiteGenerator = new TestSuiteGenerator(testSuite, unitTestsWriter, testProject.Name, "[TestFixture]");

            var testSuiteFilePath =
                Path.Combine(
            new string[]{
                testProject.FullName.Substring(0, testProject.FullName.LastIndexOf('\\')),
                                               testSuite.Type.FullName + ".Tests.cs"
            }
            );
            var file = File.Create(testSuiteFilePath);
            var streamWriter = new StreamWriter(file);
            streamWriter.Write(testSuiteGenerator.TransformText());
            streamWriter.Close();
            file.Close();

            var item =testProject.ProjectItems.AddFromFile(testSuiteFilePath);
            item.Open(Constants.vsViewKindCode);
            item.Document.Activate();
        }
        private void CalculateRequiredNamespaces(TestSuite tSuite)
        {
            _mNamespacesUsed.Add(tSuite.Type.Namespace);
            foreach (var unitTest in tSuite.Tests)
            {
                ExceptionThrowingTest exceptionThrowingTest = unitTest as ExceptionThrowingTest;
                MethodTest methodTest = unitTest as MethodTest;

                if(exceptionThrowingTest != null)
                {
                    _mNamespacesUsed.Add(exceptionThrowingTest.Exception.GetType().Namespace);
                }
                else if (methodTest != null && methodTest.Result != null)
                {
                    _mNamespacesUsed.Add(methodTest.Result.GetType().Namespace);
                }

                if(unitTest.Arguments != null)
                    AddArgumentTypes(unitTest.Arguments);
            }
        }
 public TestSuiteGenerator(TestSuite tSuite, UnitTestCodeWriter unitTestCodeWriter)
     : this(tSuite, unitTestCodeWriter, tSuite.Type + ".Tests", "[TestFixture]")
 {
 }