Beispiel #1
0
 public RevitTestEventListener(DynamoRevitTest test)
 {
     _dynamoRevitTest = test;
 }
Beispiel #2
0
 public RevitTestEventListener(DynamoRevitTest test)
 {
     _dynamoRevitTest = test;
 }
Beispiel #3
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            DynamoLogger.Instance.StartLogging();

            // Get the StringStringMap class which can write support into.
            IDictionary <string, string> dataMap = revit.JournalData;

            try
            {
                m_revit = revit.Application;
                m_doc   = m_revit.ActiveUIDocument;

                #region default level

                Level defaultLevel = null;
                var   fecLevel     = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                defaultLevel = fecLevel.ToElements()[0] as Level;

                #endregion

                dynRevitSettings.Revit        = m_revit;
                dynRevitSettings.Doc          = m_doc;
                dynRevitSettings.DefaultLevel = defaultLevel;

                //create dynamo
                Regex  r       = new Regex(@"\b(Autodesk |Structure |MEP |Architecture )\b");
                string context = r.Replace(m_revit.Application.VersionName, "");

                var dynamoController = new DynamoController_Revit(DynamoRevitApp.env, DynamoRevitApp.updater, typeof(DynamoRevitViewModel), context);

                //flag to run evalauation synchronously, helps to
                //avoid threading issues when testing.
                dynamoController.Testing = true;

                //execute the tests
                Results = new DynamoRevitTestRunner();
                //var resultsView = new DynamoRevitTestResultsView();
                //resultsView.DataContext = Results;

                //http://stackoverflow.com/questions/2798561/how-to-run-nunit-from-my-code
                string assLocation = Assembly.GetExecutingAssembly().Location;
                var    fi          = new FileInfo(assLocation);
                string testLoc     = Path.Combine(fi.DirectoryName, @"DynamoRevitTester.dll");

                //Tests must be executed on the main thread in order to access the Revit API.
                //NUnit's SimpleTestRunner runs the tests on the main thread
                //http://stackoverflow.com/questions/16216011/nunit-c-run-specific-tests-through-coding?rq=1
                CoreExtensions.Host.InitializeService();
                var runner  = new SimpleTestRunner();
                var builder = new TestSuiteBuilder();
                var package = new TestPackage("DynamoRevitTests", new List <string>()
                {
                    testLoc
                });
                runner.Load(package);
                TestSuite   suite   = builder.Build(package);
                TestFixture fixture = null;
                FindFixtureByName(out fixture, suite, "DynamoRevitTests");
                if (fixture == null)
                {
                    throw new Exception("Could not find DynamoRevitTests fixture.");
                }

                //foreach (var t in fixture.Tests)
                //{
                //    if (t is ParameterizedMethodSuite)
                //    {
                //        var paramSuite = t as ParameterizedMethodSuite;
                //        foreach (var tInner in paramSuite.Tests)
                //        {
                //            if (tInner is TestMethod)
                //                Results.Results.Add(new DynamoRevitTest(tInner as TestMethod));
                //        }
                //    }
                //    else if (t is TestMethod)
                //        Results.Results.Add(new DynamoRevitTest(t as TestMethod));
                //}

                //resultsView.ShowDialog();

                //for testing
                //if the journal file contains data
                bool canReadData = (0 < dataMap.Count) ? true : false;
                if (canReadData)
                {
                    //revit.Application.OpenAndActivateDocument(dataMap["dynamoModel"]);
                    //dynamoController.DynamoViewModel.OpenCommand.Execute(dataMap["dynamoGraph"]);
                    //dynamoController.DynamoViewModel.RunExpressionCommand.Execute(null);

                    TestMethod t = FindTestByName(fixture, dataMap["dynamoTestName"]);
                    if (t != null)
                    {
                        //Results.Results.Add(new DynamoRevitTest(t as TestMethod));
                        //Results.RunAllTests(null);
                        var dynTest = new DynamoRevitTest(t as TestMethod);
                        dynTest.Run(null);
                        dynTest.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(Result.Failed);
            }

            return(Result.Succeeded);
        }