PclUnit.Run.TestCycleExceptions.Add C# (CSharp) Méthode

Add() public méthode

public Add ( TestCycle cycle, Exception exception ) : void
cycle TestCycle
exception System.Exception
Résultat void
        public void Add(TestCycle cycle, Exception exception)
        {
            var testException = exception as TestCycleExceptions;
            if (testException != null)
            {
                Add(testException);
                return;
            }

            //Unwrap Target invocation Exceptions if possible
            if (exception is TargetInvocationException)
            {
                exception = exception.InnerException ?? exception;
            }

            switch (cycle)
            {
                case TestCycle.Setup:
                    Setup.Add(exception);
                    break;
                case TestCycle.Test:
                    Test.Add(exception);
                    break;
                case TestCycle.Teardown:
                    Teardown.Add(exception);
                    break;
            }
        }

Same methods

TestCycleExceptions::Add ( TestCycleExceptions exceptions ) : void

Usage Example

Exemple #1
0
        private void RunHelper(Object stateInfo)
        {
            var state = (State) stateInfo;
            var startTime = DateTime.Now;

            IAssertionHelper helper = new DummyHelper()
                                          {
                                              Assert = new Assert(),
                                              Log = new Log()
                                          };

            object fixture = null;
            var exceptions = new TestCycleExceptions();
            Result finalResult = null;
            try
            {

                fixture = _init(_type, _constructorArgs.Parameters);
                var helpertemp = fixture as IAssertionHelper;
                if (helpertemp != null)
                {
                    helpertemp.Assert = helper.Assert;
                    helpertemp.Log = helper.Log;
                    helper = helpertemp;
                }

                if (_constructorArgs.Disposed)
                {
                    throw new InvalidOperationException("Type ParameterSet Disposed Regenerated Tests to rerun");
                }
                if (_methodArgs.Disposed)
                {
                    throw new InvalidOperationException(
                        "Method ParameterSet Disposed Regenerated Tests to rerun");
                }

                try
                {
                    var result = _invoke(helper, _method, fixture, _methodArgs.Parameters);

                    //If the test method returns a boolean, true increments assertion
                    if (result as bool? ?? false)
                    {
                        helper.Assert.Okay();
                    }

                    //If the test method returns a boolean, false is fail
                    if (!(result as bool? ?? true))
                    {
                        helper.Assert.Fail("Test returned false.");
                    }

                    if (result is IReturnedResult)
                    {
                       finalResult = new Result(state.Platform,
                                                  startTime, DateTime.Now, result as IReturnedResult);
                    }
                }
                catch (Exception ex)
                {
                     exceptions.Add(TestCycle.Test, ex);
                }
            }
            catch (Exception ex)
            {
                exceptions.Add(TestCycle.Setup, ex);
            }
            finally
            {
                try
                {
                    var disposable = fixture as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    exceptions.Add(TestCycle.Teardown, ex);
                }
                exceptions.WriteOutExceptions(helper);
                state.Result = finalResult ?? new Result(state.Platform, exceptions.GetResult(helper), startTime, DateTime.Now, helper);
                state.Event.Set();
            }
        }
All Usage Examples Of PclUnit.Run.TestCycleExceptions::Add