FrameworkController provides a facade for use in loading, browsing and running tests without requiring a reference to the NUnit framework. All calls are encapsulated in constructors for this class and its nested classes, which only require the types of the Common Type System as arguments. The controller supports four actions: Load, Explore, Count and Run. They are intended to be called by a driver, which should allow for proper sequencing of calls. Load must be called before any of the other actions. The driver may support other actions, such as reload on run, by combining these calls.
Inheritance: LongLivedMarshalByRefObject
        public void CountTestsAction_FileNotFound_ReturnsZero()
        {
            var controller = new FrameworkController(MISSING_FILE, "ID", _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.CountTestsAction(controller, EMPTY_FILTER, _handler);
            Assert.That(_handler.GetCallbackResult(), Is.EqualTo("0"));
        }
        public void CreateController()
        {
#if SILVERLIGHT || PORTABLE
            _controller = new FrameworkController(MOCK_ASSEMBLY_NAME, "ID", _settings);
#else
            _controller = new FrameworkController(MOCK_ASSEMBLY_PATH, "ID", _settings);
#endif
            _handler = new CallbackEventHandler();
        }
Beispiel #3
0
        public void CreateController()
        {
#if PORTABLE || NETSTANDARD1_6
            _controller = new FrameworkController(typeof(MockAssembly).GetTypeInfo().Assembly, "ID", _settings);
#else
            _controller = new FrameworkController(MOCK_ASSEMBLY_PATH, "ID", _settings);
#endif
            _handler = new CallbackEventHandler();
        }
        public void CreateController()
        {
#if SILVERLIGHT
            _controller = new FrameworkController(MOCK_ASSEMBLY_NAME, "ID", _settings);
#else
            _controller = new FrameworkController(MOCK_ASSEMBLY_PATH, "ID", _settings);
#endif
            _handler = new CallbackEventHandler();
        }
        public void CreateController()
        {
#if PORTABLE || NETSTANDARD1_6
            _controller = new FrameworkController(typeof(MockAssembly).GetTypeInfo().Assembly, "ID", _settings);
#else
            _controller = new FrameworkController(MOCK_ASSEMBLY_PATH, "ID", _settings);
#endif
            _handler = new CallbackEventHandler();
        }
Beispiel #6
0
        public static void TestSchemaMatches()
        {
            Assert.Multiple(() =>
            {
                var controller = new FrameworkController("mock-assembly", Test.IdPrefix, new Dictionary <string, string>());
                var loadXml    = controller.LoadTests();
                var exploreXml = controller.ExploreTests(null);

                SchemaTestUtils.AssertValidXml(loadXml, "Test.xsd");
                SchemaTestUtils.AssertValidXml(exploreXml, "Test.xsd");
            });
        }
Beispiel #7
0
        public void LoadTestsAction_Assembly_ReturnsRunnableSuite()
        {
            _controller = new FrameworkController(typeof(MockAssembly).GetTypeInfo().Assembly, "ID", _settings);
            new FrameworkController.LoadTestsAction(_controller, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME).IgnoreCase);
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
Beispiel #8
0
        public void InsertSettingsElement_SettingIsValue_CreatesASettingElementPerKey()
        {
            var outerNode    = new TNode("test");
            var testSettings = new Dictionary <string, object>
            {
                ["key1"] = "value1",
                ["key2"] = "value2"
            };

            var inserted = FrameworkController.InsertSettingsElement(outerNode, testSettings);

            // in parallel, an additional node is added with number of test workers
            Assert.That(inserted.ChildNodes.Count, Is.EqualTo(3));
        }
Beispiel #9
0
        public void InsertSettingsElement_SettingIsDictionary_CreatesEntriesForDictionaryElements(string value)
        {
            var outerNode    = new TNode("test");
            var testSettings = new Dictionary <string, object>
            {
                ["outerkey"] = new Dictionary <string, object> {
                    { "key1", "value1" }, { "key2", value }
                }
            };

            var inserted    = FrameworkController.InsertSettingsElement(outerNode, testSettings);
            var settingNode = inserted.FirstChild;

            Assert.That(settingNode.ChildNodes.Count, Is.EqualTo(2));
        }
        public void ExploreTestsAction_FileNotFound_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(MISSING_FILE, _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.ExploreTestsAction(controller, EMPTY_FILTER, _handler);
            var result = GetXmlResult();

            Assert.That(result.Name, Is.EqualTo("test-suite"));
            Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            Assert.That(GetSkipReason(result), Is.StringStarting("Could not load").And.Contains(MISSING_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Result should not have child tests");
        }
Beispiel #11
0
        public void RunAsyncAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunAsyncAction(controller, EMPTY_FILTER, _handler);
            //var result = GetXmlResult();

            //Assert.That(result.Name, Is.EqualTo("test-suite"));
            //Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            //Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            //Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            //Assert.That(GetSkipReason(result), Does.StartWith("Could not load").And.Contains(BAD_FILE));
            //Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
Beispiel #12
0
        public void RunAsyncAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, "ID", _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunAsyncAction(controller, EMPTY_FILTER, _handler);
            //var result = TNode.FromXml(_handler.GetCallbackResult());

            //Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            //Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            //Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            //Assert.That(result.Attributes["testcasecount"], Is.EqualTo("0"));
            // Minimal check here to allow for platform differences
            //Assert.That(GetSkipReason(result), Contains.Substring(BAD_FILE));
            //Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
        public void RunTestsAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunTestsAction(controller, EMPTY_FILTER, _handler);
            var result = GetXmlResult();

            Assert.That(result.Name, Is.EqualTo("test-suite"));
            Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            Assert.That(GetSkipReason(result), Does.StartWith("Could not load").And.Contains(BAD_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
            // Issue: tests look all the same, duplicated but minor differences
            // Navigation smell because I do not know where to go because all looks the same
        }
Beispiel #14
0
        public void InsertSettingsElement_SettingIsValue_SetsKeyAndValueAsAttributes(string value)
        {
            var outerNode    = new TNode("test");
            var testSettings = new Dictionary <string, object>
            {
                ["key1"] = "value1",
                ["key2"] = value
            };

            var inserted = FrameworkController.InsertSettingsElement(outerNode, testSettings);

            Assert.That(inserted.ChildNodes[0].Attributes["name"], Is.EqualTo("key1"));
            Assert.That(inserted.ChildNodes[0].Attributes["value"], Is.EqualTo("value1"));

            Assert.That(inserted.ChildNodes[1].Attributes["name"], Is.EqualTo("key2"));
            Assert.That(inserted.ChildNodes[1].Attributes["value"], Is.EqualTo(value));
        }
        public void ExploreTestsAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.ExploreTestsAction(controller, EMPTY_FILTER, _handler);
            var result = GetXmlResult();

            Assert.That(result.Name, Is.EqualTo("test-suite"));
            Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            Assert.That(GetSkipReason(result), Does.StartWith("Could not load").And.Contains(BAD_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Result should not have child tests");
            // duplication is not a navigation smell in itself
            // bad readability is not a navigation smell unless on method calls (but not on deepest low level)
            // Idea: long method is navigation smell because I need to scroll and scroll
        }
Beispiel #16
0
        public void RunTestsAction_FileNotFound_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(MISSING_FILE, "ID", _settings);

            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunTestsAction(controller, EMPTY_FILTER, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo("0"));
            // Minimal check here to allow for platform differences
#if NETCOREAPP1_1
            Assert.That(GetSkipReason(result), Contains.Substring("The system cannot find the file specified."));
#else
            Assert.That(GetSkipReason(result), Contains.Substring(MISSING_NAME));
#endif
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
Beispiel #17
0
        public void InsertSettingsElement_SettingIsDictionary_CreatesEntriesWithKeysAndValuesFromDictionary(string value)
        {
            var outerNode    = new TNode("test");
            var testSettings = new Dictionary <string, object>();

            testSettings.Add("outerkey", new Dictionary <string, object> {
                { "key1", "value1" }, { "key2", value }
            });

            var inserted    = FrameworkController.InsertSettingsElement(outerNode, testSettings);
            var settingNode = inserted.FirstChild;

            var key1Node = settingNode.ChildNodes[0];

            Assert.That(key1Node.Attributes["key"], Is.EqualTo("key1"));
            Assert.That(key1Node.Attributes["value"], Is.EqualTo("value1"));

            var key2Node = settingNode.ChildNodes[1];

            Assert.That(key2Node.Attributes["key"], Is.EqualTo("key2"));
            Assert.That(key2Node.Attributes["value"], Is.EqualTo(value));
        }
Beispiel #18
0
        public void InsertSettingsElement_MixedSettings_CreatesCorrectSubNodes(string value)
        {
            var outerNode    = new TNode("test");
            var testSettings = new Dictionary <string, object>
            {
                ["key1"] = "value1",
                ["key2"] = new Dictionary <string, object> {
                    ["innerkey"] = value
                }
            };

            var inserted = FrameworkController.InsertSettingsElement(outerNode, testSettings);

            // in parallel, an additional node is added with number of test workers
            Assert.That(inserted.ChildNodes.Count, Is.EqualTo(3));
            Assert.That(inserted.ChildNodes[0].Attributes["name"], Is.EqualTo("key1"));
            Assert.That(inserted.ChildNodes[0].Attributes["value"], Is.EqualTo("value1"));

            var innerNode = inserted.ChildNodes[1].FirstChild;

            Assert.That(innerNode.Attributes["key"], Is.EqualTo("innerkey"));
            Assert.That(innerNode.Attributes["value"], Is.EqualTo(value));
        }
Beispiel #19
0
 /// <summary>
 /// Construct a StopRunAction and stop any ongoing run. If no
 /// run is in process, no error is raised.
 /// </summary>
 /// <param name="controller">The FrameworkController for which a run is to be stopped.</param>
 /// <param name="force">True the stop should be forced, false for a cooperative stop.</param>
 /// <param name="handler">>A callback handler used to report results</param>
 /// <remarks>A forced stop will cause threads and processes to be killed as needed.</remarks>
 public StopRunAction(FrameworkController controller, bool force, object handler)
 {
     controller.StopRun((ICallbackEventHandler)handler, force);
 }
Beispiel #20
0
 /// <summary>
 /// Construct a RunAsyncAction and run all tests in the loaded TestSuite.
 /// </summary>
 /// <param name="controller">A FrameworkController holding the TestSuite to run</param>
 /// <param name="filter">A string containing the XML representation of the filter to use</param>
 /// <param name="handler">A callback handler used to report results</param>
 public RunAsyncAction(FrameworkController controller, string filter, object handler)
 {
     controller.RunAsync((ICallbackEventHandler)handler, filter);
 }
Beispiel #21
0
 /// <summary>
 /// Construct a CountsTestAction and perform the count of test cases.
 /// </summary>
 /// <param name="controller">A FrameworkController holding the TestSuite whose cases are to be counted</param>
 /// <param name="filter">A string containing the XML representation of the filter to use</param>
 /// <param name="handler">A callback handler used to report results</param>
 public CountTestsAction(FrameworkController controller, string filter, object handler)
 {
     controller.CountTests((ICallbackEventHandler)handler, filter);
 }
Beispiel #22
0
 /// <summary>
 /// LoadTestsAction loads the tests in an assembly.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="handler">The callback handler.</param>
 public LoadTestsAction(FrameworkController controller, object handler)
 {
     controller.LoadTests((ICallbackEventHandler)handler);
 }
 public void CreateController()
 {
     _mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY);
     _controller = new FrameworkController(_mockAssemblyPath, _settings);
     _handler = new CallbackEventHandler();
 }
Beispiel #24
0
 /// <summary>
 /// Construct a CountsTestAction and perform the count of test cases.
 /// </summary>
 /// <param name="controller">A FrameworkController holding the TestSuite whose cases are to be counted</param>
 /// <param name="filter">A string containing the XML representation of the filter to use</param>
 /// <param name="handler">A callback handler used to report results</param>
 public CountTestsAction(FrameworkController controller, string filter, object handler) 
 {
     controller.CountTests((ICallbackEventHandler)handler, filter);
 }
Beispiel #25
0
 public void CreateController()
 {
     _mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY);
     _controller       = new FrameworkController(_mockAssemblyPath, _settings);
     _handler          = new CallbackEventHandler();
 }
Beispiel #26
0
        public void LoadTestsAction_Assembly_ReturnsRunnableSuite()
        {
            _controller = new FrameworkController(typeof(MockAssembly).GetTypeInfo().Assembly, "ID", _settings);
            new FrameworkController.LoadTestsAction(_controller, _handler);
            var result = TNode.FromXml(_handler.GetCallbackResult());

            Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            Assert.That(result.Attributes["id"], Is.Not.Null.And.StartWith("ID"));
            Assert.That(result.Attributes["name"], Is.EqualTo(EXPECTED_NAME).IgnoreCase);
            Assert.That(result.Attributes["runstate"], Is.EqualTo("Runnable"));
            Assert.That(result.Attributes["testcasecount"], Is.EqualTo(MockAssembly.Tests.ToString()));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
Beispiel #27
0
 public void CountTestsAction_BadFile_ReturnsZero()
 {
     var controller = new FrameworkController(BAD_FILE, "ID", _settings);
     new FrameworkController.LoadTestsAction(controller, _handler);
     new FrameworkController.CountTestsAction(controller, EMPTY_FILTER, _handler);
     Assert.That(_handler.GetCallbackResult(), Is.EqualTo("0"));
 }
Beispiel #28
0
 /// <summary>
 /// Construct a StopRunAction and stop any ongoing run. If no
 /// run is in process, no error is raised.
 /// </summary>
 /// <param name="controller">The FrameworkController for which a run is to be stopped.</param>
 /// <param name="force">True the stop should be forced, false for a cooperative stop.</param>
 /// <param name="handler">>A callback handler used to report results</param>
 /// <remarks>A forced stop will cause threads and processes to be killed as needed.</remarks>
 public StopRunAction(FrameworkController controller, bool force, object handler)
 {
     controller.StopRun((ICallbackEventHandler)handler, force);
 }
Beispiel #29
0
        public void RunAsyncAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, "ID", _settings);
            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunAsyncAction(controller, EMPTY_FILTER, _handler);
            //var result = TNode.FromXml(_handler.GetCallbackResult());

            //Assert.That(result.Name.ToString(), Is.EqualTo("test-suite"));
            //Assert.That(result.Attributes["type"], Is.EqualTo("Assembly"));
            //Assert.That(result.Attributes["runstate"], Is.EqualTo("NotRunnable"));
            //Assert.That(result.Attributes["testcasecount"], Is.EqualTo("0"));
            // Minimal check here to allow for platform differences
            //Assert.That(GetSkipReason(result), Contains.Substring(BAD_FILE));
            //Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
        public void RunAsyncAction_BadFile_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(BAD_FILE, _settings);
            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.RunAsyncAction(controller, EMPTY_FILTER, _handler);
            //var result = GetXmlResult();

            //Assert.That(result.Name, Is.EqualTo("test-suite"));
            //Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            //Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            //Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            //Assert.That(GetSkipReason(result), Does.StartWith("Could not load").And.Contains(BAD_FILE));
            //Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Load result should not have child tests");
        }
        public void ExploreTestsAction_FileNotFound_ReturnsNonRunnableSuite()
        {
            var controller = new FrameworkController(MISSING_FILE, _settings);
            new FrameworkController.LoadTestsAction(controller, _handler);
            new FrameworkController.ExploreTestsAction(controller, EMPTY_FILTER, _handler);
            var result = GetXmlResult();

            Assert.That(result.Name, Is.EqualTo("test-suite"));
            Assert.That(GetAttribute(result, "type"), Is.EqualTo("Assembly"));
            Assert.That(GetAttribute(result, "runstate"), Is.EqualTo("NotRunnable"));
            Assert.That(GetAttribute(result, "testcasecount"), Is.EqualTo("0"));
            Assert.That(GetSkipReason(result), Is.StringStarting("Could not load").And.Contains(MISSING_FILE));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Result should not have child tests");
        }
Beispiel #32
0
 public void CreateController()
 {
     _controller = new FrameworkController(MOCK_ASSEMBLY_PATH, "ID", _settings);
     _handler    = new CallbackEventHandler();
 }
Beispiel #33
0
 /// <summary>
 /// Construct a RunAsyncAction and run all tests in the loaded TestSuite.
 /// </summary>
 /// <param name="controller">A FrameworkController holding the TestSuite to run</param>
 /// <param name="filter">A string containing the XML representation of the filter to use</param>
 /// <param name="handler">A callback handler used to report results</param>
 public RunAsyncAction(FrameworkController controller, string filter, object handler) 
 {
     controller.RunAsync((ICallbackEventHandler)handler, filter);
 }
Beispiel #34
0
 /// <summary>
 /// LoadTestsAction loads the tests in an assembly.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="handler">The callback handler.</param>
 public LoadTestsAction(FrameworkController controller, object handler)
 {
     controller.LoadTests((ICallbackEventHandler)handler);
 }