-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨Add UnitsNetSetup to hold global static state (#1267)
Added `UnitsNetSetup` to gather global state in a single place as a singleton, with the possibility of passing instances of it to static methods later to override the defaults. This way, state is no longer scattered among multiple classes that depend on each other in non-obvious ways and where initialization order has caused issues up until now. ### Changes - Add `UnitsNetSetup` to hold global state as a singleton property `Default` that controls default state initialization. - Add properties for all "services" that depend on global state: `UnitConverter, UnitAbbreviationsCache, UnitParser, QuantityParser` - Forward all other `Default` singleton properties from these services to `UnitsNetSetup.Default` and mark obsolete - Add some TODOs where it seems functionality is missing ### Testing ❌ Still running into a handful of flaky tests due to racing conditions. This was a regression in #1210, but still not fixed. Will investigate and fix in separate PR. ``` UnitAbbreviationsCacheTests.AllUnitsImplementToStringForInvariantCulture UnitAbbreviationsCacheTests.MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits ```
- Loading branch information
1 parent
49f8864
commit 5f13d99
Showing
13 changed files
with
440 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace UnitsNet.Tests; | ||
|
||
/// <summary> | ||
/// Useful for debugging tests where a particular order of tests is required. | ||
/// </summary> | ||
/// <example> | ||
/// Add the attribute to your test class: | ||
/// <code> | ||
/// <![CDATA[ | ||
/// [TestCaseOrderer( | ||
/// ordererTypeName: "UnitsNet.Tests.AlphabeticalOrderer", | ||
/// ordererAssemblyName: "UnitsNet.Tests")] | ||
/// ]]> | ||
/// </code> | ||
/// </example> | ||
public class AlphabeticalOrderer : ITestCaseOrderer | ||
{ | ||
public IEnumerable<TTestCase> OrderTestCases<TTestCase>( | ||
IEnumerable<TTestCase> testCases) where TTestCase : ITestCase => | ||
testCases.OrderBy(testCase => testCase.TestMethod.Method.Name); | ||
} |
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
Oops, something went wrong.