コード例 #1
0
        public void Test_AppHost_IHostedService()
        {
            var hostedProcess = new SampleProcess()
            {
                Name = "Process1"
            };
            var hostedProcess2 = new SampleProcess()
            {
                Name = "Process2"
            };
            var hostedService = new SampleService()
            {
                Name = "Service1"
            };
            var hostedService2 = new SampleService()
            {
                Name = "Service2"
            };

            var hostBuilder = new AppHostBuilder().CreateDefaultBuilder();

            hostBuilder.AddHostedProcess(hostedProcess);
            hostBuilder.AddHostedProcess(hostedProcess2);
            hostBuilder.AddHostedProcess <SampleProcess>();
            hostBuilder.AddHostedService(hostedService);
            hostBuilder.AddHostedService(hostedService2);
            hostBuilder.AddHostedService <SampleService>();
            var host = hostBuilder.Build();

            host.RunOnce();

            //hostedProcess.StartCalls.Should().Be(1);
            //hostedProcess.StopCalls.Should().Be(1);
            //hostedProcess.ErrorCalls.Should().Be(1);
            //hostedService.StartCalls.Should().Be(1);
            //hostedService.StopCalls.Should().Be(1);
        }