|
1 | | -// Copyright (c) .NET Foundation. All rights reserved. |
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. See License.txt in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using Microsoft.Azure.WebJobs.Host; |
| 6 | +using Microsoft.Azure.WebJobs.Script.Workers.Rpc; |
5 | 7 | using Xunit; |
6 | 8 |
|
7 | 9 | namespace Microsoft.Azure.WebJobs.Script.Tests.Extensions |
@@ -31,7 +33,55 @@ public void GetExceptionDetails_ReturnsExpectedResult() |
31 | 33 | Assert.Contains("System.Exception : some outer exception ---> System.InvalidOperationException : Some inner exception", exceptionDetails); |
32 | 34 | Assert.Contains("End of inner exception", exceptionDetails); |
33 | 35 | Assert.Contains("at Microsoft.Azure.WebJobs.Script.Tests.Extensions.ExceptionExtensionsTests.GetExceptionDetails_ReturnsExpectedResult()", exceptionDetails); |
34 | | - Assert.Contains("ExceptionExtensionsTests.cs : 20", exceptionDetails); |
| 36 | + Assert.Contains("ExceptionExtensionsTests.cs", exceptionDetails); |
| 37 | + } |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public void GetExceptionDetails_Rpc() |
| 41 | + { |
| 42 | + string rpcMessage = "rpcMessage"; |
| 43 | + Exception innerException = new RpcException("result", rpcMessage, "stack"); |
| 44 | + Exception outerException = new FunctionInvocationException("message", innerException); |
| 45 | + Exception fullException; |
| 46 | + |
| 47 | + try |
| 48 | + { |
| 49 | + throw outerException; |
| 50 | + } |
| 51 | + catch (Exception e) |
| 52 | + { |
| 53 | + fullException = e; |
| 54 | + } |
| 55 | + |
| 56 | + (string exceptionType, string exceptionMessage, string exceptionDetails, string formattedText) = fullException.GetSanitizedExceptionDetails("safe text"); |
| 57 | + |
| 58 | + Assert.Equal("Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException", exceptionType); |
| 59 | + Assert.DoesNotContain(rpcMessage, exceptionMessage); |
| 60 | + Assert.DoesNotContain(rpcMessage, exceptionDetails); |
| 61 | + Assert.Contains("safe text", formattedText); |
| 62 | + } |
| 63 | + |
| 64 | + [Fact] |
| 65 | + public void GetExceptionDetails_Rpc_Empty() |
| 66 | + { |
| 67 | + Exception innerException = new RpcException(string.Empty, string.Empty, string.Empty); |
| 68 | + Exception outerException = new FunctionInvocationException(string.Empty, innerException); |
| 69 | + Exception fullException; |
| 70 | + |
| 71 | + try |
| 72 | + { |
| 73 | + throw outerException; |
| 74 | + } |
| 75 | + catch (Exception e) |
| 76 | + { |
| 77 | + fullException = e; |
| 78 | + } |
| 79 | + |
| 80 | + (string exceptionType, string exceptionMessage, _, string formattedText) = fullException.GetSanitizedExceptionDetails("safe text"); |
| 81 | + |
| 82 | + Assert.Equal("Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException", exceptionType); |
| 83 | + Assert.Equal("Result: \nType: \nException: \nStack: ", exceptionMessage); |
| 84 | + Assert.Contains("safe text", formattedText); |
35 | 85 | } |
36 | 86 | } |
37 | 87 | } |
0 commit comments