Пример #1
0
            public void ReturnsATask()
            {
                var context = new Mock <DbContext>();
                var job     = new UpdateStatisticsJob(TimeSpan.FromSeconds(10), () => context.Object, TimeSpan.MaxValue);

                var task = job.Execute();

                Assert.NotNull(task);
            }
Пример #2
0
            private static void RunJob(UpdateStatisticsJob job)
            {
                var task = job.Execute();

                task.Start();
                try
                {
                    task.Wait();
                }
                catch (AggregateException)
                {
                }
            }
            public void CreatesNewContextOnEachRun()
            {
                int createTimes = 0;
                var context     = new Mock <DbContext>();
                var job         = new UpdateStatisticsJob(TimeSpan.FromSeconds(10), () =>
                {
                    Interlocked.Increment(ref createTimes);
                    throw new InvalidOperationException(); // Prevent the actual calling of the query.
                }, TimeSpan.MaxValue);

                RunJob(job);
                RunJob(job);

                Assert.Equal(2, createTimes);
            }