Пример #1
0
        public static ErrorResponseDto FromException(ApplicationException ex)
        {
            switch (ex.GetType().ToString())
            {
            case "system.ApplicationException":
                return(new ErrorResponseDto
                {
                    ErrorCode = "ConfigError",
                    ErrorList = new List <string>()
                    {
                        ex.Message
                    },
                    ErrorMessage = "Configuración inválida o faltante inicializando el processor",
                    ErrorSource = "utg"
                });

            default:
                return(new ErrorResponseDto
                {
                    ErrorCode = "AlmostUnhandledException",
                    ErrorList = new List <string>()
                    {
                        ex.Message
                    },
                    ErrorMessage = "Error inesperado (exception) dentro del processor",
                    ErrorSource = "utg"
                });
            }
        }
Пример #2
0
        public void HttpError_ExceptionType_RoundTrips()
        {
            ApplicationException exception = new ApplicationException("HelloWorld");

            Assert.Reflection.Property(
                new HttpError(exception, includeErrorDetail: true),
                e => e.ExceptionType,
                expectedDefaultValue: exception.GetType().FullName,
                allowNull: true,
                roundTripTestValue: "HelloAgain");
        }
        public void CreateToken_WhenPublicSigningThrowsException_ExpectSameException()
        {
            var expectedException = new ApplicationException("public");
            var tokenDescriptor   = new PasetoSecurityTokenDescriptor(TestVersion, PasetoConstants.Purposes.Public);

            mockVersionStrategy.Setup(x => x.Sign(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SigningCredentials>()))
            .Throws(expectedException);

            var exception = Assert.Throws(expectedException.GetType(), () => sut.CreateToken(tokenDescriptor));

            exception.Should().Be(expectedException);
        }
Пример #4
0
        private static string FormatError(ApplicationException exception)
        {
            var error = string.Format("{0}\n\nHora: {1:HH:mm:ss}\n\nModulo: {2}\n\nTipo: {3}\n\nMensaje: {4}\n\nMensaje Interno: {5}",
                                      string.Empty.PadLeft(30, '='),
                                      DateTime.Now,
                                      exception.Source,
                                      exception.GetType(),
                                      exception.Message,
                                      exception.InnerException == null ? @"Mensaje vacio" : exception.InnerException.Message
                                      );

            return(error);
        }
Пример #5
0
        public void OuterExceptionPackageTest()
        {
            const string rollbarDataTitle      = "You have some coding to do...";
            const string innerExceptionMessage = "Forgotten method";

            System.Exception innerException   = new NotImplementedException(innerExceptionMessage);
            const string     exceptionMessage = "Application level exception";

            System.Exception exception = new ApplicationException(exceptionMessage, innerException);

            IRollbarPackage packagingStrategy =
                new ExceptionPackage(exception, rollbarDataTitle);

            Assert.IsFalse(packagingStrategy.MustApplySynchronously, "Expected to be an async strategy!");

            Data rollbarData = packagingStrategy.PackageAsRollbarData();

            Assert.AreEqual(rollbarDataTitle, rollbarData.Title, "Data title is properly set!");
            Assert.IsNotNull(rollbarData.Body);
            Assert.IsNotNull(rollbarData.Body.TraceChain);
            Assert.IsNull(rollbarData.Body.Trace);
            Assert.IsNull(rollbarData.Body.Message);
            Assert.IsNull(rollbarData.Body.CrashReport);

            Assert.AreEqual(2, rollbarData.Body.TraceChain.Length);

            Assert.IsNotNull(rollbarData.Body.TraceChain[0]);
            Assert.IsNotNull(rollbarData.Body.TraceChain[0].Exception);
            Assert.AreEqual(exceptionMessage, rollbarData.Body.TraceChain[0].Exception.Message);
            Assert.AreEqual(exception.GetType().FullName, rollbarData.Body.TraceChain[0].Exception.Class);

            Assert.IsNotNull(rollbarData.Body.TraceChain[1]);
            Assert.IsNotNull(rollbarData.Body.TraceChain[1].Exception);
            Assert.AreEqual(innerExceptionMessage, rollbarData.Body.TraceChain[1].Exception.Message);
            Assert.AreEqual(innerException.GetType().FullName, rollbarData.Body.TraceChain[1].Exception.Class);
        }
 public void AfterThrowing(ApplicationException aex)
 {
     Count(aex.GetType().Name);
 }
