public void Context_With_No_Task()
        {
            var startupTasksContext = new StartupTasksContext();

            Assert.True(startupTasksContext.HaveAllTasksFinished);
            Assert.False(startupTasksContext.HasAnyTaskFailed);
        }
        public void Context_Before_Tasks_Execution()
        {
            var startupTasksContext = new StartupTasksContext();

            startupTasksContext.RegisterTask();

            Assert.False(startupTasksContext.HaveAllTasksFinished);
            Assert.False(startupTasksContext.HasAnyTaskFailed);
        }
        public void Context_When_Task_Fails()
        {
            var startupTasksContext = new StartupTasksContext();

            startupTasksContext.RegisterTask();
            startupTasksContext.MarkTaskAsFailed();

            Assert.True(startupTasksContext.HaveAllTasksFinished);
            Assert.True(startupTasksContext.HasAnyTaskFailed);
        }
        public void Context_After_Tasks_Execution()
        {
            var startupTasksContext = new StartupTasksContext();

            startupTasksContext.RegisterTask();
            startupTasksContext.RegisterTask();
            startupTasksContext.MarkTaskAsComplete();
            startupTasksContext.MarkTaskAsComplete();

            Assert.True(startupTasksContext.HaveAllTasksFinished);
            Assert.False(startupTasksContext.HasAnyTaskFailed);
        }
        public async Task Middleware_Returns_503_When_Tasks_Have_Not_Started()
        {
            var context = new DefaultHttpContext();

            context.Response.Body = new MemoryStream();


            var startupTasksContext = new StartupTasksContext();

            startupTasksContext.RegisterTask();
            startupTasksContext.RegisterTask();

            var middleware = new StartupTasksMiddleware(null, httpContext => httpContext.Response.WriteAsync("Hello world!"));
            await middleware.ProcessRequest(context, startupTasksContext);

            Assert.Equal(503, context.Response.StatusCode);
        }