11using System . Collections . Concurrent ;
2+ using System . Text ;
23#if FEATURE_GUID_PARSE
34using System . Collections . Generic ;
45#endif
@@ -11,54 +12,53 @@ namespace Testably.Abstractions.Tests.RandomSystem;
1112[ RandomSystemTests ]
1213public partial class GuidTests
1314{
15+ #if FEATURE_GUID_V7
1416 [ Fact ]
15- public async Task Empty_ShouldReturnEmptyGuid ( )
16- {
17- await That ( RandomSystem . Guid . Empty ) . IsEqualTo ( Guid . Empty ) ;
18- }
19-
20- [ Fact ]
21- public async Task NewGuid_ShouldBeThreadSafeAndReturnUniqueItems ( )
17+ public async Task CreateVersion7_ShouldBeThreadSafeAndReturnUniqueItems ( )
2218 {
2319 ConcurrentBag < Guid > results = [ ] ;
2420
2521 Parallel . For ( 0 , 100 , _ =>
2622 {
27- results . Add ( RandomSystem . Guid . NewGuid ( ) ) ;
23+ results . Add ( RandomSystem . Guid . CreateVersion7 ( ) ) ;
2824 } ) ;
2925
3026 await That ( results ) . AreAllUnique ( ) ;
3127 }
28+ #endif
3229
3330#if FEATURE_GUID_V7
3431 [ Fact ]
35- public async Task CreateVersion7_ShouldBeThreadSafeAndReturnUniqueItems ( )
32+ public async Task CreateVersion7_WithOffset_ShouldBeThreadSafeAndReturnUniqueItems ( )
3633 {
3734 ConcurrentBag < Guid > results = [ ] ;
3835
3936 Parallel . For ( 0 , 100 , _ =>
4037 {
41- results . Add ( RandomSystem . Guid . CreateVersion7 ( ) ) ;
38+ results . Add ( RandomSystem . Guid . CreateVersion7 ( DateTimeOffset . UtcNow ) ) ;
4239 } ) ;
4340
4441 await That ( results ) . AreAllUnique ( ) ;
4542 }
4643#endif
44+ [ Fact ]
45+ public async Task Empty_ShouldReturnEmptyGuid ( )
46+ {
47+ await That ( RandomSystem . Guid . Empty ) . IsEqualTo ( Guid . Empty ) ;
48+ }
4749
48- #if FEATURE_GUID_V7
4950 [ Fact ]
50- public async Task CreateVersion7_WithOffset_ShouldBeThreadSafeAndReturnUniqueItems ( )
51+ public async Task NewGuid_ShouldBeThreadSafeAndReturnUniqueItems ( )
5152 {
5253 ConcurrentBag < Guid > results = [ ] ;
5354
5455 Parallel . For ( 0 , 100 , _ =>
5556 {
56- results . Add ( RandomSystem . Guid . CreateVersion7 ( DateTimeOffset . UtcNow ) ) ;
57+ results . Add ( RandomSystem . Guid . NewGuid ( ) ) ;
5758 } ) ;
5859
5960 await That ( results ) . AreAllUnique ( ) ;
6061 }
61- #endif
6262
6363#if FEATURE_GUID_PARSE
6464 [ Theory ]
@@ -67,9 +67,9 @@ public async Task Parse_SpanArray_ShouldReturnCorrectGuid(Guid guid)
6767 {
6868 ReadOnlySpan < char > serializedGuid = guid . ToString ( ) . AsSpan ( ) ;
6969
70- #pragma warning disable MA0011
70+ #pragma warning disable MA0011
7171 Guid result = RandomSystem . Guid . Parse ( serializedGuid ) ;
72- #pragma warning restore MA0011
72+ #pragma warning restore MA0011
7373
7474 await That ( result ) . IsEqualTo ( guid ) ;
7575 }
@@ -82,9 +82,39 @@ public async Task Parse_String_ShouldReturnCorrectGuid(Guid guid)
8282 {
8383 string serializedGuid = guid . ToString ( ) ;
8484
85- #pragma warning disable MA0011
85+ #pragma warning disable MA0011
8686 Guid result = RandomSystem . Guid . Parse ( serializedGuid ) ;
87- #pragma warning restore MA0011
87+ #pragma warning restore MA0011
88+
89+ await That ( result ) . IsEqualTo ( guid ) ;
90+ }
91+ #endif
92+
93+ #if FEATURE_GUID_PARSE_UTF8
94+ [ Theory ]
95+ [ AutoData ]
96+ public async Task Parse_UTF8_ShouldReturnCorrectGuid ( Guid guid )
97+ {
98+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( guid . ToString ( ) ) ;
99+
100+ #pragma warning disable MA0011
101+ Guid result = RandomSystem . Guid . Parse ( bytes ) ;
102+ #pragma warning restore MA0011
103+
104+ await That ( result ) . IsEqualTo ( guid ) ;
105+ }
106+ #endif
107+
108+ #if FEATURE_GUID_PARSE_UTF8
109+ [ Theory ]
110+ [ AutoData ]
111+ public async Task Parse_UTF8_WithFormatProvider_ShouldReturnCorrectGuid ( Guid guid )
112+ {
113+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( guid . ToString ( ) ) ;
114+
115+ #pragma warning disable MA0011
116+ Guid result = RandomSystem . Guid . Parse ( bytes , CultureInfo . InvariantCulture ) ;
117+ #pragma warning restore MA0011
88118
89119 await That ( result ) . IsEqualTo ( guid ) ;
90120 }
@@ -150,9 +180,24 @@ public async Task TryParse_SpanArray_ShouldReturnTrue(Guid guid)
150180 {
151181 ReadOnlySpan < char > serializedGuid = guid . ToString ( ) . AsSpan ( ) ;
152182
153- #pragma warning disable MA0011
183+ #pragma warning disable MA0011
154184 bool result = RandomSystem . Guid . TryParse ( serializedGuid , out Guid value ) ;
155- #pragma warning restore MA0011
185+ #pragma warning restore MA0011
186+
187+ await That ( result ) . IsTrue ( ) ;
188+ await That ( value ) . IsEqualTo ( guid ) ;
189+ }
190+ #endif
191+
192+ #if FEATURE_GUID_FORMATPROVIDER
193+ [ Theory ]
194+ [ AutoData ]
195+ public async Task TryParse_SpanArray_WithFormatProvider_ShouldReturnTrue ( Guid guid )
196+ {
197+ ReadOnlySpan < char > serializedGuid = guid . ToString ( ) . AsSpan ( ) ;
198+
199+ bool result = RandomSystem . Guid . TryParse ( serializedGuid , CultureInfo . InvariantCulture ,
200+ out Guid value ) ;
156201
157202 await That ( result ) . IsTrue ( ) ;
158203 await That ( value ) . IsEqualTo ( guid ) ;
@@ -166,9 +211,9 @@ public async Task TryParse_String_ShouldReturnTrue(Guid guid)
166211 {
167212 string serializedGuid = guid . ToString ( ) ;
168213
169- #pragma warning disable MA0011
214+ #pragma warning disable MA0011
170215 bool result = RandomSystem . Guid . TryParse ( serializedGuid , out Guid value ) ;
171- #pragma warning restore MA0011
216+ #pragma warning restore MA0011
172217
173218 await That ( result ) . IsTrue ( ) ;
174219 await That ( value ) . IsEqualTo ( guid ) ;
@@ -178,9 +223,9 @@ public async Task TryParse_String_ShouldReturnTrue(Guid guid)
178223#if FEATURE_GUID_FORMATPROVIDER
179224 [ Theory ]
180225 [ AutoData ]
181- public async Task TryParse_WithFormatProvider_SpanArray_ShouldReturnTrue ( Guid guid )
226+ public async Task TryParse_String_WithFormatProvider_ShouldReturnTrue ( Guid guid )
182227 {
183- ReadOnlySpan < char > serializedGuid = guid . ToString ( ) . AsSpan ( ) ;
228+ string serializedGuid = guid . ToString ( ) ;
184229
185230 bool result = RandomSystem . Guid . TryParse ( serializedGuid , CultureInfo . InvariantCulture ,
186231 out Guid value ) ;
@@ -190,14 +235,30 @@ public async Task TryParse_WithFormatProvider_SpanArray_ShouldReturnTrue(Guid gu
190235 }
191236#endif
192237
193- #if FEATURE_GUID_FORMATPROVIDER
238+ #if FEATURE_GUID_PARSE_UTF8
194239 [ Theory ]
195240 [ AutoData ]
196- public async Task TryParse_WithFormatProvider_String_ShouldReturnTrue ( Guid guid )
241+ public async Task TryParse_UTF8_ShouldReturnTrue ( Guid guid )
197242 {
198- string serializedGuid = guid . ToString ( ) ;
243+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( guid . ToString ( ) ) ;
199244
200- bool result = RandomSystem . Guid . TryParse ( serializedGuid , CultureInfo . InvariantCulture ,
245+ #pragma warning disable MA0011
246+ bool result = RandomSystem . Guid . TryParse ( bytes , out Guid value ) ;
247+ #pragma warning restore MA0011
248+
249+ await That ( result ) . IsTrue ( ) ;
250+ await That ( value ) . IsEqualTo ( guid ) ;
251+ }
252+ #endif
253+
254+ #if FEATURE_GUID_PARSE_UTF8
255+ [ Theory ]
256+ [ AutoData ]
257+ public async Task TryParse_UTF8_WithFormatProvider_ShouldReturnTrue ( Guid guid )
258+ {
259+ byte [ ] bytes = Encoding . UTF8 . GetBytes ( guid . ToString ( ) ) ;
260+
261+ bool result = RandomSystem . Guid . TryParse ( bytes , CultureInfo . InvariantCulture ,
201262 out Guid value ) ;
202263
203264 await That ( result ) . IsTrue ( ) ;
@@ -240,7 +301,7 @@ public async Task TryParseExact_String_ShouldReturnTrue(string format, Guid guid
240301 #region Helpers
241302
242303#if FEATURE_GUID_PARSE
243- #pragma warning disable MA0018
304+ #pragma warning disable MA0018
244305 public static IEnumerable < object [ ] > GuidFormats ( )
245306 {
246307 yield return [ "N" ] ;
0 commit comments