예제 #1
0
            public static void Execute(SpecificationPrimitive <Action> primitive)
            {
                Debug.Assert(primitive.ActionDelegate != null);

                if (primitive.TimeoutMs > 0)
                {
#if SILVERLIGHT
                    IAsyncResult asyncResult = AsyncDelegatesCompatibility.WorkingBeginInvoke(primitive.ActionDelegate, null, null);
#else
                    IAsyncResult asyncResult = primitive.ActionDelegate.BeginInvoke(null, null);
#endif

                    if (!asyncResult.AsyncWaitHandle.WaitOne(primitive.TimeoutMs))
                    {
                        throw new Xunit.Sdk.TimeoutException(primitive.TimeoutMs);
                    }
                    else
                    {
#if SILVERLIGHT
                        primitive.ActionDelegate.WorkingEndInvoke(asyncResult);
#else
                        primitive.ActionDelegate.EndInvoke(asyncResult);
#endif
                    }
                }
                else
                {
                    primitive.ActionDelegate();
                }
            }
예제 #2
0
 private static void Reset()
 {
     _exceptions   = new List <Action>();
     _context      = null;
     _do           = null;
     _asserts      = new List <SpecificationPrimitive <Action> >();
     _observations = new List <SpecificationPrimitive <Action> >();
     _skips        = new List <SpecificationPrimitive <Action> >();
 }
예제 #3
0
            public static ISpecificationPrimitive Todo(string message, Action skippedAction)
            {
                EnsureThreadStaticInitialized();

                SpecificationPrimitive <Action> skip = new SpecificationPrimitive <Action>(message, skippedAction);

                _skips.Add(skip);

                return(skip);
            }
예제 #4
0
            public static ISpecificationPrimitive Observation(string message, Action observationAction)
            {
                EnsureThreadStaticInitialized();

                var observation = new SpecificationPrimitive <Action>(message, observationAction);

                _observations.Add(observation);

                return(observation);
            }
예제 #5
0
            public static ISpecificationPrimitive Assert(string message, Action assertAction)
            {
                EnsureThreadStaticInitialized();

                SpecificationPrimitive <Action> assert = new SpecificationPrimitive <Action>(message, assertAction);

                _asserts.Add(assert);

                return(assert);
            }
예제 #6
0
            public static ISpecificationPrimitive Do(string message, Action doAction)
            {
                EnsureThreadStaticInitialized();

                if (_do == null)
                {
                    _do = new SpecificationPrimitive <Action>(message, doAction);
                }
                else
                {
                    _exceptions.Add(() => { throw new InvalidOperationException("Cannot have more than one Do statement in a specification"); });
                }

                return(_do);
            }
예제 #7
0
            public static ISpecificationPrimitive Context(string message, ContextDelegate arrange)
            {
                EnsureThreadStaticInitialized();

                if (_context == null)
                {
                    _context = new SpecificationPrimitive <ContextDelegate>(message, arrange);
                }
                else
                {
                    _exceptions.Add(() => { throw new InvalidOperationException("Cannot have more than one Context statement in a specification"); });
                }

                return(_context);
            }
예제 #8
0
 public ObservationExecutor(SpecificationPrimitive <ContextDelegate> context, SpecificationPrimitive <Action> @do, IEnumerable <SpecificationPrimitive <Action> > observations)
 {
     _observations = observations;
     _context      = context;
     _do           = @do;
 }
예제 #9
0
 public AssertExecutor(SpecificationPrimitive <ContextDelegate> context, SpecificationPrimitive <Action> @do, List <SpecificationPrimitive <Action> > asserts)
 {
     _asserts = asserts;
     _context = context;
     _do      = @do;
 }