public async Task If_a_build_is_in_fly_the_second_one_will_wait_and_do_not_continue() { var buildEvents = new LogEntryList(); var buildEventsMessages = new List <string>(); var package = await Create.ConsoleWorkspaceCopy(isRebuildable : true); var barrier = new Barrier(2); using (LogEvents.Subscribe(e => { buildEvents.Add(e); buildEventsMessages.Add(e.Evaluate().Message); if (e.Evaluate().Message.StartsWith("Attempting building package ")) { barrier.SignalAndWait(10.Minutes()); } })) { await Task.WhenAll( Task.Run(() => package.FullBuild()), Task.Run(() => package.FullBuild())); } buildEventsMessages.Should() .Contain(e => e.StartsWith($"Building package {package.Name}")) .And .Contain(e => e.StartsWith($"Skipping build for package {package.Name}")); }
public async Task When_package_contains_simple_console_app_then_IsAspNet_is_false() { var package = await Create.ConsoleWorkspaceCopy(); await package.CreateRoslynWorkspaceForLanguageServicesAsync(new TimeBudget(30.Seconds())); package.IsWebProject.Should().BeFalse(); }
protected async Task <(ICodeRunner runner, Package workspace)> GetRunnerAndWorkspaceBuild( [CallerMemberName] string testName = null) { var workspace = await Create.ConsoleWorkspaceCopy(testName); var server = new RoslynWorkspaceServer(workspace); return(server, workspace); }
public async Task If_an_existing_file_is_modified_then_the_workspace_is_updated() { var package = (RebuildablePackage)await Create.ConsoleWorkspaceCopy(isRebuildable : true); var oldWorkspace = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); var existingFile = Path.Combine(package.Directory.FullName, "Program.cs"); File.WriteAllText(existingFile, "//this is Program.cs"); await Task.Delay(1000); var newWorkspace = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); newWorkspace.Should().NotBeSameAs(oldWorkspace); }
public async Task If_a_new_file_is_added_the_workspace_includes_the_file() { var package = (RebuildablePackage)await Create.ConsoleWorkspaceCopy(isRebuildable : true); var ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); var newFile = Path.Combine(package.Directory.FullName, "Sample.cs"); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().NotContain(filePath => filePath == newFile); File.WriteAllText(newFile, "//this is a new file"); ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath == newFile); }
public async Task If_an_existing_file_is_deleted_then_the_workspace_does_not_include_the_file() { var package = (RebuildablePackage)await Create.ConsoleWorkspaceCopy(isRebuildable : true); var ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); var existingFile = Path.Combine(package.Directory.FullName, "Program.cs"); ws.CurrentSolution.Projects.First().Documents.Should().Contain(d => d.FilePath == existingFile); File.Delete(existingFile); await Task.Delay(1000); ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); ws.CurrentSolution.Projects.First().Documents.Should().NotContain(d => d.FilePath == existingFile); }
public async Task If_an_already_built_package_contains_new_file_the_new_workspace_contains_the_file() { var oldPackage = await Create.ConsoleWorkspaceCopy(isRebuildable : true); var ws = await oldPackage.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); var newFile = Path.Combine(oldPackage.Directory.FullName, "Sample.cs"); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().NotContain(filePath => filePath == newFile); File.WriteAllText(newFile, "//this is a new file"); var newPackage = new RebuildablePackage(directory: oldPackage.Directory); ws = await newPackage.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath == newFile); }
public async Task If_the_project_file_is_changed_then_the_workspace_reflects_the_changes() { var package = (RebuildablePackage)await Create.ConsoleWorkspaceCopy(isRebuildable : true); var ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); var references = ws.CurrentSolution.Projects.First().MetadataReferences; references.Should().NotContain(reference => reference.Display.Contains("Microsoft.CodeAnalysis.CSharp.dll") && reference.Display.Contains("2.8.2")); await new Dotnet(package.Directory).AddPackage("Microsoft.CodeAnalysis", "2.8.2"); ws = await package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); references = ws.CurrentSolution.Projects.First().MetadataReferences; references.Should().Contain(reference => reference.Display.Contains("Microsoft.CodeAnalysis.CSharp.dll") && reference.Display.Contains("2.8.2")); }
public async Task If_an_already_built_package_contains_a_new_file_and_an_old_file_is_deleted_workspace_reflects_it() { var oldPackage = await Create.ConsoleWorkspaceCopy(isRebuildable : true); var sampleCsFile = Path.Combine(oldPackage.Directory.FullName, "Sample.cs"); File.WriteAllText(sampleCsFile, "//this is a file which will be deleted later"); var ws = await oldPackage.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath == sampleCsFile); File.Delete(sampleCsFile); var newFileAdded = Path.Combine(oldPackage.Directory.FullName, "foo.cs"); File.WriteAllText(newFileAdded, "//this is a file we have just created"); var newPackage = new RebuildablePackage(directory: oldPackage.Directory); ws = await newPackage.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().NotContain(filePath => filePath == sampleCsFile); ws.CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath == newFileAdded); }
public async Task If_a_build_is_in_progress_and_another_request_comes_in_both_are_resolved_using_the_final_one() { var vt = new TestScheduler(); var package = (RebuildablePackage)await Create.ConsoleWorkspaceCopy(isRebuildable : true, buildThrottleScheduler : vt); var workspace1 = package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); vt.AdvanceBy(TimeSpan.FromSeconds(0.2).Ticks); var newFile = Path.Combine(package.Directory.FullName, "Sample.cs"); File.WriteAllText(newFile, "//this is Sample.cs"); vt.AdvanceBy(TimeSpan.FromSeconds(0.2).Ticks); var workspace2 = package.CreateRoslynWorkspaceForRunAsync(new TimeBudget(30.Seconds())); vt.AdvanceBy(TimeSpan.FromSeconds(0.6).Ticks); workspace1.Should().BeSameAs(workspace2); var workspaces = await Task.WhenAll(workspace1, workspace2); workspaces[0].CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath.EndsWith("Sample.cs")); workspaces[1].CurrentSolution.Projects.First().Documents.Select(d => d.FilePath).Should().Contain(filePath => filePath.EndsWith("Sample.cs")); }