File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed
src/CodeOfChaos.Extensions
tests/Tests.CodeOfChaos.Extensions Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 11// ---------------------------------------------------------------------------------------------------------------------
22// Imports
33// ---------------------------------------------------------------------------------------------------------------------
4+ using System . Collections . Concurrent ;
5+
46// ReSharper disable once CheckNamespace
57namespace System ;
68// ---------------------------------------------------------------------------------------------------------------------
79// Code
810// ---------------------------------------------------------------------------------------------------------------------
911public static class EnumExtensions {
10- private static readonly Dictionary < Type , Array > EnumValuesCache = new ( ) ;
12+ private static readonly ConcurrentDictionary < Type , Array > EnumValuesCache = new ( ) ;
1113
1214 /// <summary>
1315 /// Retrieves all values of the specified enum type from the cache, falling back to reflection if uncached.
1416 /// </summary>
1517 private static IEnumerable < T > GetEnumValues < T > ( ) where T : struct , Enum {
16- if ( EnumValuesCache . TryGetValue ( typeof ( T ) , out var values ) ) return ( T [ ] ) values ;
18+ if ( EnumValuesCache . TryGetValue ( typeof ( T ) , out Array ? values ) ) return ( T [ ] ) values ;
1719
1820 values = Enum . GetValues < T > ( ) ;
1921 EnumValuesCache [ typeof ( T ) ] = values ;
Original file line number Diff line number Diff line change 11// ---------------------------------------------------------------------------------------------------------------------
22// Imports
33// ---------------------------------------------------------------------------------------------------------------------
4+ using TUnit . Core . Exceptions ;
5+
46namespace Tests . CodeOfChaos . Extensions ;
57
68// ---------------------------------------------------------------------------------------------------------------------
@@ -105,9 +107,33 @@ public async Task ToGuid_ShouldThrowException_WhenInputIsInvalid(string input) {
105107 // Arrange
106108
107109 // Act
108- Func < Guid > act = input . ToGuid ;
109110
110111 // Assert
111- await Assert . That ( act ) . Throws < FormatException > ( ) ;
112+ Assert . Throws < TUnitException > ( ( ) => input . ToGuid ( ) ) ;
113+ }
114+
115+
116+ [ Test ]
117+ [ Arguments ( "test" , "00000000-0000-0000-0000-000000000000" ) ]
118+ public async Task ToGuidAsHash_ShouldReturnSameGuid ( string input , string expectedGuidString ) {
119+
120+
121+ }
122+
123+ [ Test ]
124+ [ Arguments ( "test" ) ]
125+ [ Arguments ( "some_data" ) ]
126+ [ Arguments ( "1234" ) ]
127+ [ Arguments ( "" ) ]
128+ public async Task ToGuidAsHash_ShouldReturnSameGuid_ForSameString ( string input ) {
129+ // Arrange
130+
131+ // Act
132+ Guid guid1 = input . ToGuidAsHashed ( ) ;
133+ Guid guid2 = input . ToGuidAsHashed ( ) ;
134+
135+ // Assert
136+ await Assert . That ( guid1 ) . IsEqualTo ( guid2 ) ;
137+ await Assert . That ( guid2 ) . IsEqualTo ( guid1 ) ;
112138 }
113139}
You can’t perform that action at this time.
0 commit comments