Skip to content

Commit

Permalink
Fix Debug.Assert behavior to match xunit <2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
voided committed Nov 9, 2015
1 parent 49e771c commit c377fd8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
11 changes: 11 additions & 0 deletions SteamKit2/Tests/ClientMsgFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using SteamKit2;
Expand Down Expand Up @@ -39,6 +40,16 @@ public class ClientMsgFacts
0x00,
};

public ClientMsgFacts()
{
// Debug.Assert's default behavior is to display a dialog if the default trace listener is still installed
// xunit prior to 2.0 would disable the default trace listener and prevent the assert dialog
// since we're now on 2.0, we need to restore this behavior ourselves

Debug.Listeners.Clear();
Debug.Listeners.Add( new TraceAssertListener() );
}

[Fact]
public void PayloadReaderReadsNullTermString()
{
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions SteamKit2/Tests/Helpers/TraceAssertListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tests
{
class TraceAssertListener : TraceListener
{
public override void Fail( string message, string detailMessage )
{
throw new TraceAssertException( message, detailMessage );
}

public override void Write( string message )
{
}

public override void WriteLine( string message )
{
}
}

class TraceAssertException : Exception
{
public string AssertMessage { get; private set; }
public string AssertDetailedMessage { get; private set; }


public TraceAssertException( string message, string detailMessage )
{
AssertMessage = message;
AssertDetailedMessage = detailMessage;
}
}
}
4 changes: 3 additions & 1 deletion SteamKit2/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<Compile Include="ClientMsgFacts.cs" />
<Compile Include="CMClientFacts.cs" />
<Compile Include="DebugLogFacts.cs" />
<Compile Include="HandlerTestBase.cs" />
<Compile Include="Helpers\HandlerTestBase.cs" />
<Compile Include="Helpers\TraceAssertListener.cs" />
<Compile Include="KeyValueFacts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SmartCMServerListFacts.cs" />
Expand All @@ -93,6 +94,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down

0 comments on commit c377fd8

Please sign in to comment.