Exemple #1
0
        public void ApiExceptionMapper_MapException_HttpResponseException()
        {
            // This method tests what happens when a HttpResponseException was thrown
            var apiExceptionMapper    = new ApiExceptionMapper();
            var actionExecutedContext = this.CreateExecutedContextWithStatusCode(new HttpResponseException(HttpStatusCode.InternalServerError));

            apiExceptionMapper.MapException(actionExecutedContext);

            Assert.IsNotNull(actionExecutedContext.Response);
            Assert.AreEqual(HttpStatusCode.InternalServerError, actionExecutedContext.Response.StatusCode);
            Assert.IsNull(actionExecutedContext.Response.Content);
        }
Exemple #2
0
        public void ApiExceptionMapper_MapException_DemoInvalidOperationException()
        {
            // This method tests what happens when a DemoInvalidOperationException was thrown
            var apiExceptionMapper    = new ApiExceptionMapper();
            var actionExecutedContext = this.CreateExecutedContextWithStatusCode(new DemoInvalidOperationException("Testing"));

            apiExceptionMapper.MapException(actionExecutedContext);

            Assert.IsNotNull(actionExecutedContext.Response);
            Assert.AreEqual(HttpStatusCode.BadRequest, actionExecutedContext.Response.StatusCode);
            Assert.IsNotNull(actionExecutedContext.Response.Content);
        }
Exemple #3
0
        public void ApiExceptionMapper_MapException_AggregateException()
        {
            // This method tests what happens when an AggregateException was thrown
            var apiExceptionMapper    = new ApiExceptionMapper();
            var exception             = new AggregateException("Test 1", new Exception("Test 2", new Exception("Test 2.1")), new Exception("Test 3", new Exception("Test 3.1")));
            var actionExecutedContext = this.CreateExecutedContextWithStatusCode(exception);

            apiExceptionMapper.MapException(actionExecutedContext);

            Assert.IsNotNull(actionExecutedContext.Response);
            Assert.AreEqual(HttpStatusCode.InternalServerError, actionExecutedContext.Response.StatusCode);
            Assert.IsNotNull(actionExecutedContext.Response.Content);
        }
Exemple #4
0
 public void ApiExceptionMapper_Constructor()
 {
     // This test verifies that the default constructor works.
     // Note: this test is useless except for code coverage since we are testing the default constructor with no custom logic.
     var apiExceptionMapper = new ApiExceptionMapper();
 }