From 16a1161f426c754af30ef3139d40622182a05425 Mon Sep 17 00:00:00 2001 From: Bobby Driggs Date: Wed, 17 Nov 2021 11:39:29 -0800 Subject: [PATCH] Update StrictMode to allow for RECURLY_STRICT_MODE to be optional Update unit test to explicitly set RECURLY_STRICT_MODE to TRUE for proper test execution --- Recurly.Tests/BaseClientTest.cs | 5 +++++ Recurly/Utils.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Recurly.Tests/BaseClientTest.cs b/Recurly.Tests/BaseClientTest.cs index 6b80ff0b..ca01cbef 100644 --- a/Recurly.Tests/BaseClientTest.cs +++ b/Recurly.Tests/BaseClientTest.cs @@ -138,10 +138,15 @@ public void WillThrowARecurlyErrorForUnknownErrors() [Fact] public void WillThrowAnApiErrorForUnknownErrorType() { + // Force RECURLY_STRICT_MODE for this test + Environment.SetEnvironmentVariable("RECURLY_STRICT_MODE", "TRUE"); + var client = MockClient.Build(UnknownTypeResponse()); // Instead of disabling strict mode, test with ArgumentException as proxy var exception = Assert.Throws(() => client.GetResource("benjamin", "param1", new DateTime(2020, 01, 01))); Assert.Matches("no valid exception class", exception.Message); + + Environment.SetEnvironmentVariable("RECURLY_STRICT_MODE", null); } [Fact] diff --git a/Recurly/Utils.cs b/Recurly/Utils.cs index dda939f8..2d0d0892 100644 --- a/Recurly/Utils.cs +++ b/Recurly/Utils.cs @@ -19,7 +19,7 @@ public static bool StrictMode { if (!strictMode.HasValue) { - strictMode = Environment.GetEnvironmentVariable("RECURLY_STRICT_MODE").ToUpper() == "TRUE"; + strictMode = Environment.GetEnvironmentVariable("RECURLY_STRICT_MODE")?.ToUpper() == "TRUE"; } } }