Exemplo n.º 1
0
        public void WrapErrorCreatesACollectionOfErrors()
        {
            var errors = SlcsErrors.WrapError(new SlcsError()
            {
                code = "123"
            });

            Assert.AreEqual(1, errors.errors.Count);
            Assert.AreEqual("123", errors.errors[0].code);
        }
        private static async Task AssignUnexpectedExceptionResponse(HttpContext context, IExceptionHandlerPathFeature exceptionHandlerPathFeature)
        {
            var errorResponse = SlcsErrors.WrapError(new SlcsError()
            {
                code           = "Slcs.InternalError",
                description    = exceptionHandlerPathFeature.Error.Message,
                retrySuggested = false
            });

            context.Response.StatusCode = 500;

            await context.Response.WriteAsync(errorResponse.ToJson());
        }
        public ActionResult <string> Get(int id)
        {
            throw new SlcsValidationException(
                      ValidationExceptionSeverity.Error, "This value was badly formed",
                      SlcsErrors.WrapError(new SlcsError()
            {
                code        = "Slcs.Validation",
                description = "Badly formed data error of some sort",
                source      = "Slcs"
            }));

            //throw new Exception("value not found");
            //return "value";
        }
Exemplo n.º 4
0
        public async Task UnhandledValidationExceptionReturnA422()
        {
            var context = new DefaultHttpContext();

            var validationException = new SlcsValidationException(ValidationExceptionSeverity.Error, "a message",
                                                                  SlcsErrors.WrapError(new SlcsError {
                code = "123"
            }));

            context.AddExceptionToContext(validationException);

            await UnexpectedExceptionHandler.Invoke(context);

            Assert.AreEqual(422, context.Response.StatusCode);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public void WrapErrorThrowsExceptionOnNull()
 {
     SlcsErrors.WrapError(null);
 }