public async Task UnhandledException_BodySerialisesToA_SlcsErrors_Instance() { var context = new DefaultHttpContext(); // We need to initialise the fake httpContext to get to the body context.Response.Body = new MemoryStream(); var ex = new ApplicationException("Some exception occurred"); context.AddExceptionToContext(ex); await UnexpectedExceptionHandler.Invoke(context); string body = await context.GetBodyFromResponse(); var expectedErrorObject = JsonConvert.DeserializeObject <SlcsErrors>(body); Assert.IsNotNull(expectedErrorObject); }
public async Task UnhandledValidationException_BodySerialisesToA_SlcsErrors_Instance() { var context = new DefaultHttpContext(); // We need to initialise the fake httpContext to get to the body context.Response.Body = new MemoryStream(); var ex = new SlcsValidationException(ValidationExceptionSeverity.Error, "a message", SlcsErrors.WrapError(new SlcsError { code = "123" })); context.AddExceptionToContext(ex); await UnexpectedExceptionHandler.Invoke(context); string body = await context.GetBodyFromResponse(); var expectedErrorObject = JsonConvert.DeserializeObject <SlcsErrors>(body); Assert.IsNotNull(expectedErrorObject); }