Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Test for Exception.ToString() calling derived implementation #37960

Merged
merged 2 commits into from
May 31, 2019
Merged
Changes from all commits
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
25 changes: 23 additions & 2 deletions src/System.Runtime/tests/System/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,37 @@ private static (string, string, int) GetSourceInformation(
}
}

public class ExceptionDerivedTests : Exception
public class DerivedException : Exception
{
public override string Message
{
get => "DerivedException.Message";
}

public override string ToString()
{
return "DerivedException.ToString()";
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public static void Exception_SerializeObjectState()
{
var excp = new ExceptionDerivedTests();
var excp = new DerivedException();
Assert.Throws<PlatformNotSupportedException>(() => excp.SerializeObjectState += (exception, eventArgs) => eventArgs.AddSerializedState(null));
Assert.Throws<PlatformNotSupportedException>(() => excp.SerializeObjectState -= (exception, eventArgs) => eventArgs.AddSerializedState(null));
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public static void Exception_OverriddenToStringOnInnerException()
{
var inner = new DerivedException();
var excp = new Exception("msg", inner);

Assert.Contains("DerivedException.ToString()", excp.ToString());
Assert.DoesNotContain("DerivedException.Message", excp.ToString());
}
}

public class ExceptionDataTests : IDictionary_NonGeneric_Tests
Expand Down