Ejemplo n.º 1
0
        /// <summary>
        /// Replaces the domain clock with a virtual clock that can be used to control the current time.
        /// </summary>
        /// <param name="now">The time to which the virtual clock is set.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">You must dispose the current VirtualClock before starting another.</exception>
        /// <param name="caller">The caller.</param>
        /// <param name="callerFilePath">The caller file path.</param>
        public static VirtualClock Start(
            DateTimeOffset?now = null,
            [CallerMemberName] string caller       = null,
            [CallerFilePath] string callerFilePath = null)
        {
            var clock = Clock.Current as VirtualClock;

            if (clock != null)
            {
                throw new InvalidOperationException($"You must dispose the current VirtualClock (created by {clock.creatorMemberName} [{clock.creatorFilePath}]) before starting another.");
            }

            Configuration.Current.EnsureCommandSchedulerPipelineTrackerIsInitialized();

            var virtualClock = new VirtualClock(now ?? DateTimeOffset.Now)
            {
                creatorMemberName = caller,
                creatorFilePath   = callerFilePath
            };

            Clock.Current = virtualClock;

            return(virtualClock);
        }