예제 #1
0
        /// <summary>
        /// Sets the TestScheduler property on the target <paramref name="contextSpecification"/>.
        /// </summary>
        /// <param name="contextSpecification">
        /// The target context specification instance.
        /// </param>
        /// <param name="testScheduler">
        /// The test scheduler to apply to <paramref name="contextSpecification"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown when this aspect is applied to a test fixture not defining a TestScheduler property.
        /// </exception>
        private static void SetTestScheduler(IContextSpecification contextSpecification,
                                             [CanBeNull] TestScheduler testScheduler)
        {
            var testSchedulerPropertyInfo = contextSpecification.GetType().GetProperty("TestScheduler", BindingFlags.Instance | BindingFlags.NonPublic);

            if (testSchedulerPropertyInfo == null)
            {
                throw new InvalidOperationException("RxTestSchedulerAspect was applied but the target test fixture does not contain a TestScheduler property.");
            }

            Helper.SetPrivateProperty(contextSpecification, "TestScheduler", testScheduler);
        }
        /// <summary>
        /// Sets the TestScheduler property on the target <paramref name="contextSpecification"/>.
        /// </summary>
        /// <param name="contextSpecification">
        /// The target context specification instance.
        /// </param>
        /// <param name="testScheduler">
        /// The test scheduler to apply to <paramref name="contextSpecification"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown when this aspect is applied to a test fixture not defining a TestScheduler property.
        /// </exception>
        private static void SetTestScheduler(IContextSpecification contextSpecification,
                                             [CanBeNull] TestScheduler testScheduler)
        {
            var testSchedulerPropertyInfo = contextSpecification.GetType().GetProperty("TestScheduler", BindingFlags.Instance | BindingFlags.NonPublic);

            if (testSchedulerPropertyInfo == null)
            {
                throw new InvalidOperationException("RxTestSchedulerAspect was applied but the target test fixture does not contain a TestScheduler property.");
            }

            Helper.SetPrivateProperty(contextSpecification, "TestScheduler", testScheduler);
        }
예제 #3
0
        /// <summary>
        /// Determines whether TPL tasks will be run on a given <see cref="IContextSpecification"/>. The <paramref name="contextSpecification"/> instance needs to have the <see cref="TplContextAspect"/> aspect applied to it.
        /// </summary>
        /// <param name="contextSpecification">
        /// The context specification to inspect.
        /// </param>
        /// <returns>
        /// The value defined in <see cref="TplContextAspect.ExecuteTplTasks"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">The <paramref name="contextSpecification"/> instance does not have <see cref="TplContextAspect"/> applied to it.</exception>
        public static bool WillExecuteTplTasksOn(IContextSpecification contextSpecification)
        {
            var tplContextAspect =
                contextSpecification.GetType()
                                    .GetCustomAttributes(typeof(TplContextAspect), true)
                                    .Cast<TplContextAspect>()
                                    .SingleOrDefault();

            if (tplContextAspect == null)
            {
                throw new InvalidOperationException(string.Format("The {0} test fixture is missing a {1} attribute!", contextSpecification.GetType().FullName, typeof(TplContextAspect).Name));
            }

            return tplContextAspect.ExecuteTplTasks;
        }
예제 #4
0
        /// <summary>
        /// Determines whether TPL tasks will be run on a given <see cref="IContextSpecification"/>. The <paramref name="contextSpecification"/> instance needs to have the <see cref="TplContextAspect"/> aspect applied to it.
        /// </summary>
        /// <param name="contextSpecification">
        /// The context specification to inspect.
        /// </param>
        /// <returns>
        /// The value defined in <see cref="TplContextAspect.ExecuteTplTasks"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">The <paramref name="contextSpecification"/> instance does not have <see cref="TplContextAspect"/> applied to it.</exception>
        public static bool WillExecuteTplTasksOn(IContextSpecification contextSpecification)
        {
            var tplContextAspect =
                contextSpecification.GetType()
                                    .GetCustomAttributes(typeof(TplContextAspect), true)
                                    .Cast<TplContextAspect>()
                                    .SingleOrDefault();

            if (tplContextAspect == null)
            {
                throw new InvalidOperationException(string.Format("The {0} test fixture is missing a {1} attribute!", contextSpecification.GetType().FullName, typeof(TplContextAspect).Name));
            }

            return tplContextAspect.ExecuteTplTasks;
        }
예제 #5
0
        /// <summary>
        /// Determines whether TPL tasks will be run on a given <see cref="IContextSpecification"/>. The <paramref name="contextSpecification"/> instance needs to have the <see cref="TplContextAspectAttribute"/> aspect applied to it.
        /// </summary>
        /// <param name="contextSpecification">
        /// The context specification to inspect.
        /// </param>
        /// <returns>
        /// The value defined in <see cref="TplContextAspectAttribute.ExecuteTplTasks"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">The <paramref name="contextSpecification"/> instance does not have <see cref="TplContextAspectAttribute"/> applied to it.</exception>
        public static bool WillExecuteTplTasksOn(IContextSpecification contextSpecification)
        {
            var tplContextAspectAttribute =
                contextSpecification.GetType()
                                    .GetCustomAttributes(typeof(TplContextAspectAttribute), true)
                                    .Cast<TplContextAspectAttribute>()
                                    .Single();

            return tplContextAspectAttribute.ExecuteTplTasks;
        }