Esempio n. 1
0
        public void ExecuteAsync()
        {
            var executor = ServiceProvider.GetRequiredService <IBackgroundJobExecuter>();

            Should.Throw <ScorpioException>(() => executor.ExecuteAsync(new JobExecutionContext(ServiceProvider, typeof(BackgroundJob <int>), 1)));
            Should.Throw <ScorpioException>(() => executor.ExecuteAsync(new JobExecutionContext(ServiceProvider, typeof(IServiceProvider), 1)));
            Should.NotThrow(async() =>
            {
                await executor.ExecuteAsync(new JobExecutionContext(ServiceProvider, typeof(BackgroundJob <string>), "Test"));
                ServiceProvider.GetRequiredService <BackgroundJob <string> >().ReceivedWithAnyArgs(1).Execute(Arg.Any <string>());
            });
            Should.NotThrow(async() =>
            {
                await executor.ExecuteAsync(new JobExecutionContext(ServiceProvider, typeof(AsyncBackgroundJob <string>), "Test"));
                await ServiceProvider.GetRequiredService <AsyncBackgroundJob <string> >().ReceivedWithAnyArgs(1).ExecuteAsync(Arg.Any <string>());
            });
            Should.Throw <BackgroundJobExecutionException>(async() =>
            {
                var job = ServiceProvider.GetRequiredService <BackgroundJob <string> >();
#pragma warning disable S3626 // Jump statements should not be redundant
                job.WhenForAnyArgs(e => e.Execute(Arg.Any <string>())).Do(x => throw new NotImplementedException());
#pragma warning restore S3626 // Jump statements should not be redundant
                await executor.ExecuteAsync(new JobExecutionContext(ServiceProvider, typeof(BackgroundJob <string>), "Test"));
            }).InnerException.ShouldBeOfType <TargetInvocationException>().InnerException.ShouldBeOfType <NotImplementedException>();
        }
Esempio n. 2
0
        public void FilterFactoryThrows()
        {
            _filterFactories[0] = provider => throw new NotSupportedException("oops!");

            var ex = Assert.Throws <InvalidOperationException>(() => _sut.CreateHandler(_service.Object, _context.Object));

            Console.WriteLine(ex);
            ex !.InnerException.ShouldBeOfType <NotSupportedException>();
            ex.InnerException.Message.ShouldContain("oops!");
        }