DTLib.Demystifier/test/Ben.Demystifier.Test/GenericMethodDisplayStringTests.cs
Tyler Young aa10921687 Don't enumerate fields on generic type Def (#77)
* Don't enumerate fields on generic type Def

Prevent exception being thrown when generic type definition is not a constructed generic type when trying to retrieve field values.

Added TODO with suggestion as to how to diagnose type arguments for generic type definition to create a constructed generic type.

* add test demonstrating error
2018-11-12 00:10:22 +00:00

43 lines
1.1 KiB
C#

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;
namespace Ben.Demystifier.Test
{
public class GenericMethodDisplayStringTests
{
private static class Example<T>
{
// ReSharper disable once StaticMemberInGenericType
public static readonly StackFrame StackFrame;
static Example()
{
var fun = new Func<StackFrame>(() => new StackFrame(0, true));
StackFrame = fun();
}
}
[Fact]
public void DiagnosesGenericMethodDisplayString()
{
var sf = Example<Type>.StackFrame;
try
{
var s = EnhancedStackTrace.GetMethodDisplayString(sf.GetMethod());
Assert.True(true, "Does not throw exception when diagnosing generic method display string.");
}
catch (Exception ioe)
{
Assert.True(false, "Must not throw an exception when diagnosing generic method display string.");
}
}
}
}