Skip to content

Commit

Permalink
Small refactoring for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
savpek committed Jun 5, 2020
1 parent 10c3668 commit 92f41d9
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions tests/OmniSharp.Roslyn.CSharp.Tests/FilesChangedFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public async Task TestFileAddedToMSBuildWorkspaceOnCreation()
{
var watcher = host.GetExport<IFileSystemWatcher>();

var path = Path.GetDirectoryName(host.Workspace.CurrentSolution.Projects.First().FilePath);
var filePath = Path.Combine(path, "FileName.cs");
File.WriteAllText(filePath, "text");
var handler = GetRequestHandler(host);
await handler.Handle(new[] { new FilesChangedRequest() { FileName = filePath, ChangeType = FileChangeType.Create } });
var filePath = await AddFile(host);

Assert.Contains(host.Workspace.CurrentSolution.Projects.First().Documents, d => d.FilePath == filePath && d.Name == "FileName.cs");
}
Expand All @@ -46,22 +42,18 @@ public async Task TestFileMovedToPreviouslyEmptyDirectory()

var projectDirectory = Path.GetDirectoryName(host.Workspace.CurrentSolution.Projects.First().FilePath);

const string filename = "FileName.cs";
var filePath = Path.Combine(projectDirectory, filename);
File.WriteAllText(filePath, "text");
var handler = GetRequestHandler(host);
await handler.Handle(new[] { new FilesChangedRequest() { FileName = filePath, ChangeType = FileChangeType.Create } });
var filePath = await AddFile(host);

Assert.Contains(host.Workspace.CurrentSolution.Projects.First().Documents, d => d.FilePath == filePath && d.Name == "FileName.cs");

var nestedDirectory = Path.Combine(projectDirectory, "Nested");
Directory.CreateDirectory(nestedDirectory);

var destinationPath = Path.Combine(nestedDirectory, filename);
var destinationPath = Path.Combine(nestedDirectory, Path.GetFileName(filePath));
File.Move(filePath, destinationPath);

await handler.Handle(new[] { new FilesChangedRequest() { FileName = filePath, ChangeType = FileChangeType.Delete } });
await handler.Handle(new[] { new FilesChangedRequest() { FileName = destinationPath, ChangeType = FileChangeType.Create } });
await GetRequestHandler(host).Handle(new[] { new FilesChangedRequest() { FileName = filePath, ChangeType = FileChangeType.Delete } });
await GetRequestHandler(host).Handle(new[] { new FilesChangedRequest() { FileName = destinationPath, ChangeType = FileChangeType.Create } });

Assert.Contains(host.Workspace.CurrentSolution.Projects.First().Documents, d => d.FilePath == destinationPath && d.Name == "FileName.cs");
Assert.DoesNotContain(host.Workspace.CurrentSolution.Projects.First().Documents, d => d.FilePath == filePath && d.Name == "FileName.cs");
Expand Down

0 comments on commit 92f41d9

Please sign in to comment.