/// <summary> /// Discovers the tests. /// </summary> private void DiscoverTests() { System.Threading.Tasks.Task.Factory.StartNew(new Action(() => { var potentialTestDLLs = IDEHelper.GetPotentialTestDLLs(); var testDiscoverer = new Discoverer(potentialTestDLLs); testDiscoverer.Discover(UpdateTreeView); })); }
public void TestDiscoverer() { var engine = CreateEngine(); engine.Listener.ClearBindings(); var serverEndPoint = new IPEndPoint(IPAddress.Any, Port.NextId); engine.Listener.AddBinding(serverEndPoint); engine.Start(); try { var signal = new AutoResetEvent(false); var discoverer = new Discoverer(); discoverer.AgentFound += (sender, args) => { Assert.True(args.Agent.Address.ToString() != "0.0.0.0"); signal.Set(); }; discoverer.Discover(VersionCode.V1, new IPEndPoint(IPAddress.Broadcast, serverEndPoint.Port), new OctetString("public"), 3000); signal.WaitOne(); signal.Reset(); discoverer.Discover(VersionCode.V2, new IPEndPoint(IPAddress.Broadcast, serverEndPoint.Port), new OctetString("public"), 3000); signal.WaitOne(); signal.Reset(); discoverer.Discover(VersionCode.V3, new IPEndPoint(IPAddress.Broadcast, serverEndPoint.Port), null, 3000); signal.WaitOne(); } finally { if (SnmpMessageExtension.IsRunningOnWindows) { engine.Stop(); } } }
public void Method_with_scenario_wrong_discoverer() { ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_invalid_scenario_wrong_discoverer)); var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute); testCases.Should().NotBeNull(); testCases.Count().Should().Be(1); testCases.First().Should().BeOfType <ExecutionErrorScenarioTestCase>(); }
public static void Main(string[] args) { if (args.Length != 0) { return; } Discoverer discoverer = new Discoverer(); discoverer.AgentFound += DiscovererAgentFound; Console.WriteLine("v1 discovery"); discoverer.Discover(VersionCode.V1, new IPEndPoint(IPAddress.Broadcast, 161), new OctetString("public"), 6000); Console.WriteLine("v2 discovery"); discoverer.Discover(VersionCode.V2, new IPEndPoint(IPAddress.Broadcast, 161), new OctetString("public"), 6000); Console.WriteLine("v3 discovery"); discoverer.Discover(VersionCode.V3, new IPEndPoint(IPAddress.Broadcast, 161), null, 6000); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public void Method_with_one_scenario() { ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_with_one_scenario)); var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute); testCases.Should().NotBeNull(); testCases.Count().Should().Be(1); testCases.First().Should().BeOfType <MultipleScenariosTestCase>(); }
public void Method_without_scenarios(bool preEnumerateTestCases) { Discoverer.PreEnumerateTestCases = preEnumerateTestCases; ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_without_scenarios)); var testCases = Discoverer.Discover(Options, testMethod, ExpectThatAttribute); testCases.Should().NotBeNull(); testCases.Count().Should().Be(1); testCases.First().Should().BeOfType <ExecutionErrorTestCase>(); }
private void FindDevices() { IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, 161); OctetString octetString = new OctetString("public"); discoverer.AgentFound += new EventHandler <AgentFoundEventArgs>(DeviceFoundV1); discoverer.Discover(VersionCode.V1, endPoint, octetString, 9000); //discoverer.AgentFound += new EventHandler<AgentFoundEventArgs>(DeviceFoundV2); //discoverer.Discover(VersionCode.V2, endPoint, octetString, 9000); //discoverer.AgentFound += new EventHandler<AgentFoundEventArgs>(DeviceFoundV3); //discoverer.Discover(VersionCode.V3, endPoint, null, 9000); }
public void GetBaseNotAuthorizedTest() { authMoq.Setup(x => x.IsAuthorized(It.IsAny <AuthorizeAttributes>())).Returns(false); var explorer = new Discoverer(new Extractor(), new Settings { }); var nodes = explorer.Discover(System.Reflection.Assembly.GetAssembly(GetType()).FullName); var local = nodes.Where(x => x.Key.Contains(nameof(Discovery.Tests.DiscovererTests))); var parser = new Parser(authMoq.Object, routeMoq.Object); var entries = parser.GetBase(local); Assert.AreEqual(0, entries.Count()); }
public void Method_with_skip_flag(bool preEnumerateTestCases) { Discoverer.PreEnumerateTestCases = preEnumerateTestCases; ITestMethod testMethod = XunitMocks.TestMethod(typeof(XunitExtensionsTestCases), nameof(XunitExtensionsTestCases.Method_without_scenarios)); var skippedExpectThatAttribute = XunitMocks.ExpectThatAttribute(null, "Should be skipped"); var testCases = Discoverer.Discover(Options, testMethod, skippedExpectThatAttribute); testCases.Should().NotBeNull(); testCases.Count().Should().Be(1); testCases.First().Should().BeOfType <XunitTestCase>(); }
public void GetNotAuthorizedLinksTest() { authMoq.Setup(x => x.IsAuthorized(It.IsAny <AuthorizeAttributes>())).Returns(false); var explorer = new Discoverer(new Extractor(), new Settings { }); var nodes = explorer.Discover(System.Reflection.Assembly.GetAssembly(GetType()).FullName); var local = nodes.Where(x => x.Key.Contains(nameof(Discovery.Tests.DiscovererTests))); var parser = new Parser(authMoq.Object, routeMoq.Object); var method = typeof(Discovery.Tests.DiscovererTests).GetMethods().First(x => x.Name == nameof(Discovery.Tests.DiscovererTests.Stub_Overloaded_CheckMethodParametersTest) && x.GetParameters().Length == 0); var entries = parser.GetLinks(explorer.GetKey(method), local); Assert.AreEqual(0, entries.Count()); }
public void DiscoverSelfReferential() { DiscoverableParent parent = new DiscoverableParent(); parent.Parent = new DiscoverableParent(); IList <IDiscoverableParent> list = Discoverer.Discover <IDiscoverableParent>(parent); Assert.Equal(2, list.Count); parent.Parent = parent; list = Discoverer.Discover <IDiscoverableParent>(parent); Assert.Equal(1, list.Count); }
public void Discover_Finds_Regular_Test_Fixture_And_Method() { // Arrange var discoverer = new Discoverer(new List<string> { TestAssemblyLocation }); // Act var discoveredTests = discoverer.Discover(); // Assert discoveredTests.Should().NotBeNullOrEmpty(); var discoveredTest = discoveredTests.FirstOrDefault(x => x.Name == typeof(RegularTestClass).Name); discoveredTest.Should().NotBeNull(); var discoveredMethod = discoveredTest.TestMethods.FirstOrDefault(x => x.Name == "RegularTestMethod"); discoveredMethod.Should().NotBeNull(); }
protected void AssertDiscoveredMethod(Type testFixtureInAssemblyToDiscoverTestsIn, string expectedNameOfFirstTestMethod) { // Arrange var discoverer = new Discoverer(new List<string> { testFixtureInAssemblyToDiscoverTestsIn.Assembly.Location }); // Act var discoveredTests = discoverer.Discover(); // Assert discoveredTests.Should().NotBeNullOrEmpty(); var discoveredTest = discoveredTests.FirstOrDefault(x => x.Name == testFixtureInAssemblyToDiscoverTestsIn.Name); discoveredTest.Should().NotBeNull(); var discoveredMethod = discoveredTest.TestMethods.FirstOrDefault(x => x.Name == expectedNameOfFirstTestMethod); discoveredMethod.Should().NotBeNull(); }
public void DiscoverTest() { var explorer = new Discoverer(new Extractor(), new Settings { }); var nodes = explorer.Discover(System.Reflection.Assembly.GetAssembly(GetType()).FullName); var local = nodes.Where(x => x.Key.Contains(nameof(DiscovererTests))); var allExits = local.SelectMany(x => x.Exits); Assert.AreEqual(4, allExits.Count()); Assert.AreEqual(7, nodes.Count()); Assert.AreEqual(4, local.Count()); Assert.AreEqual(3, nodes.Where(x => x.Key.Contains(nameof(ExtractorTests))).Count()); Assert.AreEqual(3, local.Where(x => x.Metadata.IsEntry).Count()); Assert.IsTrue(local.Single(x => x.Metadata.IsLeaf).Key.Contains(nameof(Stub_Overloaded_CheckMethodParametersTest))); // leaf Assert.AreEqual(1, local.Single(x => x.Key.Contains(nameof(Stub_CheckMethodParametersTest))).Exits.Count()); // leaf }
protected void AssertDiscoveredMethod(Type testFixtureInAssemblyToDiscoverTestsIn, params string[] expectedTestMethodsName) { // Arrange var discoverer = new Discoverer(new List<string> { testFixtureInAssemblyToDiscoverTestsIn.Assembly.Location }, @"..\..\..\packages\NUnit.ConsoleRunner.3.2.0\tools\nunit3-console.exe"); // Act var discoveredTests = discoverer.Discover(); // Assert discoveredTests.Should().NotBeNullOrEmpty(); var discoveredTest = discoveredTests.SingleOrDefault(x => x.Name == testFixtureInAssemblyToDiscoverTestsIn.Name); discoveredTest.Should().NotBeNull(); var discoveredMethodsNames = discoveredTest.TestMethods.Select(p => p.Name); foreach (var expectedTestMethodName in expectedTestMethodsName) Assert.Contains(expectedTestMethodName, discoveredMethodsNames.ToList()); }
public void DiscoverOrphansTest() { var explorer = new Discoverer(new Extractor(), new Settings { AllowOrphans = true }); var nodes = explorer.Discover(System.Reflection.Assembly.GetAssembly(GetType()).FullName); var local = nodes.Where(x => x.Key.Contains(nameof(DiscovererTests))); var allExits = local.SelectMany(x => x.Exits).ToList(); var test = allExits.ToArray(); Assert.AreEqual(5, allExits.Count()); Assert.AreEqual(8, nodes.Count()); Assert.AreEqual(5, local.Count()); Assert.AreEqual(3, nodes.Where(x => x.Key.Contains(nameof(ExtractorTests))).Count()); Assert.AreEqual(3, local.Where(x => x.Metadata.IsEntry).Count()); Assert.AreEqual(1, local.Single(x => x.Key.Contains(nameof(Stub_Orphan))).Exits.Count()); // leaf }
public void UnreportedBehaviorsAreAddedToDepot() { var container = new TestContainer("assembly.dll", ShadowCopy.None); var request = new TestDiscoveryRequest(container); var controller = Substitute.For <IMspecController>(); var sink = Substitute.For <ITestDiscoverySink>(); var depot = new RemoteTaskDepot(GetReportedTasks().ToArray()); var discoverer = new Discoverer(request, controller, sink, depot, CancellationToken.None); var elements = GetDiscoveredElements().ToArray(); controller.Find(Arg.Do <IMspecDiscoverySink>(x => PopulateSink(x, elements)), Arg.Any <string>()); discoverer.Discover(); foreach (var element in elements) { Assert.NotNull(depot[element]); } }
public void Discover_Finds_Regular_Test_Fixture_And_Method() { // Arrange var discoverer = new Discoverer(new List <string> { TestAssemblyLocation }); // Act var discoveredTests = discoverer.Discover(); // Assert discoveredTests.Should().NotBeNullOrEmpty(); var discoveredTest = discoveredTests.FirstOrDefault(x => x.Name == typeof(RegularTestFixture).Name); discoveredTest.Should().NotBeNull(); var discoveredMethod = discoveredTest.TestMethods.FirstOrDefault(x => x.Name == "RegularTestMethod"); discoveredMethod.Should().NotBeNull(); }
protected void AssertDiscoveredMethod(Type testFixtureInAssemblyToDiscoverTestsIn, string expectedNameOfFirstTestMethod) { // Arrange var discoverer = new Discoverer(new List <string> { testFixtureInAssemblyToDiscoverTestsIn.Assembly.Location }); // Act var discoveredTests = discoverer.Discover(); // Assert discoveredTests.Should().NotBeNullOrEmpty(); var discoveredTest = discoveredTests.FirstOrDefault(x => x.Name == testFixtureInAssemblyToDiscoverTestsIn.Name); discoveredTest.Should().NotBeNull(); var discoveredMethod = discoveredTest.TestMethods.FirstOrDefault(x => x.Name == expectedNameOfFirstTestMethod); discoveredMethod.Should().NotBeNull(); }
public void TestDiscovererV3() { if (Environment.GetEnvironmentVariable("CI") == "true") { return; } var engine = CreateEngine(); engine.Listener.ClearBindings(); var serverEndPoint = new IPEndPoint(IPAddress.Any, Port.NextId); engine.Listener.AddBinding(serverEndPoint); engine.Start(); var timeout = 1000; var wait = 60 * timeout; try { var signal = new AutoResetEvent(false); var ending = new AutoResetEvent(false); var discoverer = new Discoverer(); discoverer.AgentFound += (sender, args) => { Assert.True(args.Agent.Address.ToString() != "0.0.0.0"); signal.Set(); }; var source = Observable.Defer(() => { discoverer.Discover(VersionCode.V3, new IPEndPoint(IPAddress.Broadcast, serverEndPoint.Port), null, timeout); var result = signal.WaitOne(wait); if (!result) { throw new TimeoutException(); } return(Observable.Return(result)); }) .RetryWithBackoffStrategy( retryCount: 4, retryOnError: e => e is TimeoutException ); source.Subscribe(result => { Assert.True(result); ending.Set(); }); Assert.True(ending.WaitOne(MaxTimeout)); } finally { if (SnmpMessageExtension.IsRunningOnWindows) { engine.Stop(); } } }
/// <summary> /// Invokes the <see cref="Discoverer"/> to discover instances with a <see cref="Type"/> which is assignable from the /// <see cref="Type"/> of this generic <see cref="ProviderRegistry{T}"/>. /// </summary> /// <returns>The list of discovered <see cref="IProvider"/> instances.</returns> public IReadOnlyList <T> Discover() { providers = Discoverer.Discover <T>(manager); return(Providers); }