Skip to content

Commit

Permalink
Capturing last response and last test failure for dumping
Browse files Browse the repository at this point in the history
  • Loading branch information
ebekker committed Jan 12, 2016
1 parent aa7f790 commit c6ee5bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 23 additions & 0 deletions ACMESharp/ACMESharp-test/AcmeClientUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public class AcmeClientUnitTests
private static string _testCertRequRefreshed_AcmeCertRequFile = $"{DEFAULT_BASE_LOCAL_STORE}\\501-TestCertRequ-Refreshed.acmeCertRequ";
private static string _testCertRequRefreshed_CerFile = $"{DEFAULT_BASE_LOCAL_STORE}\\502-TestCertRequ-Refreshed.cer";

public static AcmeClient LastAcmeClient
{ get; set; }

public TestContext TestContext
{ get; set; }

[ClassInitialize]
public static void OneTimeSetup(TestContext tctx)
{
Expand Down Expand Up @@ -107,9 +113,26 @@ private static AcmeClient BuildClient(Uri rootUrl = null, ISigner signer = null,
x.Headers.Add("X-ACME-TestTag", testTagHeader);
};

LastAcmeClient = c;
return c;
}

[TestCleanup]
public void TestCleanup()
{
var testOut = TestContext.CurrentTestOutcome;

if (testOut.HasFlag(UnitTestOutcome.Error)
|| testOut.HasFlag(UnitTestOutcome.Failed))
{
if (LastAcmeClient?.LastResponse != null)
{
var lastResponse = LastAcmeClient.LastResponse.ContentAsString;
Console.Error.WriteLine($"Failed Test: Last Response = [{lastResponse}]")
}
}
}

[TestMethod]
[TestCategory("acmeServerInteg")]
public void Test0010_Init()
Expand Down
13 changes: 11 additions & 2 deletions ACMESharp/ACMESharp/AcmeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public bool Initialized
public string NextNonce
{ get; private set; }

public AcmeHttpResponse LastResponse
{ get; private set; }

#endregion -- Properties --

#region -- Methods --
Expand Down Expand Up @@ -626,7 +629,9 @@ private AcmeHttpResponse RequestHttpGet(Uri uri)
using (var resp = (HttpWebResponse)requ.GetResponse())
{
ExtractNonce(resp);
return new AcmeHttpResponse(resp);
var acmeResp = new AcmeHttpResponse(resp);
LastResponse = acmeResp;
return acmeResp;
}
}
catch (WebException ex) when (ex.Response != null)
Expand All @@ -638,6 +643,7 @@ private AcmeHttpResponse RequestHttpGet(Uri uri)
IsError = true,
Error = ex,
};
LastResponse = acmeResp;

if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType
&& !string.IsNullOrEmpty(acmeResp.ContentAsString))
Expand Down Expand Up @@ -685,7 +691,9 @@ private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
using (var resp = (HttpWebResponse)requ.GetResponse())
{
ExtractNonce(resp);
return new AcmeHttpResponse(resp);
var acmeResp = new AcmeHttpResponse(resp);
LastResponse = acmeResp;
return acmeResp;
}
}
catch (WebException ex) when (ex.Response != null)
Expand All @@ -697,6 +705,7 @@ private AcmeHttpResponse RequestHttpPost(Uri uri, object message)
IsError = true,
Error = ex,
};
LastResponse = acmeResp;

if (ProblemDetailResponse.CONTENT_TYPE == resp.ContentType
&& !string.IsNullOrEmpty(acmeResp.ContentAsString))
Expand Down

0 comments on commit c6ee5bc

Please sign in to comment.