public async Task Invoke_HandlesCalledTwice()
        {
            // arrange
            var clacks = new ClacksMiddleware(_onNext);
            await clacks.Invoke(_context);

            // act
            Func <Task> action = () => clacks.Invoke(_context);

            // assert
            action.ShouldNotThrow("Invoke handled ArgumentException properly");
        }
        public async Task Invoke_CallsOnNext()
        {
            // arrange
            var clacks = new ClacksMiddleware(_onNext);

            // act
            await clacks.Invoke(_context);

            // assert
            _onNextCalledTimes.Should().Be(1, "onNext was called exactly once");
        }
        public void Invoke_ChecksHttpContextForNull()
        {
            // arrange
            var clacks = new ClacksMiddleware(_onNext);

            // act
            // ReSharper disable once AssignNullToNotNullAttribute testing the check
            Func <Task> action = () => clacks.Invoke(null);

            // assert
            action.ShouldThrow <ArgumentNullException>("Invoke checked parameter for null");
        }
        public async Task Invoke_AddsHeader()
        {
            // arrange
            var clacks = new ClacksMiddleware(_onNext);

            // act
            await clacks.Invoke(_context);

            // assert
            _context.Response.Headers.Should()
            .Contain("X-Clacks-Overhead", new StringValues("GNU Terry Pratchett"),
                     "purpose of the middleware is to add the header");
        }