This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathDefaultImportDocumentManagerIntegrationTest.cs
91 lines (76 loc) · 3.94 KB
/
DefaultImportDocumentManagerIntegrationTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Moq;
using Xunit;
namespace Microsoft.VisualStudio.Editor.Razor.Documents
{
public class DefaultImportDocumentManagerIntegrationTest : ForegroundDispatcherTestBase
{
public DefaultImportDocumentManagerIntegrationTest()
{
ProjectPath = TestProjectData.SomeProject.FilePath;
DirectoryPath = Path.GetDirectoryName(ProjectPath);
FileSystem = RazorProjectFileSystem.Create(Path.GetDirectoryName(ProjectPath));
ProjectEngine = RazorProjectEngine.Create(FallbackRazorConfiguration.MVC_2_1, FileSystem, b =>
{
// These tests rely on MVC's import behavior.
Microsoft.AspNetCore.Mvc.Razor.Extensions.RazorExtensions.Register(b);
});
}
private string DirectoryPath { get; }
private string ProjectPath { get; }
private RazorProjectFileSystem FileSystem { get; }
private RazorProjectEngine ProjectEngine { get; }
[ForegroundFact]
public void Changed_TrackerChanged_ResultsInChangedHavingCorrectArgs()
{
// Arrange
var testImportsPath = Path.Combine(DirectoryPath, "_ViewImports.cshtml");
var tracker = Mock.Of<VisualStudioDocumentTracker>(
t => t.FilePath == Path.Combine(DirectoryPath, "Views", "Home", "_ViewImports.cshtml") &&
t.ProjectPath == ProjectPath &&
t.ProjectSnapshot == Mock.Of<ProjectSnapshot>(p => p.GetProjectEngine() == ProjectEngine));
var anotherTracker = Mock.Of<VisualStudioDocumentTracker>(
t => t.FilePath == Path.Combine(DirectoryPath, "anotherFile.cshtml") &&
t.ProjectPath == ProjectPath &&
t.ProjectSnapshot == Mock.Of<ProjectSnapshot>(p => p.GetProjectEngine() == ProjectEngine));
var fileChangeTrackerFactory = new Mock<FileChangeTrackerFactory>();
var fileChangeTracker = new Mock<FileChangeTracker>();
fileChangeTracker
.Setup(f => f.FilePath)
.Returns(testImportsPath);
fileChangeTrackerFactory
.Setup(f => f.Create(testImportsPath))
.Returns(fileChangeTracker.Object);
fileChangeTrackerFactory
.Setup(f => f.Create(Path.Combine(DirectoryPath, "Views", "_ViewImports.cshtml")))
.Returns(Mock.Of<FileChangeTracker>());
fileChangeTrackerFactory
.Setup(f => f.Create(Path.Combine(DirectoryPath, "Views", "Home", "_ViewImports.cshtml")))
.Returns(Mock.Of<FileChangeTracker>());
var called = false;
var manager = new DefaultImportDocumentManager(Dispatcher, new DefaultErrorReporter(), fileChangeTrackerFactory.Object);
manager.OnSubscribed(tracker);
manager.OnSubscribed(anotherTracker);
manager.Changed += (sender, args) =>
{
called = true;
Assert.Same(sender, manager);
Assert.Equal(testImportsPath, args.FilePath);
Assert.Equal(FileChangeKind.Changed, args.Kind);
Assert.Collection(
args.AssociatedDocuments,
f => Assert.Equal(Path.Combine(DirectoryPath, "Views", "Home", "_ViewImports.cshtml"), f),
f => Assert.Equal(Path.Combine(DirectoryPath, "anotherFile.cshtml"), f));
};
// Act
fileChangeTracker.Raise(t => t.Changed += null, new FileChangeEventArgs(testImportsPath, FileChangeKind.Changed));
// Assert
Assert.True(called);
}
}
}