internal async Task OnProjectChangedAsync_WhenProjectUnloaded_TriggersCancellation() { var unloadSource = new CancellationTokenSource(); var instance = await CreateInitializedInstanceAsync( tasksService : IUnconfiguredProjectTasksServiceFactory.ImplementUnloadCancellationToken(unloadSource.Token)); var registration = IDataProgressTrackerServiceRegistrationFactory.Create(); var activeConfiguredProject = ConfiguredProjectFactory.Create(); var update = IProjectVersionedValueFactory.CreateEmpty(); await Assert.ThrowsAsync <OperationCanceledException>(() => { return(instance.OnProjectChangedAsync( registration, activeConfiguredProject, update, hasChange: _ => true, applyFunc: (_, _, _, token) => { // Simulate project unload during callback unloadSource.Cancel(); token.ThrowIfCancellationRequested(); })); }); }
public static IDataProgressTrackerService Create() { var mock = new Mock <IDataProgressTrackerService>(); mock.Setup(s => s.RegisterOutputDataSource(It.IsAny <IProgressTrackerOutputDataSource>())) .Returns(IDataProgressTrackerServiceRegistrationFactory.Create()); return(mock.Object); }
internal async Task OnProjectChangedAsync_WhenInstanceDisposed_TriggersCancellation() { var instance = await CreateInitializedInstanceAsync(); var registration = IDataProgressTrackerServiceRegistrationFactory.Create(); var activeConfiguredProject = ConfiguredProjectFactory.Create(); var update = IProjectVersionedValueFactory.CreateEmpty(); await Assert.ThrowsAsync <OperationCanceledException>(() => { return(instance.OnProjectChangedAsync( registration, activeConfiguredProject, update, hasChange: _ => true, applyFunc: (_, _, state, token) => { // Dispose the instance underneath us instance !.DisposeAsync().Wait(); token.ThrowIfCancellationRequested(); })); });