예제 #1
0
            public IEnumerable <ITestCommand> AssertCommands(string name, IMethodInfo method)
            {
                foreach (var assertion in _asserts)
                {
                    // do not capture the iteration variable because
                    // all tests would point to the same assertion
                    var    capturableAssertion = assertion;
                    Action test =
                        () =>
                    {
                        using (SpecificationPrimitiveExecutor.Execute(_context))
                        {
                            if (_do != null)
                            {
                                SpecificationPrimitiveExecutor.Execute(_do);
                            }

                            SpecificationPrimitiveExecutor.Execute(capturableAssertion);
                        }
                    };

                    string testDescription = String.Format("{0}, {1}", name, assertion.Message);

                    yield return(new ActionTestCommand(method, testDescription, MethodUtility.GetTimeoutParameter(method), test));
                }
            }
예제 #2
0
            public IEnumerable <ITestCommand> ObservationCommands(string name, IMethodInfo method)
            {
                if (_observations.Count() == 0)
                {
                    yield break;
                }

                bool        setupExceptionOccurred = false;
                IDisposable systemUnderTest        = default(IDisposable);

                Action setupAction = () =>
                {
                    try
                    {
                        systemUnderTest = SpecificationPrimitiveExecutor.Execute(_context);

                        if (_do != null)
                        {
                            SpecificationPrimitiveExecutor.Execute(_do);
                        }
                    }
                    catch (Exception)
                    {
                        setupExceptionOccurred = true;
                        throw;
                    }
                };

                yield return(new ActionTestCommand(method, "{ " + name, 0, setupAction));

                foreach (var observation in _observations)
                {
                    // do not capture the iteration variable because
                    // all tests would point to the same observation
                    var    capturableObservation = observation;
                    Action perform = () =>
                    {
                        if (setupExceptionOccurred)
                        {
                            throw new ContextSetupFailedException("Setting up Context failed");
                        }

                        SpecificationPrimitiveExecutor.Execute(capturableObservation);
                    };

                    yield return(new ActionTestCommand(method, "\t- " + capturableObservation.Message, 0, perform));
                }

                Action tearDownAction = () =>
                {
                    if (systemUnderTest != null)
                    {
                        systemUnderTest.Dispose();
                    }

                    if (setupExceptionOccurred)
                    {
                        throw new ContextSetupFailedException("Setting up Context failed, but Fixtures were disposed.");
                    }
                };

                yield return(new ActionTestCommand(method, "} " + name, 0, tearDownAction));
            }