-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored unit tests for ReflectionSource and thread-safe mode (#291)
* Removed usage of System.Reflection * All changes to SmartSettings.IsThreadSafeMode are performed by SmartFormat.Tests.TestUtils.ThreadSafeMode methods
- Loading branch information
Showing
11 changed files
with
84 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright SmartFormat Project maintainers and contributors. | ||
// Licensed under the MIT license. | ||
// | ||
|
||
using SmartFormat.Core.Settings; | ||
using SmartFormat.Pooling; | ||
|
||
namespace SmartFormat.Tests.TestUtils | ||
{ | ||
/// <summary> | ||
/// Change <see cref="SmartSettings.IsThreadSafeMode"/> during unit tests. | ||
/// </summary> | ||
public static class ThreadSafeMode | ||
{ | ||
/// <summary> | ||
/// Sets <see cref="SmartSettings.IsThreadSafeMode"/> to <see langword="true"/> | ||
/// and resets <see cref="PoolRegistry.Items"/> using the new mode. | ||
/// </summary> | ||
/// <returns>The current value of <see cref="SmartSettings.IsThreadSafeMode"/> before switching the mode.</returns> | ||
public static bool SwitchOn() | ||
{ | ||
return SwitchTo(true); | ||
} | ||
|
||
/// <summary> | ||
/// Sets <see cref="SmartSettings.IsThreadSafeMode"/> to <see langword="true"/> | ||
/// and resets <see cref="PoolRegistry.Items"/> using the new mode. | ||
/// </summary> | ||
/// <returns>The current value of <see cref="SmartSettings.IsThreadSafeMode"/> before switching the mode.</returns> | ||
public static bool SwitchOff() | ||
{ | ||
return SwitchTo(false); | ||
} | ||
|
||
/// <summary> | ||
/// Sets <see cref="SmartSettings.IsThreadSafeMode"/> to the <paramref name="newSetting"/>. | ||
/// and resets <see cref="PoolRegistry.Items"/> using the new mode. | ||
/// </summary> | ||
/// <returns>The value of <see cref="SmartSettings.IsThreadSafeMode"/> before switching the mode.</returns> | ||
public static bool SwitchTo(bool newSetting) | ||
{ | ||
var currentMode = SmartSettings.IsThreadSafeMode; | ||
SmartSettings.IsThreadSafeMode = newSetting; | ||
|
||
ResetThreadPools(newSetting); | ||
|
||
return currentMode; | ||
} | ||
|
||
private static void ResetThreadPools(bool mode) | ||
{ | ||
// Thread pools might not be created in thread-safe mode, | ||
// so we have to reset them | ||
foreach (dynamic p in PoolRegistry.Items.Values) | ||
{ | ||
p.Reset(mode); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters