public void TestsWhereShouldFilter(string filter, int expectedCount, int noOfSkipped = 0, int noOfNone = 0)
        {
            // Create a fake environment.
            var context       = new FakeRunContext(new FakeRunSettingsForWhere(filter));
            var fakeFramework = new FakeFrameworkHandle();

            var executor = TestAdapterUtils.CreateExecutor();

            executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework);

            var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd).ToList();

            TestContext.WriteLine(" ");
            foreach (var test in completedRuns)
            {
                TestContext.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}");
            }

            Assert.Multiple(() =>
            {
                Assert.That(completedRuns, Has.Exactly(expectedCount).Items, "Total number wrong");
                Assert.That(completedRuns.Count(o => o.TestOutcome == TestOutcome.Skipped), Is.EqualTo(noOfSkipped), "Skipped number wrong");
                Assert.That(completedRuns.Count(o => o.TestOutcome == TestOutcome.None), Is.EqualTo(noOfNone), "Explicit and inconclusive number wrong");
            });
        }
        public void NativeAssemblyProducesWarning()
        {
            // Create a fake environment.
            var context       = new FakeRunContext();
            var fakeFramework = new FakeFrameworkHandle();

            // Find the native exaple dll.
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "NativeTests.dll");

            Assert.That(File.Exists(path));

            // Try to execute tests from the dll.
            TestAdapterUtils.CreateExecutor().RunTests(
                new[] { path },
                context,
                fakeFramework);

            // Gather results.
            var testResults = fakeFramework.Events
                              .Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult)
                              .Select(e => e.TestResult)
                              .ToList();

            // No tests found.
            Assert.That(testResults.Count, Is.EqualTo(0));

            // A warning about unsupported assebly format provided.
            var messages = fakeFramework.Events
                           .Where(e => e.EventType == FakeFrameworkHandle.EventType.SendMessage &&
                                  e.Message.Level == Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning)
                           .Select(o => o.Message.Text);

            Assert.That(messages, Has.Some.Contains("Assembly not supported"));
        }
Пример #3
0
        public void SetUp()
        {
            testLog       = new FakeFrameworkHandle();
            testConverter = new TestConverter(new TestLogger(new MessageLoggerStub(), 0), FakeTestData.AssemblyPath);
            fakeTestNode  = FakeTestData.GetTestNode();

            // Ensure that the converted testcase is cached
            testConverter.ConvertTestCase(fakeTestNode);
            Assert.NotNull(testConverter.GetCachedTestCase("123"));

            listener = new NUnitEventListener(testLog, testConverter);
        }
        public void Listener_LeaseLifetimeWillNotExpire()
        {
            testLog       = new FakeFrameworkHandle();
            testConverter = new TestConverter(new TestLogger(), ThisAssemblyPath);
            MarshalByRefObject localInstance = (MarshalByRefObject)Activator.CreateInstance(typeof(NUnitEventListener), testLog, testConverter);

            RemotingServices.Marshal(localInstance);

            var lifetime = ((MarshalByRefObject)localInstance).GetLifetimeService();

            // A null lifetime (as opposed to an ILease) means the object has an infinite lifetime
            Assert.IsNull(lifetime);
        }
Пример #5
0
        public void Listener_LeaseLifetimeWillNotExpire()
        {
            testLog       = new FakeFrameworkHandle();
            testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, collectSourceInformation: true);
            var localInstance = (MarshalByRefObject)Activator.CreateInstance(typeof(NUnitEventListener), testLog, testConverter, null);

            RemotingServices.Marshal(localInstance);

            var lifetime = ((MarshalByRefObject)localInstance).GetLifetimeService();

            // A null lifetime (as opposed to an ILease) means the object has an infinite lifetime
            Assert.IsNull(lifetime);
        }
        public void TestsWhereShouldFilter(string filter, int expectedCount)
        {
            // Create a fake environment.
            var context       = new FakeRunContext(new FakeRunSettingsForWhere(filter));
            var fakeFramework = new FakeFrameworkHandle();

            var executor = TestAdapterUtils.CreateExecutor();

            executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework);

            var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd);

            Assert.That(completedRuns, Has.Exactly(expectedCount).Items);
        }
        public void SetUp()
        {
            testLog = new FakeFrameworkHandle();

            using (var testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, collectSourceInformation: true))
            {
                fakeTestNode = FakeTestData.GetTestNode();

                // Ensure that the converted testcase is cached
                testConverter.ConvertTestCase(fakeTestNode);
                Assert.NotNull(testConverter.GetCachedTestCase("123"));

                listener = new NUnitEventListener(testLog, testConverter, null);
            }
        }
Пример #8
0
        public void LoadMockassembly()
        {
            // Sanity check to be sure we have the correct version of mock-assembly.dll
            Assert.That(MockAssembly.Tests, Is.EqualTo(31),
                        "The reference to mock-assembly.dll appears to be the wrong version");
            new List <TestCase>();
            testResults = new List <TestResult>();
            testLog     = new FakeFrameworkHandle();

            // Load the NUnit mock-assembly.dll once for this test, saving
            // the list of test cases sent to the discovery sink
            executor = ((ITestExecutor) new NUnitTestExecutor());
            executor.RunTests(new[] { MockAssemblyPath }, Context, testLog);
            this.Summary = new ResultSummary(testResults);
        }
Пример #9
0
        public void SetUp()
        {
            testLog  = new FakeFrameworkHandle();
            settings = Substitute.For <IAdapterSettings>();
            executor = Substitute.For <INUnit3TestExecutor>();
            executor.Settings.Returns(settings);
            executor.FrameworkHandle.Returns(testLog);
            settings.CollectSourceInformation.Returns(true);
            using var testConverter = new TestConverterForXml(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings);
            fakeTestNode            = new NUnitEventTestCase(FakeTestData.GetTestNode());

            // Ensure that the converted testcase is cached
            testConverter.ConvertTestCase(fakeTestNode);
            Assert.That(testConverter.GetCachedTestCase("123"), Is.Not.Null);

            listener = new NUnitEventListener(testConverter, executor);
        }
        public void SetUp()
        {
            MethodInfo fakeTestMethod = GetType().GetMethod("FakeTestMethod", BindingFlags.Instance | BindingFlags.NonPublic);

            fakeNUnitTest = new NUnitTestMethod(fakeTestMethod);

            fakeNUnitResult = new NUnitTestResult(fakeNUnitTest);
            fakeNUnitResult.SetResult(ResultState.Success, "It passed!", null);
            fakeNUnitResult.Time = 1.234;

            testLog = new FakeFrameworkHandle();

            testConverter = new TestConverter(new TestLogger(), ThisAssemblyPath);

            testConverter.ConvertTestCase(fakeNUnitTest);
            Assert.NotNull(testConverter.GetCachedTestCase(fakeNUnitTest.TestName.UniqueName));

            listener = new NUnitEventListener(testLog, testConverter);
        }
        public void LoadMockAssembly()
        {
            _mockAssemblyPath   = Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll");
            _mockAssemblyFolder = Path.GetDirectoryName(_mockAssemblyPath);
            // Sanity check to be sure we have the correct version of mock-assembly.dll
            Assert.That(MockAssembly.TestsAtRuntime, Is.EqualTo(MockAssembly.Tests),
                        "The reference to mock-assembly.dll appears to be the wrong version");
            testLog = new FakeFrameworkHandle();

            // Load the NUnit mock-assembly.dll once for this test, saving
            // the list of test cases sent to the discovery sink

            var testResults = testLog.Events
                              .Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult)
                              .Select(e => e.TestResult)
                              .ToList();

            Summary = new ResultSummary(testResults);
        }