public void Controllers_WhenResourceLockedExceptionOccurs_ReturnsConflictError()
        {
            // Arrange
            var domain           = "http://www.domain.com";
            var path             = "/testController/testAction";
            var exceptionMessage = "exception message";
            var exception        = new ResourceLockedException(exceptionMessage);

            var httpRequestMessage = new HttpRequestMessage()
            {
                RequestUri = new Uri(domain + path)
            };

            var httpControllerContext = new HttpControllerContext(_httpConfiguration, _httpRouteData, httpRequestMessage)
            {
                Controller = _controller
            };

            var httpActionContext         = new HttpActionContext(httpControllerContext, _httpActionDescriptor);
            var httpActionExecutedContext = new HttpActionExecutedContext(httpActionContext, exception);

            // Act
            var attribute = new GlobalExceptionHandlerAttribute();

            attribute.OnException(httpActionExecutedContext);

            // Assert
            var expectedError = string.Format("Exception occurred in: {0}; Exception: {1}", path, exceptionMessage);

            Assert.AreEqual(expectedError, httpActionExecutedContext.Response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(HttpStatusCode.Conflict, httpActionExecutedContext.Response.StatusCode);
        }
Beispiel #2
0
        public static VfsException ToException(this VfsFault fault)
        {
            VfsException exception;

            switch (fault.FaultType)
            {
            case VfsFaultType.ResourceNotFound:
                exception = new VirtualResourceNotFoundException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.ResourceAccess:
                exception = new ResourceAccessException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.ResourceOverwrite:
                exception = new ResourceOverwriteException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.ResourceLocked:
                exception = new ResourceLockedException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.ResourcePathInvalid:
                exception = new InvalidResourcePathException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.TransferError:
                exception = new TransferException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.TransferUnknown:
                exception = new UnknownTransferException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.TransferStatusError:
                exception = new TransferStatusException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.DataBlockError:
                exception = new DataBlockException(fault.CreateFaultMessage());
                break;

            case VfsFaultType.Undefined:
                exception = new VfsFaultException(fault.CreateFaultMessage(), fault);
                break;

            default:
                Debug.WriteLine("Unsupported VFS fault type: " + fault.FaultType);
                exception = new VfsFaultException(fault.CreateFaultMessage(), fault);
                break;
            }

            exception.EventId = fault.EventId;
            return(exception);
        }