示例#1
0
        public async Task ShouldKickTask()
        {
            //Arrange
            var kickService = new TestTaskKickerService();

            var actualJob = new JobOptions
            {
                Cron    = "0/1 * * * * ?",
                Host    = "foo",
                Path    = "/bar",
                Port    = 8080,
                Headers = new Dictionary <string, string>
                {
                    { "foo", "bar" }
                }
            };

            //Act
            var jobsConfig = new JobOptionsConfig
            {
                Jobs = new[] { actualJob }
            };

            using var host = new HostBuilder()
                             .ConfigureServices(services =>
            {
                services.AddLogging(l => l
                                    .AddFilter(f => true)
                                    .AddXUnit(_output)
                                    );

                services.AddSingleton <ITaskKickerService>(kickService);
                services.AddKickerLogic(jobsConfig);
            })
                             .Build();

            await host.StartAsync();

            await Task.Delay(TimeSpan.FromSeconds(0.9));

            await host.StopAsync();

            //Assert
            Assert.Equal(2, kickService.KickCount);

            Assert.Equal(actualJob.Host, kickService.LastKickOptions.Host);
            Assert.Equal(actualJob.Path, kickService.LastKickOptions.Path);
            Assert.Equal(actualJob.Port, kickService.LastKickOptions.Port);
            Assert.Equal(actualJob.Headers, kickService.LastKickOptions.Headers);
        }
 public JobOptionsConfigBehavior()
 {
     _config = JobOptionsConfig.Load("config.yml");
 }