public void Use_Invalid_Handler_Type()
        {
            var builder = new ExceptionHandlerBuilder(new ServiceCollection().BuildServiceProvider());

            Assert.Throws <ArgumentException>(() => builder.Use(typeof(InvalidHandler)));
            Assert.Throws <ArgumentException>(() => builder.Use <InvalidHandler>());
        }
Esempio n. 2
0
        public async void Use_And_Build()
        {
            var builder = new ExceptionHandlerBuilder(new ServiceCollection().BuildServiceProvider());

            builder.Use(_ => { _flag = ""; return(Task.CompletedTask); });
            builder.Use(_ => { _flag += "1"; return(Task.CompletedTask); });
            builder.Use(_ => { _flag += "2"; return(Task.CompletedTask); });
            builder.Use(_ => { _.Properties.Add("flag", _flag); return(Task.CompletedTask); });
            var handler = builder.Build();
            var context = new ExceptionContext(new Exception());

            await handler(context);

            Assert.Equal("12", context.Properties["flag"]);
        }