Пример #7
0
        public void ProcessExceptionTest()
        {
            Type[] exceptionTypes = new Type[]
            {
                typeof(OutOfMemoryException),
                typeof(DataServiceException),
                typeof(FormatException),
                typeof(DataServiceException),
            };

            // At-End is currently always true, because the IQueryable caching
            // doesn't give us a good point to fail before content is written out.
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension(CustomDataContext.ExceptionTypeArgument, exceptionTypes),
                new Dimension(CustomDataContext.ExceptionAtEndArgument, new object[] { true }),
                new Dimension("Format", SerializationFormatData.Values),
                new Dimension("WebServerLocation", new object[] { WebServerLocation.InProcess, WebServerLocation.Local }));

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                Type exceptionType             = (Type)values[CustomDataContext.ExceptionTypeArgument];
                bool exceptionAtEnd            = (bool)values[CustomDataContext.ExceptionAtEndArgument];
                SerializationFormatData format = (SerializationFormatData)values["Format"];
                WebServerLocation location     = (WebServerLocation)values["WebServerLocation"];

                // The local web server doesn't handle OOF gracefully - skip that case.
                if (exceptionType == typeof(OutOfMemoryException) &&
                    location == WebServerLocation.Local)
                {
                    return;
                }

                // No binary properties in the model.
                if (format.Name == "Binary")
                {
                    return;
                }

                // We need at least 1024 bytes to be written out for the default
                // StreamWriter used by the XmlTextWriter to flush out (at which point
                // we can assume that throwing at the end of the stream caused
                // a "partial send").
                //
                // However the implementation ends up using an XmlUtf8RawTextWriterIndent
                // object, with a BUFSIZE of 0x1800 as declared on XmlUtf8RawTextWriter.
                //
                // (0x1800 / "Customer 1".Length) + 1 is ideal, but we can make do with much less.
                int customerCount = (0xA0 / "Customer 1".Length) + 1;
                values[CustomDataContext.CustomerCountArgument] = customerCount;

                using (TestWebRequest request = TestWebRequest.CreateForLocation(location))
                {
                    request.DataServiceType  = typeof(CustomDataContext);
                    request.TestArguments    = values;
                    request.Accept           = format.MimeTypes[0];
                    request.RequestUriString =
                        (format.Name == "Text") ? "/Customers(" + customerCount + ")/ID/$value" : "/Customers";

                    Trace.WriteLine("Requesting " + request.RequestUriString);
                    Stream response           = new MemoryStream();
                    Exception thrownException = null;
                    try
                    {
                        request.SendRequest();
                        thrownException = new ApplicationException("No exception actually thrown.");
                    }
                    catch (Exception exception)
                    {
                        thrownException = exception;
                    }

                    // InProcess always throws WebException. Look in the inner exception for the right exception type.
                    if (location == WebServerLocation.InProcess && !format.IsPrimitive && exceptionType != typeof(OutOfMemoryException))
                    {
                        Assert.AreEqual(typeof(WebException), thrownException.GetType(), "InProcess should always throw WebException - Look in TestServiceHost.ProcessException");
                        thrownException = thrownException.InnerException;
                    }

                    // Exception may be wrapped by TargetInvocationException.
                    if (thrownException is TargetInvocationException)
                    {
                        thrownException = thrownException.InnerException;
                    }

                    TestUtil.CopyStream(request.GetResponseStream(), response);

                    response.Position = 0;
                    if (exceptionAtEnd && !format.IsPrimitive)
                    {
                        // for inprocess, there will be no exception in the payload
                        if (location == WebServerLocation.InProcess)
                        {
                            // Verify the exception type
                            Assert.AreEqual(exceptionType, thrownException.GetType(), "Exception type did not match");
                            return;
                        }

                        Assert.IsTrue(HasContent(response), "HasContent(response)");
                        Assert.IsTrue(String.Equals(request.Accept, TestUtil.GetMediaType(request.ResponseContentType), StringComparison.OrdinalIgnoreCase));
                        if (exceptionType != typeof(OutOfMemoryException))
                        {
                            string responseText = new StreamReader(response).ReadToEnd();
                            TestUtil.AssertContains(responseText, "error");
                            TestUtil.AssertContains(responseText, "message");
                        }

                        Assert.IsTrue(thrownException is ApplicationException, "No exception thrown.");
                    }
                    else
                    {
                        if (exceptionType == typeof(OutOfMemoryException))
                        {
                            if (location == WebServerLocation.InProcess)
                            {
                                Assert.IsTrue(thrownException is OutOfMemoryException, "thrownException is OutOfMemoryException");
                                Assert.IsTrue(exceptionAtEnd || !HasContent(response), "exceptionAtEnd || !HasContent(response)");
                            }
                            else
                            {
                                Assert.IsTrue(thrownException is WebException, "thrownException is WebException");
                            }
                        }
                        else
                        {
                            Assert.IsTrue(thrownException is WebException, "thrownException is WebException");
                            Assert.IsTrue(HasContent(response), "HasContent(response)");
                            string expected =
                                (location == WebServerLocation.InProcess) ? "text/plain" : "application/xml";
                            Assert.AreEqual(expected, TestUtil.GetMediaType(request.ResponseContentType));
                        }
                    }
                }
            });
        }
Пример #8
0
 public void HttpError_ExceptionType_RoundTrips()
 {
     ApplicationException exception = new ApplicationException("HelloWorld");
     Assert.Reflection.Property(
         new HttpError(exception, includeErrorDetail: true),
         e => e.ExceptionType,
         expectedDefaultValue: exception.GetType().FullName,
         allowNull: true,
         roundTripTestValue: "HelloAgain");
 }