Skip to content

Commit 0e3250f

Browse files
committed
Adding null task cases for CreateContinuationTask
1 parent 45ef372 commit 0e3250f

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/Utilities/AsyncHelperTest.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
15
using System;
26
using System.Threading;
37
using System.Threading.Tasks;
@@ -619,6 +623,29 @@ public async Task ContinueTaskWithState_2Generics_TaskFaultsNoHandler()
619623

620624
#region CreateContinuationTask
621625

626+
[Fact]
627+
public void CreateContinuationTask_NullTask()
628+
{
629+
// Arrange
630+
Mock<Action> onSuccess = new();
631+
Mock<Action<Exception>> onFailure = new();
632+
Mock<Action> onCancellation = new();
633+
634+
// Act
635+
Task continuationTask = AsyncHelper.CreateContinuationTask(
636+
taskToContinue: null,
637+
onSuccess.Object,
638+
onFailure.Object,
639+
onCancellation.Object);
640+
641+
// Assert
642+
Assert.Null(continuationTask);
643+
644+
onSuccess.Verify(action => action(), Times.Once);
645+
onFailure.VerifyNeverCalled();
646+
onCancellation.VerifyNeverCalled();
647+
}
648+
622649
[Fact]
623650
public async Task CreateContinuationTask_TaskCompletes()
624651
{
@@ -638,6 +665,7 @@ public async Task CreateContinuationTask_TaskCompletes()
638665

639666
// Assert
640667
Assert.Equal(TaskStatus.RanToCompletion, continuationTask.Status);
668+
641669
onSuccess.Verify(action => action(), Times.Once);
642670
onFailure.VerifyNeverCalled();
643671
onCancellation.VerifyNeverCalled();
@@ -779,6 +807,31 @@ public async Task CreateContinuationTask_TaskFaultsNoHandler()
779807

780808
#region CreateContinuationTaskWithState<T1>
781809

810+
[Fact]
811+
public void CreateContinuationTaskWithState_1Generic_NullTask()
812+
{
813+
// Arrange
814+
const int state1 = 123;
815+
Mock<Action<int>> onSuccess = new();
816+
Mock<Action<int, Exception>> onFailure = new();
817+
Mock<Action<int>> onCancellation = new();
818+
819+
// Act
820+
Task continuationTask = AsyncHelper.CreateContinuationTaskWithState(
821+
taskToContinue: null,
822+
state1,
823+
onSuccess.Object,
824+
onFailure.Object,
825+
onCancellation.Object);
826+
827+
// Assert
828+
Assert.Null(continuationTask);
829+
830+
onSuccess.Verify(action => action(state1), Times.Once);
831+
onFailure.VerifyNeverCalled();
832+
onCancellation.VerifyNeverCalled();
833+
}
834+
782835
[Fact]
783836
public async Task CreateContinuationTaskWithState_1Generic_TaskCompletes()
784837
{
@@ -957,6 +1010,34 @@ public async Task CreateContinuationTaskWithState_1Generic_TaskFaultsNoHandler()
9571010

9581011
#region CreateContinuationTaskWithState<T1, T2>
9591012

1013+
[Fact]
1014+
public void CreateContinuationTaskWithState_2Generics_NullTask()
1015+
{
1016+
// Arrange
1017+
const int state1 = 123;
1018+
const int state2 = 234;
1019+
1020+
Mock<Action<int, int>> onSuccess = new();
1021+
Mock<Action<int, int, Exception>> onFailure = new();
1022+
Mock<Action<int, int>> onCancellation = new();
1023+
1024+
// Act
1025+
Task continuationTask = AsyncHelper.CreateContinuationTaskWithState(
1026+
taskToContinue: null,
1027+
state1,
1028+
state2,
1029+
onSuccess.Object,
1030+
onFailure.Object,
1031+
onCancellation.Object);
1032+
1033+
// Assert
1034+
Assert.Null(continuationTask);
1035+
1036+
onSuccess.Verify(action => action(state1, state2), Times.Once);
1037+
onFailure.VerifyNeverCalled();
1038+
onCancellation.VerifyNeverCalled();
1039+
}
1040+
9601041
[Fact]
9611042
public async Task CreateContinuationTaskWithState_2Generics_TaskCompletes()
9621043
{

src/Microsoft.Data.SqlClient/tests/UnitTests/Utilities/MockExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
15
using System;
26
using Moq;
37

0 commit comments

Comments
 (0)