Пример #1
0
        public static Error IdentifyExceptionByType(ServiceOperationException exception)
        {
            switch (exception)
            {
            case ObsoleteDataException _:
                return(new Error(ErrorCodes.OldData, exception.Message));

            case ResourceAlreadyExistException _:
                return(new Error(ErrorCodes.ResourceAlreadyExist, exception.Message));

            case ObjectMissingException _:
                return(new Error(ErrorCodes.ObjectMissing, exception.Message));

            default:
                return(new Error(ErrorCodes.Undefined, exception.Message));
            }
        }
Пример #2
0
        public void Error_ReturnsNonFatal_OnServiceException()
        {
            var target     = new LaunchPad();
            var mockLogger = new MockLogger();
            var output     = new ServiceOperationException(ServiceOperationError.BadParameter, "Yuba bears");
            var result     = LaunchPad.Error(output, mockLogger);

            AssertEx.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
            AssertEx.AreEqual(1, mockLogger.Logs.Count);

            var stuff = JsonConvert.DeserializeObject <TestResponse>(
                result.Content.ReadAsStringAsync().Result);

            AssertEx.AreEqual(0, stuff.Count);
            AssertEx.AreEqual(new string[0], stuff.Values);
            AssertEx.AreEqual(ServiceOperationError.BadParameter.ToString(), stuff.ErrorCode);
            AssertEx.StartsWith("Yuba bears\r\nThe Log Key for this error is", stuff.ErrorMessage);
        }