public void GetHostDocuments_SomeLegacyDocuments() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(LatestProjectConfigurationProvider.RazorGenerateWithTargetPathItemType, "file.cshtml", new Dictionary <string, string>() { [LatestProjectConfigurationProvider.RazorTargetPathMetadataName] = "path/file.cshtml", }); projectInstance.AddItem(LatestProjectConfigurationProvider.RazorGenerateWithTargetPathItemType, "otherfile.cshtml", new Dictionary <string, string>() { [LatestProjectConfigurationProvider.RazorTargetPathMetadataName] = "other/path/otherfile.cshtml", }); var projectDirectory = projectInstance.Directory; // Act var hostDocuments = LatestProjectConfigurationProvider.GetHostDocuments(projectInstance.Items); // Assert Assert.Collection( hostDocuments, hostDocument => { Assert.Equal(Path.Combine(projectDirectory, "file.cshtml"), hostDocument.FilePath); Assert.Equal("path\\file.cshtml", hostDocument.TargetPath); Assert.Equal(FileKinds.Legacy, hostDocument.FileKind); }, hostDocument => { Assert.Equal(Path.Combine(projectDirectory, "otherfile.cshtml"), hostDocument.FilePath); Assert.Equal("other\\path\\otherfile.cshtml", hostDocument.TargetPath); Assert.Equal(FileKinds.Legacy, hostDocument.FileKind); }); }
public void GetHostDocuments_SomeComponentDocuments() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(LatestProjectConfigurationProvider.RazorComponentWithTargetPathItemType, "file.razor", new Dictionary <string, string>() { [LatestProjectConfigurationProvider.RazorTargetPathMetadataName] = "path/file.razor", }); projectInstance.AddItem(LatestProjectConfigurationProvider.RazorComponentWithTargetPathItemType, "otherfile.razor", new Dictionary <string, string>() { [LatestProjectConfigurationProvider.RazorTargetPathMetadataName] = "other/path/otherfile.razor", }); // Act var hostDocuments = LatestProjectConfigurationProvider.GetHostDocuments(projectInstance.Items); // Assert Assert.Collection( hostDocuments, hostDocument => { Assert.Equal("file.razor", hostDocument.FilePath); Assert.Equal("path/file.razor", hostDocument.TargetPath); Assert.Equal(FileKinds.Component, hostDocument.FileKind); }, hostDocument => { Assert.Equal("otherfile.razor", hostDocument.FilePath); Assert.Equal("other/path/otherfile.razor", hostDocument.TargetPath); Assert.Equal(FileKinds.Component, hostDocument.FileKind); }); }
public void TryGetConfigurationItem_SucceedsForMatchingConfigurationItem() { // Arrange var expectedConfiguration = "Razor-13.37"; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem("RazorConfiguration", "Razor-10.0-DoesNotMatch"); var expectedConfigurationItem = projectInstance.AddItem("RazorConfiguration", expectedConfiguration); // Act var result = LatestProjectConfigurationProvider.TryGetConfigurationItem(expectedConfiguration, projectInstance.Items, out var configurationItem); // Assert Assert.True(result); Assert.Same(expectedConfigurationItem, configurationItem); }
public void AddItemNullMetadata() { ProjectInstance p = GetEmptyProjectInstance(); ProjectItemInstance item = p.AddItem("i", "i1", null); Assert.False(item.Metadata.GetEnumerator().MoveNext()); }
public void AddItemWithMetadata() { ProjectInstance p = GetEmptyProjectInstance(); var metadata = new List <KeyValuePair <string, string> >(); metadata.Add(new KeyValuePair <string, string>("m", "m1")); metadata.Add(new KeyValuePair <string, string>("n", "n1")); metadata.Add(new KeyValuePair <string, string>("o", "o%40")); ProjectItemInstance returned = p.AddItem("i", "i1", metadata); Assert.True(object.ReferenceEquals(returned, Helpers.MakeList(p.GetItems("i"))[0])); foreach (ProjectItemInstance item in p.Items) { Assert.Same(returned, item); Assert.Equal("i1", item.EvaluatedInclude); var metadataOut = Helpers.MakeList(item.Metadata); Assert.Equal(3, metadataOut.Count); Assert.Equal("m1", item.GetMetadataValue("m")); Assert.Equal("n1", item.GetMetadataValue("n")); Assert.Equal("o@", item.GetMetadataValue("o")); } }
/// <summary> /// Get a single item instance /// </summary> private static ProjectItemInstance GetItemInstance() { Project project = new Project(); ProjectInstance projectInstance = project.CreateProjectInstance(); ProjectItemInstance item = projectInstance.AddItem("i", "i1"); return(item); }
private static ProjectItemInstance GetItemInstance(string itemType, string evaluatedInclude) { Project project = new Project(); ProjectInstance projectInstance = project.CreateProjectInstance(); ProjectItemInstance item = projectInstance.AddItem(itemType, evaluatedInclude); return(item); }
public static IEnumerable <object[]> ProjectInstanceHasEvaluationIdTestData() { // from file (new) yield return(new ProjectInstanceFactory[] { (f, xml, c) => new ProjectInstance(f, null, null, c) }); // from file (factory method) yield return(new ProjectInstanceFactory[] { (f, xml, c) => ProjectInstance.FromFile(f, new ProjectOptions { ProjectCollection = c }) }); // from Project yield return(new ProjectInstanceFactory[] { (f, xml, c) => new Project(f, null, null, c).CreateProjectInstance() }); // from DeepCopy yield return(new ProjectInstanceFactory[] { (f, xml, c) => new ProjectInstance(f, null, null, c).DeepCopy() }); // from ProjectRootElement (new) yield return(new ProjectInstanceFactory[] { (f, xml, c) => new ProjectInstance(xml, null, null, c) }); // from ProjectRootElement (factory method) yield return(new ProjectInstanceFactory[] { (f, xml, c) => ProjectInstance.FromProjectRootElement(xml, new ProjectOptions { ProjectCollection = c }) }); // from translated project instance yield return(new ProjectInstanceFactory[] { (f, xml, c) => { var pi = new ProjectInstance(f, null, null, c); pi.AddItem("foo", "bar"); pi.TranslateEntireState = true; ((ITranslatable)pi).Translate(TranslationHelpers.GetWriteTranslator()); var copy = ProjectInstance.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()); return copy; } }); }
/// <summary> /// Get a single metadata instance /// </summary> private static ProjectMetadataInstance GetMetadataInstance() { Project project = new Project(); ProjectInstance projectInstance = project.CreateProjectInstance(); ProjectItemInstance item = projectInstance.AddItem("i", "i1"); ProjectMetadataInstance metadata = item.SetMetadata("m", "m1"); return(metadata); }
public void AddItemInvalidNullItemType() { Assert.Throws <ArgumentNullException>(() => { ProjectInstance p = GetEmptyProjectInstance(); p.AddItem(null, "i1"); } ); }
public void AddItemInvalidEmptyItemType() { Assert.Throws <ArgumentException>(() => { ProjectInstance p = GetEmptyProjectInstance(); p.AddItem(String.Empty, "i1"); } ); }
public void AddItemInvalidNullInclude() { Assert.Throws <ArgumentNullException>(() => { ProjectInstance p = GetEmptyProjectInstance(); p.AddItem("i", null); } ); }
/// <summary> /// Initialize 'resolvedInfo' by having MSBuild resolve the assembly in the context of the current project /// </summary> /// <param name="assemblyInclude">Either a full path to a file on disk, or a simple name or fusion name</param> private void AddToProjectFileAndTryResolve(string assemblyInclude) { // starting: assemblyInclude ProjectInstance instance = null; instance = this.ProjectMgr.BuildProject.CreateProjectInstance(); // use a fresh instance... instance.AddItem(ProjectFileConstants.Reference, assemblyInclude); // ...and mutate it as through there were another <Reference Include="blah"> there var result = BuildInstance(this.ProjectMgr, ref instance, MsBuildTarget.ResolveAssemblyReferences); this.ResolveFromBuiltProject(assemblyInclude, result); }
public void CloneItems() { ProjectInstance first = GetSampleProjectInstance(); ProjectInstance second = first.DeepCopy(); Assert.False(Object.ReferenceEquals(Helpers.MakeList(first.GetItems("i"))[0], Helpers.MakeList(second.GetItems("i"))[0])); first.AddItem("i", "i3"); Assert.Equal(4, Helpers.MakeList(first.GetItems("i")).Count); Assert.Equal(3, Helpers.MakeList(second.GetItems("i")).Count); }
public void GetExtensions_SomeConfiguredExtensions_ReturnsConfiguredExtensions() { // Arrange var expectedExtension1Name = "Extension1"; var expectedExtension2Name = "Extension2"; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem("NotAnExtension", "UnconfiguredExtensionName"); projectInstance.AddItem("RazorExtension", expectedExtension1Name); projectInstance.AddItem("RazorExtension", expectedExtension2Name); // Act var extensions = LatestProjectConfigurationProvider.GetExtensions(new[] { expectedExtension1Name, expectedExtension2Name }, projectInstance.Items); // Assert Assert.Collection( extensions, extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName), extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName)); }
public void GetProjectConfiguration_NoProviders_ReturnsNull() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(MSBuildProjectManager.ProjectCapabilityItemType, CoreProjectConfigurationProvider.DotNetCoreRazorCapability); // Act var result = MSBuildProjectManager.GetProjectConfiguration(projectInstance, Enumerable.Empty<ProjectConfigurationProvider>()); // Assert Assert.Null(result); }
public void GetConfiguredExtensionNames_NoExtensions() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var configurationItem = projectInstance.AddItem("RazorConfiguration", "Razor-10.0"); // Act var configuredExtensionNames = LatestProjectConfigurationProvider.GetConfiguredExtensionNames(configurationItem); // Assert Assert.Empty(configuredExtensionNames); }
private ProjectConfigurationProviderContext BuildContext(params string[] referencePaths) { var projectInstance = new ProjectInstance(ProjectRootElement.Create()); foreach (var path in referencePaths) { projectInstance.AddItem(SystemWebConfigurationProvider.ReferencePathWithRefAssembliesItemType, path); } var context = new ProjectConfigurationProviderContext(Array.Empty <string>(), projectInstance); return(context); }
public void GetExtensions_UnConfiguredExtensionTypes_ReturnsEmptyArray() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem("NotAnExtension", "UnconfiguredExtensionName"); // Act var extensions = LatestProjectConfigurationProvider.GetExtensions(new[] { "Extension1", "Extension2" }, projectInstance.Items); // Assert Assert.Empty(extensions); }
public void CreateItemWithNullMetadataValue() { Project project = new Project(); ProjectInstance projectInstance = project.CreateProjectInstance(); IDictionary <string, string> metadata = new Dictionary <string, string>(); metadata.Add("m", null); ProjectItemInstance item = projectInstance.AddItem("i", "i1", metadata); Assert.Equal(String.Empty, item.GetMetadataValue("m")); }
private ProjectConfigurationProviderContext BuildContext(params string[] referencePaths) { var projectCapabilities = new[] { CoreProjectConfigurationProvider.DotNetCoreRazorCapability }; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); foreach (var path in referencePaths) { projectInstance.AddItem(FallbackConfigurationProvider.ReferencePathWithRefAssembliesItemType, path); } var context = new ProjectConfigurationProviderContext(projectCapabilities, projectInstance); return(context); }
public void TryGetConfiguration_SucceedsWithAllPreRequisites() { // Arrange var expectedRootNamespace = "SomeApp.Root.Namespace"; var expectedLanguageVersion = RazorLanguageVersion.Version_1_0; var expectedConfigurationName = "Razor-Test"; var expectedExtension1Name = "Extension1"; var expectedExtension2Name = "Extension2"; var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.SetProperty(LatestProjectConfigurationProvider.RootNamespaceProperty, expectedRootNamespace); projectInstance.AddItem("RazorConfiguration", "UnconfiguredRazorConfiguration"); projectInstance.AddItem("RazorConfiguration", "UnconfiguredExtensionName"); projectInstance.AddItem("RazorExtension", expectedExtension1Name); projectInstance.AddItem("RazorExtension", expectedExtension2Name); var expectedRazorConfigurationItem = projectInstance.AddItem( "RazorConfiguration", expectedConfigurationName, new Dictionary <string, string>() { ["Extensions"] = "Extension1;Extension2", }); projectInstance.SetProperty("RazorDefaultConfiguration", expectedConfigurationName); projectInstance.SetProperty("RazorLangVersion", "1.0"); // Act var result = LatestProjectConfigurationProvider.TryGetConfiguration(projectInstance, out var configuration); // Assert Assert.True(result); Assert.Equal(expectedLanguageVersion, configuration.Configuration.LanguageVersion); Assert.Equal(expectedConfigurationName, configuration.Configuration.ConfigurationName); Assert.Collection( configuration.Configuration.Extensions, extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName), extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName)); Assert.Equal(expectedRootNamespace, configuration.RootNamespace); }
public void TryGetConfigurationItem_FailsNoMatchingRazorConfigurationItems() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem("RazorConfiguration", "Razor-10.0"); // Act var result = LatestProjectConfigurationProvider.TryGetConfigurationItem("Razor-13.37", projectInstance.Items, out var configurationItem); // Assert Assert.False(result); Assert.Null(configurationItem); }
private void RegisterRunfiles(ProjectInstance project) { var runfilesDir = Path.Combine(_context.MSBuild.PublishDir, _context.Command.assembly_name + ".dll.runfiles"); var runfilesManifest = new FileInfo(Path.Combine(runfilesDir, "MANIFEST")); if (runfilesManifest.Exists) { foreach (var entry in File.ReadAllLines(runfilesManifest.FullName)) { var parts = entry.Split(' '); var manifestPath = parts[0]; var filePath = Path.Combine(runfilesDir, parts[1]); project.AddItem("None", filePath, new[] { new KeyValuePair <string, string>("Pack", "true"), new KeyValuePair <string, string>("PackagePath", $"content/runfiles/{manifestPath}"), }); } } // the dll will be placed at <root>/tools/<tfm>/any/<primaryName>.dll // runfiles will be at <root>/content/runfiles var packDir = _context.OutputPath("pack"); Directory.CreateDirectory(packDir); var path = Path.Combine(packDir, "runfiles.info"); WriteRunfilesInfo(path, "../../../content/runfiles", true); project.AddItem("None", path, new[] { // new KeyValuePair<string, string>("What", "wow"), new KeyValuePair <string, string>("Pack", "true"), new KeyValuePair <string, string>("PackagePath", $"tools/{_context.Tfm}/any/"), }); }
public void GetProjectConfiguration_SingleProviderReturnsFalse_ReturnsNull() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(MSBuildProjectManager.ProjectCapabilityItemType, CoreProjectConfigurationProvider.DotNetCoreRazorCapability); var provider = new Mock<ProjectConfigurationProvider>(); var configuration = new ProjectConfiguration(RazorConfiguration.Default, Array.Empty<OmniSharpHostDocument>(), "TestRootNamespace"); // Setting to non-null to ensure the listener doesn't return the config verbatim. provider.Setup(p => p.TryResolveConfiguration(It.IsAny<ProjectConfigurationProviderContext>(), out configuration)) .Returns(false); // Act var result = MSBuildProjectManager.GetProjectConfiguration(projectInstance, Enumerable.Empty<ProjectConfigurationProvider>()); // Assert Assert.Null(result); }
public void AddItemWithoutMetadata() { ProjectInstance p = GetEmptyProjectInstance(); ProjectItemInstance returned = p.AddItem("i", "i1"); Assert.Equal("i", returned.ItemType); Assert.Equal("i1", returned.EvaluatedInclude); Assert.False(returned.Metadata.GetEnumerator().MoveNext()); foreach (ProjectItemInstance item in p.Items) { Assert.Equal("i1", item.EvaluatedInclude); Assert.False(item.Metadata.GetEnumerator().MoveNext()); } }
/// <summary> /// Initialize 'resolvedInfo' by having MSBuild resolve the assembly in the context of the current project /// </summary> /// <param name="assemblyInclude">Either a full path to a file on disk, or a simple name or fusion name</param> /// <param name="isAlreadyInProjectFile">Pass true for this parameter, as well as the evaluated include for the other parameter, if you are trying to discover the MSBuild resolution of an existing ProjectElement</param> private void AddToProjectFileAndTryResolve(string assemblyInclude) { Action <string> Trace = (s) => FSharpTrace.PrintLine("ProjectSystemReferenceResolution", () => "ResolveAssemblyReferenceCore: " + s); Trace("starting: \"" + assemblyInclude + "\""); ProjectInstance instance = null; instance = this.ProjectMgr.BuildProject.CreateProjectInstance(); // use a fresh instance... instance.AddItem(ProjectFileConstants.Reference, assemblyInclude); // ...and mutate it as through there were another <Reference Include="blah"> there Trace("instance[Configuration]=" + instance.GetPropertyValue("Configuration")); Trace("instance[Platform]=" + instance.GetPropertyValue("Platform")); var result = BuildInstance(this.ProjectMgr, ref instance, MsBuildTarget.ResolveAssemblyReferences); this.ResolveFromBuiltProject(assemblyInclude, result); Trace("finished without finding original item: \"" + assemblyInclude + "\""); }
public void GetConfiguredExtensionNames_EmptyExtensions() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); var configurationItem = projectInstance.AddItem( "RazorConfiguration", "Razor-10.0", new Dictionary <string, string>() { ["Extensions"] = string.Empty }); // Act var configuredExtensionNames = LatestProjectConfigurationProvider.GetConfiguredExtensionNames(configurationItem); // Assert Assert.Empty(configuredExtensionNames); }
/// <summary> /// Helper function creating a task item that is associated with a parent project /// </summary> private ITaskItem GetParentedTaskItem(string itemSpec, string linkMetadata = null) { Project p = new Project(new ProjectCollection()); p.FullPath = Path.Combine(Path.GetTempPath(), "a.proj"); ProjectInstance pi = p.CreateProjectInstance(); IDictionary <string, string> metadata = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (linkMetadata != null) { metadata.Add("Link", linkMetadata); } ITaskItem item = pi.AddItem("Foo", itemSpec, metadata); return(item); }
public void TryGetConfiguration_SucceedsIfNoConfiguredExtensionNames() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.SetProperty("RazorDefaultConfiguration", "Razor-13.37"); projectInstance.SetProperty("RazorLangVersion", "1.0"); projectInstance.AddItem("RazorConfiguration", "Razor-13.37"); // Act var result = LatestProjectConfigurationProvider.TryGetConfiguration(projectInstance, out var configuration); // Assert Assert.True(result); Assert.Equal(RazorLanguageVersion.Version_1_0, configuration.Configuration.LanguageVersion); Assert.Equal("Razor-13.37", configuration.Configuration.ConfigurationName); Assert.Empty(configuration.Configuration.Extensions); }