コード例 #1
0
        /// <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);
            }));
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
        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>();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: agluque62/svn-dev_TFT
        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);
        }
コード例 #5
0
        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>();
        }
コード例 #6
0
        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>();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: ParserTests.cs プロジェクト: raphaelheitor/LoveOAS
        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());
        }
コード例 #9
0
        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>();
        }
コード例 #10
0
ファイル: ParserTests.cs プロジェクト: raphaelheitor/LoveOAS
        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());
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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
        }
コード例 #15
0
        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());
        }
コード例 #16
0
        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]);
            }
        }
コード例 #18
0
        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();
        }
コード例 #19
0
        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();
        }
コード例 #20
0
        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();
                }
            }
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
		/// <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);
			}));
		}