Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests on net472
  • Loading branch information
tonydnewell committed Aug 31, 2023
commit 5314bd6d5ddc8294fd3858344797fa731d659ac0
36 changes: 29 additions & 7 deletions test/Grpc.StatusProto.Tests/ExceptionExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
#endregion

using System.Text;
using Google.Rpc;
using NUnit.Framework;

namespace Grpc.StatusProto.Tests;
Expand All @@ -36,9 +38,13 @@ public void ToRpcDebugInfoTest()
var debugInfo = ex.ToRpcDebugInfo();
Assert.IsNotNull(debugInfo);
Assert.AreEqual("System.ArgumentException: extra details", debugInfo.Detail);
Assert.IsTrue(debugInfo.StackEntries.Count >= 2);
Assert.IsTrue(debugInfo.StackEntries[0].Contains("ExceptionExtensionsTest.ThrowException"));
Assert.IsTrue(debugInfo.StackEntries[1].Contains("ExceptionExtensionsTest.ToRpcDebugInfoTest"));

var stackTraces = ConcatStackTraces(debugInfo);
Console.WriteLine("Test stack trace data:");
Console.WriteLine(stackTraces);
Assert.IsTrue(stackTraces.Contains("ExceptionExtensionsTest.ThrowException"));
Assert.IsTrue(stackTraces.Contains("ExceptionExtensionsTest.ToRpcDebugInfoTest"));
Assert.IsFalse(stackTraces.Contains("InnerException:"));
}
}

Expand All @@ -54,10 +60,14 @@ public void ToRpcDebugInfo_WithInnerExceptionTest()
var debugInfo = ex.ToRpcDebugInfo(1);
Assert.IsNotNull(debugInfo);
Assert.AreEqual("System.ArgumentException: extra details", debugInfo.Detail);
Assert.IsTrue(debugInfo.StackEntries.Count >= 5);
Assert.IsTrue(debugInfo.StackEntries[0].Contains("ExceptionExtensionsTest.ThrowException"));
Assert.IsTrue(debugInfo.StackEntries[1].Contains("ExceptionExtensionsTest.ToRpcDebugInfo_WithInnerExceptionTest"));
Assert.IsTrue(debugInfo.StackEntries[2].Contains("InnerException:"));

var stackTraces = ConcatStackTraces(debugInfo);
Console.WriteLine("Test stack trace data:");
Console.WriteLine(stackTraces);
Assert.IsTrue(stackTraces.Contains("ExceptionExtensionsTest.ThrowException"));
Assert.IsTrue(stackTraces.Contains("ExceptionExtensionsTest.ToRpcDebugInfo_WithInnerExceptionTest"));
Assert.IsTrue(stackTraces.Contains("InnerException: System.ApplicationException: inner exception"));
Assert.IsTrue(stackTraces.Contains("ExceptionExtensionsTest.ThrowInnerException"));
}
}

Expand All @@ -77,4 +87,16 @@ private void ThrowInnerException(string message)
{
throw new System.ApplicationException(message);
}

private string ConcatStackTraces(DebugInfo debugInfo)
{
var sb = new StringBuilder();

foreach (var stackEntry in debugInfo.StackEntries)
{
sb.AppendLine(stackEntry);
}

return sb.ToString();
}
}