Skip to content

Commit f6542d5

Browse files
Fixup tests
1 parent a111984 commit f6542d5

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

src/EditorFeatures/Core/IntelliSense/AbstractController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ private void OnTextViewClosed(object sender, EventArgs e)
7878
this.TextView.TextBuffer.PostChanged -= this.OnTextViewBufferPostChanged;
7979
}
8080

81-
public Task WaitForModelComputation_ForTestingPurposesOnlyAsync()
81+
public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
8282
{
8383
this.ThreadingContext.ThrowIfNotOnUIThread();
8484
VerifySessionIsActive();
85-
return sessionOpt.WaitForModelComputation_ForTestingPurposesOnlyAsync();
85+
return sessionOpt.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync();
8686
}
8787

8888
void IController<TModel>.OnModelUpdated(TModel result, bool updateController)

src/EditorFeatures/Core/IntelliSense/ISession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ internal interface ISession<TModel>
1414

1515
void Stop();
1616

17-
Task WaitForModelComputation_ForTestingPurposesOnlyAsync();
17+
Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync();
1818
}

src/EditorFeatures/Core/IntelliSense/ModelComputation.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,19 @@ public Task<TModel> ModelTask
8181
}
8282
}
8383

84-
public Task WaitForModelComputation_ForTestingPurposesOnlyAsync()
85-
=> ModelTask;
84+
public async Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
85+
{
86+
var model = await ModelTask.ConfigureAwait(true);
87+
if (!_notifyControllerTask.IsCompleted)
88+
{
89+
// Reset lastTask so controller.OnModelUpdated is only called once
90+
_lastTask = Task.FromResult(model);
91+
}
92+
93+
await _notifyControllerTask.ConfigureAwait(true);
94+
}
8695

87-
public virtual void Stop()
96+
public void Stop()
8897
{
8998
ThreadingContext.ThrowIfNotOnUIThread();
9099

src/EditorFeatures/Core/IntelliSense/Session.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public virtual void Stop()
5353
this.PresenterSession.Dismiss();
5454
}
5555

56-
public Task WaitForModelComputation_ForTestingPurposesOnlyAsync()
56+
public Task WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
5757
{
5858
Computation.ThreadingContext.ThrowIfNotOnUIThread();
59-
return Computation.WaitForModelComputation_ForTestingPurposesOnlyAsync();
59+
return Computation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync();
6060
}
6161
}

src/EditorFeatures/Test2/IntelliSense/ModelTests.vb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
5656
Dim model = New Model()
5757
Dim controller = New Mock(Of IController(Of Model))(MockBehavior.Strict)
5858
controller.Setup(Function(c) c.BeginAsyncOperation("", Nothing, It.IsAny(Of String), It.IsAny(Of Integer))).Returns(EmptyAsyncToken.Instance)
59-
controller.Setup(Sub(c) c.OnModelUpdated(model, True))
59+
controller.Setup(Sub(c) c.OnModelUpdated(model, False))
60+
6061
Dim modelComputation = TestModelComputation.Create(threadingContext, controller:=controller.Object)
6162

6263
modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model))
63-
Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync()
64+
Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
6465

65-
controller.Verify(Sub(c) c.OnModelUpdated(model, True))
66+
controller.Verify(Sub(c) c.OnModelUpdated(model, False))
6667
End Function
6768

6869
<WpfFact>
@@ -83,9 +84,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
8384
End Function)
8485
modelComputation.ChainTaskAndNotifyControllerWhenFinished(Function(m, c) Task.FromResult(model))
8586
Monitor.Exit(gate)
86-
Await modelComputation.WaitForModelComputation_ForTestingPurposesOnlyAsync()
87+
Await modelComputation.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
8788

88-
controller.Verify(Sub(c) c.OnModelUpdated(model, True), Times.Once)
89+
controller.Verify(Sub(c) c.OnModelUpdated(DirectCast(Nothing, Model), False), Times.Once)
8990
End Function
9091

9192
<WpfFact>

src/EditorFeatures/Test2/IntelliSense/SignatureHelpControllerTests.vb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
3232

3333
GetMocks(controller).PresenterSession.Setup(Sub(p) p.Dismiss())
3434

35-
Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync()
35+
Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
3636

3737
Assert.Equal(0, GetMocks(controller).Provider.GetItemsCount)
3838
End Function
@@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
8080
Dim controller = Await CreateController(CreateWorkspace(), waitForPresentation:=True)
8181

8282
Mock.Get(GetMocks(controller).View.Object.Caret).Raise(Sub(c) AddHandler c.PositionChanged, Nothing, New CaretPositionChangedEventArgs(Nothing, Nothing, Nothing))
83-
Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync()
83+
Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
8484

8585
' GetItemsAsync is called once initially, and then once as a result of handling the PositionChanged event
8686
Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount)
@@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
9393
DirectCast(controller, IChainedCommandHandler(Of TypeCharCommandArgs)).ExecuteCommand(
9494
New TypeCharCommandArgs(CreateMock(Of ITextView), CreateMock(Of ITextBuffer), ")"c),
9595
Sub() GetMocks(controller).Buffer.Insert(0, ")"), TestCommandExecutionContext.Create())
96-
Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync()
96+
Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
9797

9898
' GetItemsAsync is called once initially, and then once as a result of handling the typechar command
9999
Assert.Equal(2, GetMocks(controller).Provider.GetItemsCount)
@@ -185,7 +185,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
185185
DirectCast(controller, IChainedCommandHandler(Of InvokeSignatureHelpCommandArgs)).ExecuteCommand(
186186
New InvokeSignatureHelpCommandArgs(view.Object, buffer), Nothing, TestCommandExecutionContext.Create())
187187
If waitForPresentation Then
188-
Await controller.WaitForModelComputation_ForTestingPurposesOnlyAsync()
188+
Await controller.WaitForModelComputationAndControllerNotification_ForTestingPurposesOnlyAsync()
189189
End If
190190
End If
191191

0 commit comments

Comments
 (0)