예제 #1
0
        public void duplicated_runs_dont_accidentally_accumulate_afterEach_calls()
        {
            AFixture fixture = new AFixture();

            var fakeGlobalSetupManager = new FakeGlobalSetupManager();

            TestPosition testPosition = TestPosition.At(1, 3, 2);

            var traceMessages = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = testPosition
            }, traceMessages);

            fixture.ResetObservations();

            var traceMessages1 = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = testPosition
            }, traceMessages1);

            expect_observation_matches(fixture.Observations, 1, 2, 3, 4, 5, 6, -2, -3, -4, 7, 8);
        }
예제 #2
0
        TestResult RunTest(EventListener listener)
        {
            listener.TestStarted(base.TestName);

            TestResult nunitTestResult = new TestResult(this);

            if (_pendingException != null)
            {
                nunitTestResult.Failure(_pendingException.Message, _pendingException.StackTrace, FailureSite.Test);
            }
            else if (RunState == RunState.NotRunnable)
            {
                nunitTestResult.SetResult(ResultState.NotRunnable, IgnoreReason, "", FailureSite.Test);
            }
            else
            {
                var testResult = SpecificationRunner.RunTest(this._testContext, new List <string>());

                NativeTestResult.ApplyToNunitResult(testResult, nunitTestResult);
            }

            listener.TestFinished(nunitTestResult);

            return(nunitTestResult);
        }
        public void Run()
        {
            SpecificationRunner.Run(new CreateUserSpecification("userId1", "*****@*****.**"), Console.Out);
            SpecificationRunner.Run(new RemoveUserSpecification("userId1"), Console.Out);

            SpecificationRunner.Run(new CreateTodoListSpecification("list1", "Food", "user1"), Console.Out);
        }
예제 #4
0
            public void RunTests(string assemblyName, string[] testNames, string explictlyIncluding, ITestResultListener listener)
            {
                using (var nativeTestFactory = RunTestDiscovery(Assembly.Load(assemblyName), t => true))
                {
                    foreach (var name in testNames)
                    {
                        var testContext = nativeTestFactory.Contexts[name];

                        var ignoreReason = nativeTestFactory.GetIgnoreReason(name, explictlyIncluding);

                        listener.NotifyStart(testContext.Name.FullName);

                        List <string> traceMessages = new List <string>();

                        if (ignoreReason == null)
                        {
                            var result = SpecificationRunner.RunTest(testContext, traceMessages);

                            listener.NotifyEnd(testContext.Name.FullName, result);
                        }
                        else
                        {
                            var result = new TestResultShim();
                            result.SetSkipped(ignoreReason);
                            listener.NotifyEnd(testContext.Name.FullName, result);
                        }
                    }
                }
            }
        public void Verify(SpecificationToRun spec)
        {
            var runner = new SpecificationRunner();

            RunResult result = runner.RunSpecifciation(spec);
            if (result.Passed)
                return;

            Assert.Fail(Format(result));
        }
예제 #6
0
 public void _(SpecificationToRun spec)
 {
     var result = new SpecificationRunner().RunSpecification(spec);
     spec.Specification.Document(result);
     if (!result.Passed)
     {
         if (result.Thrown != null)
         {
             throw result.Thrown;
         }
         Assert.Fail(result.Message ?? "<null>");
     }
 }
예제 #7
0
        public void Verify(SpecificationToRun spec)
        {
            var runner = new SpecificationRunner();
            var result = runner.RunSpecifciation(spec);

            if (result.Passed)
            {
                Console.WriteLine(Format(result));
                return;
            }

            Assert.Fail(Format(result));
        }
예제 #8
0
        public void Verify(SpecificationToRun spec)
        {
            var result = new SpecificationRunner().RunSpecification(spec);

            spec.Specification.Document(result);
            if (!result.Passed)
            {
                if (result.Thrown != null)
                {
                    throw result.Thrown;
                }
                Assert.Fail(result.Message);
            }
        }
        void expect_test_to_observe(TestPosition testPosition, List <string> expected)
        {
            var fixture = new has_test_in_loop();

            var traceMessages = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, new FakeGlobalSetupManager()),
                Name           = new TestName(),
                Position       = testPosition
            }, traceMessages);


            Assert.That(fixture.Observations, Is.EquivalentTo(expected));
        }
예제 #10
0
        public void can_be_ran()
        {
            AFixture fixture = new AFixture();

            var fakeGlobalSetupManager = new FakeGlobalSetupManager();

            var traceMessages = new List <string>();

            SpecificationRunner.RunTest(new TestContext()
            {
                FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager),
                Name           = new TestName(),
                Position       = TestPosition.At(1, 3, 2)
            }, traceMessages);

            expect_observation_matches(fixture.Observations, 1, 2, 3, 4, 5, 6, 7, -2, -3, -4, 8);
        }
        public override TaskResult Start(TaskExecutionNode node)
        {
            var specificationTask = node.RemoteTask as SpecificationTask;
            if (specificationTask == null)
                return TaskResult.Error;

            var assembly = Assembly.LoadFrom(specificationTask.AssemblyLocation);
            if (assembly == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not load context assembly: {0}", specificationTask.AssemblyLocation));
                return TaskResult.Error;
            }

            var specificationContainer = assembly.GetTypes().FirstOrDefault(t => t.FullName == specificationTask.SpecificationContainerName);
            if (specificationContainer == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not load type '{0}' from assembly {1}", specificationTask.SpecificationContainerName, specificationTask.AssemblyLocation));
                return TaskResult.Error;
            }

            var fieldInfo = specificationContainer.GetField(specificationTask.SpecificationName);
            if (fieldInfo == null)
            {
                Server.TaskError(specificationTask, string.Format("Could not find field '{0}' on type {1}", specificationTask.SpecificationName, specificationTask.SpecificationContainerName));
                return TaskResult.Error;
            }

            if (!typeof(Specification).IsAssignableFrom(fieldInfo.FieldType))
            {
                Server.TaskError(specificationTask, string.Format("'{0}' is not a specification", specificationTask.SpecificationName));
                return TaskResult.Error;
            }

            var specification = (Specification)fieldInfo.GetValue(Activator.CreateInstance(specificationContainer));
            var specificationToRun = new SpecificationToRun(specification, fieldInfo);

            var runner = new SpecificationRunner();
            var runResult = runner.RunSpecification(specificationToRun);

            Server.TaskOutput(specificationTask, RunResultFormatter.FormatRunResult(runResult), TaskOutputType.STDOUT);

            return runResult.Passed ? TaskResult.Success : TaskResult.Error;
        }
예제 #12
0
 public static IEnumerable<RunResult> RunAllInAssembly(Assembly assembly)
 {
     var generator = new RootGenerator(assembly);;
     var runner = new SpecificationRunner();
     return generator.GetSpecifications().Select(runner.RunSpecification);
 }