private static VsSafeProjectGuidService CreateInstance(IProjectAsynchronousTasksService tasksService = null, IProjectAsyncLoadDashboard loadDashboard = null)
        {
            var project = UnconfiguredProjectFactory.Create();

            tasksService  = tasksService ?? IProjectAsynchronousTasksServiceFactory.Create();
            loadDashboard = loadDashboard ?? IProjectAsyncLoadDashboardFactory.ImplementProjectLoadedInHost(() => Task.CompletedTask);

            return(new VsSafeProjectGuidService(project, tasksService, loadDashboard));
        }
        public void GetProjectGuidAsync_WhenProjectAlreadyUnloaded_ReturnsCancelledTask()
        {
            var tasksService  = IProjectAsynchronousTasksServiceFactory.ImplementUnloadCancellationToken(new CancellationToken(canceled: true));
            var loadDashboard = IProjectAsyncLoadDashboardFactory.ImplementProjectLoadedInHost(() => Task.Delay(Timeout.Infinite));

            var accessor = CreateInstance(tasksService, loadDashboard);

            var result = accessor.GetProjectGuidAsync();

            Assert.True(result.IsCanceled);
        }
        public async Task GetProjectGuidAsync_WhenProjectUnloads_CancelsTask()
        {
            var projectUnloaded = new CancellationTokenSource();
            var tasksService    = IProjectAsynchronousTasksServiceFactory.ImplementUnloadCancellationToken(projectUnloaded.Token);
            var loadDashboard   = IProjectAsyncLoadDashboardFactory.ImplementProjectLoadedInHost(() => Task.Delay(Timeout.Infinite));

            var accessor = CreateInstance(tasksService, loadDashboard);

            var result = accessor.GetProjectGuidAsync();

            Assert.False(result.IsCanceled);

            // Now "unload" the project
            projectUnloaded.Cancel();

            await Assert.ThrowsAsync <OperationCanceledException>(() =>
            {
                return(result);
            });
        }