@@ -225,29 +225,137 @@ public void ToStringOrNullShouldProduceExpectedResultWhenObjectIsNotNull()
225225 Assert . Equal ( expected , actual ) ;
226226 }
227227
228- [ Fact ( DisplayName = "ToSuccessResult should produce the expected result" ) ]
229- public void ToSuccessResultShouldProduceTheExpectedResult ( )
228+ [ Fact ( DisplayName = "ToOptional should produce the expected result when using a non-null reference type " ) ]
229+ public void ToOptionalShouldProduceExpectedResultWhenUsingNonNullReferenceType ( )
230230 {
231231 // Given
232232 const string expected = "abc" ;
233233
234234 // When
235- Result < string > result = expected . ToSuccessResult ( ) ;
235+ Optional < string > optional = expected . ToOptional ( ) ;
236+
237+ // Then
238+ Some < string > some = Assert . IsType < Some < string > > ( optional ) ;
239+ Assert . Equal ( expected , some . Value ) ;
240+ }
241+
242+ [ Fact ( DisplayName = "ToOptional should produce the expected result when using a null reference type" ) ]
243+ public void ToOptionalShouldProduceExpectedResultWhenUsingNullReferenceType ( )
244+ {
245+ // Given
246+ const string ? expected = null ;
247+
248+ // When
249+ Optional < string > optional = expected . ToOptional ( ) ;
250+
251+ // Then
252+ Assert . IsType < None < string > > ( optional ) ;
253+ }
254+
255+ [ Fact ( DisplayName = "ToOptional should produce the expected result when using a non-null value type" ) ]
256+ public void ToOptionalShouldProduceExpectedResultWhenUsingNonNullValueType ( )
257+ {
258+ // Given
259+ const int expected = 123 ;
260+
261+ // When
262+ Optional < int > optional = expected . ToOptional ( ) ;
263+
264+ // Then
265+ Some < int > some = Assert . IsType < Some < int > > ( optional ) ;
266+ Assert . Equal ( expected , some . Value ) ;
267+ }
268+
269+ [ Fact ( DisplayName = "ToOptional should produce the expected result when using a null value type" ) ]
270+ public void ToOptionalShouldProduceExpectedResultWhenUsingNullValueType ( )
271+ {
272+ // Given
273+ int ? expected = null ;
274+
275+ // When
276+ Optional < int > optional = expected . ToOptional ( ) ;
277+
278+ // Then
279+ Assert . IsType < None < int > > ( optional ) ;
280+ }
281+
282+ [ Fact ( DisplayName = "ToOptionalAsync should produce the expected result when using a non-null reference type" ) ]
283+ public async Task ToOptionalAsyncShouldProduceExpectedResultWhenUsingNonNullReferenceType ( )
284+ {
285+ // Given
286+ const string expected = "abc" ;
287+
288+ // When
289+ Optional < string > optional = await Task . FromResult < string ? > ( expected ) . ToOptionalAsync ( ) ;
290+
291+ // Then
292+ Some < string > some = Assert . IsType < Some < string > > ( optional ) ;
293+ Assert . Equal ( expected , some . Value ) ;
294+ }
295+
296+ [ Fact ( DisplayName = "ToOptionalAsync should produce the expected result when using a null reference type" ) ]
297+ public async Task ToOptionalAsyncShouldProduceExpectedResultWhenUsingNullReferenceType ( )
298+ {
299+ // Given
300+ const string ? expected = null ;
301+
302+ // When
303+ Optional < string > optional = await Task . FromResult ( expected ) . ToOptionalAsync ( ) ;
304+
305+ // Then
306+ Assert . IsType < None < string > > ( optional ) ;
307+ }
308+
309+ [ Fact ( DisplayName = "ToOptionalAsync should produce the expected result when using a non-null value type" ) ]
310+ public async Task ToOptionalAsyncShouldProduceExpectedResultWhenUsingNonNullValueType ( )
311+ {
312+ // Given
313+ const int expected = 123 ;
314+
315+ // When
316+ Optional < int > optional = await Task . FromResult ( expected ) . ToOptionalAsync ( ) ;
317+
318+ // Then
319+ Some < int > some = Assert . IsType < Some < int > > ( optional ) ;
320+ Assert . Equal ( expected , some . Value ) ;
321+ }
322+
323+ [ Fact ( DisplayName = "ToOptionalAsync should produce the expected result when using a null value type" ) ]
324+ public async Task ToOptionalAsyncShouldProduceExpectedResultWhenUsingNullValueType ( )
325+ {
326+ // Given
327+ int ? expected = null ;
328+
329+ // When
330+ Optional < int > optional = await Task . FromResult ( expected ) . ToOptionalAsync ( ) ;
331+
332+ // Then
333+ Assert . IsType < None < int > > ( optional ) ;
334+ }
335+
336+ [ Fact ( DisplayName = "ToSuccess should produce the expected result" ) ]
337+ public void ToSuccessShouldProduceTheExpectedResult ( )
338+ {
339+ // Given
340+ const string expected = "abc" ;
341+
342+ // When
343+ Result < string > result = expected . ToSuccess ( ) ;
236344
237345 // Then
238346 Success < string > success = Assert . IsType < Success < string > > ( result ) ;
239347 Assert . Equal ( expected , success . Value ) ;
240348 }
241349
242- [ Fact ( DisplayName = "ToSuccessResultAsync should produce the expected result" ) ]
243- public async Task ToSuccessResultAsyncShouldProduceTheExpectedResult ( )
350+ [ Fact ( DisplayName = "ToSuccessAsync should produce the expected result" ) ]
351+ public async Task ToSuccessAsyncShouldProduceTheExpectedResult ( )
244352 {
245353 // Given
246354 const string expected = "abc" ;
247355
248356 // When
249357 Task < string > task = Task . FromResult ( expected ) ;
250- Result < string > result = await task . ToSuccessResultAsync ( ) ;
358+ Result < string > result = await task . ToSuccessAsync ( ) ;
251359
252360 // Then
253361 Success < string > success = Assert . IsType < Success < string > > ( result ) ;
0 commit comments