@@ -33,7 +33,7 @@ namespace Ben.Demystifier.Test
|
||||
|
||||
// Assert
|
||||
var stackTrace = demystifiedException.ToString();
|
||||
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = string.Join("", stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
|
||||
// Remove items that vary between test runners
|
||||
.Where(s =>
|
||||
@@ -80,8 +80,5 @@ namespace Ben.Demystifier.Test
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
|
||||
private Regex ReplaceLineEndings = new Regex(" in [^\n\r]+");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Ben.Demystifier.Test
|
||||
|
||||
// Assert
|
||||
var stackTrace = demystifiedException.ToString();
|
||||
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
// Remove items that vary between test runners
|
||||
.Where(s =>
|
||||
@@ -53,7 +53,5 @@ namespace Ben.Demystifier.Test
|
||||
" at async Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()"},
|
||||
trace);
|
||||
}
|
||||
|
||||
private Regex ReplaceLineEndings = new Regex(" in [^\n\r]+");
|
||||
}
|
||||
}
|
||||
|
||||
14
test/Ben.Demystifier.Test/LineEndingsHelper.cs
Normal file
14
test/Ben.Demystifier.Test/LineEndingsHelper.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Ben.Demystifier.Test
|
||||
{
|
||||
internal static class LineEndingsHelper
|
||||
{
|
||||
private static readonly Regex ReplaceLineEndings = new Regex(" in [^\n\r]+");
|
||||
|
||||
public static string RemoveLineEndings(string original)
|
||||
{
|
||||
return ReplaceLineEndings.Replace(original, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace Ben.Demystifier.Test
|
||||
|
||||
// Assert
|
||||
var stackTrace = demystifiedException.ToString();
|
||||
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = stackTrace.Split(new[]{Environment.NewLine}, StringSplitOptions.None);
|
||||
|
||||
Assert.Equal(
|
||||
@@ -51,7 +51,7 @@ namespace Ben.Demystifier.Test
|
||||
|
||||
// Assert
|
||||
stackTrace = demystifiedException.ToString();
|
||||
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
trace = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
|
||||
Assert.Equal(
|
||||
@@ -76,7 +76,7 @@ namespace Ben.Demystifier.Test
|
||||
|
||||
// Assert
|
||||
var stackTrace = est.ToString();
|
||||
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
// Remove Full framework entries
|
||||
.Where(s => !s.StartsWith(" at bool System.Threading._ThreadPoolWaitCallbac") &&
|
||||
@@ -88,7 +88,5 @@ namespace Ben.Demystifier.Test
|
||||
" at bool System.Threading.ThreadPoolWorkQueue.Dispatch()"},
|
||||
trace);
|
||||
}
|
||||
|
||||
private Regex ReplaceLineEndings = new Regex(" in [^\n\r]+");
|
||||
}
|
||||
}
|
||||
|
||||
27
test/Ben.Demystifier.Test/ReflectionHelperTests.cs
Normal file
27
test/Ben.Demystifier.Test/ReflectionHelperTests.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Diagnostics.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace Ben.Demystifier.Test
|
||||
{
|
||||
public class ReflectionHelperTest
|
||||
{
|
||||
[Fact]
|
||||
public void IsValueTupleReturnsTrueForTupleWith1Element()
|
||||
{
|
||||
Assert.True(typeof(ValueTuple<int>).IsValueTuple());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValueTupleReturnsTrueForTupleWith1ElementWithOpenedType()
|
||||
{
|
||||
Assert.True(typeof(ValueTuple<>).IsValueTuple());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValueTupleReturnsTrueForTupleWith6ElementsWithOpenedType()
|
||||
{
|
||||
Assert.True(typeof(ValueTuple<,,,,,>).IsValueTuple());
|
||||
}
|
||||
}
|
||||
}
|
||||
76
test/Ben.Demystifier.Test/TuplesTests.cs
Normal file
76
test/Ben.Demystifier.Test/TuplesTests.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Ben.Demystifier.Test
|
||||
{
|
||||
public class TuplesTests
|
||||
{
|
||||
[Fact]
|
||||
public void DemistifiesAsyncMethodWithTuples()
|
||||
{
|
||||
Exception demystifiedException = null;
|
||||
|
||||
try
|
||||
{
|
||||
AsyncThatReturnsTuple().GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
demystifiedException = ex.Demystify();
|
||||
}
|
||||
|
||||
// Assert
|
||||
var stackTrace = demystifiedException.ToString();
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = string.Join("", stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
|
||||
|
||||
var expected = string.Join("", new[] {
|
||||
"System.ArgumentException: Value does not fall within the expected range.",
|
||||
" at async Task<(int left, int right)> Ben.Demystifier.Test.TuplesTests.AsyncThatReturnsTuple()",
|
||||
" at void Ben.Demystifier.Test.TuplesTests.DemistifiesAsyncMethodWithTuples()"});
|
||||
|
||||
Assert.Equal(expected, trace);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DemistifiesListOfTuples()
|
||||
{
|
||||
Exception demystifiedException = null;
|
||||
|
||||
try
|
||||
{
|
||||
ListOfTuples();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
demystifiedException = ex.Demystify();
|
||||
}
|
||||
|
||||
// Assert
|
||||
var stackTrace = demystifiedException.ToString();
|
||||
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
|
||||
var trace = string.Join("", stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
|
||||
|
||||
var expected = string.Join("", new[] {
|
||||
"System.ArgumentException: Value does not fall within the expected range.",
|
||||
" at List<(int left, int right)> Ben.Demystifier.Test.TuplesTests.ListOfTuples()",
|
||||
" at void Ben.Demystifier.Test.TuplesTests.DemistifiesListOfTuples()"});
|
||||
|
||||
Assert.Equal(expected, trace);
|
||||
}
|
||||
|
||||
async Task<(int left, int right)> AsyncThatReturnsTuple()
|
||||
{
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
List<(int left, int right)> ListOfTuples()
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user