private static string ArrangeAndAct(string contents = null) { var sut = new ProjectFileUpdater(XDocument.Parse(contents ?? CSharpProjectFileContentsWithout)); var document = sut.UpdatePropertyGroup(AutoRestConstants.PropertyGroups); return(document.ToString()); }
public void CannotUpdateProjectFileWithoutAssemblyInfoGeneration(string xml) { using var projectFileUpdater = new ProjectFileUpdater(log, fileSystem); var canUpdate = projectFileUpdater.CanUpdateProjectFile(XElement.Parse(xml)); canUpdate.ShouldBe(false); }
public void CanUpdateProjectFileWithStandardDesktopProjectFileXml(string xml) { using var projectFileUpdater = new ProjectFileUpdater(log, fileSystem); var canUpdate = projectFileUpdater.CanUpdateProjectFile(XElement.Parse(xml)); canUpdate.ShouldBe(true); }
public void CannotUpdateProjectFileWithoutAPropertyGroup(string xml) { using var projectFileUpdater = new ProjectFileUpdater(log, fileSystem); var canUpdate = projectFileUpdater.CanUpdateProjectFile(XElement.Parse(xml)); canUpdate.ShouldBe(false); }
public void CannotUpdateProjectFileWithMissingProjectSdk(string xml) { using var projectFileUpdater = new ProjectFileUpdater(this.log, this.fileSystem); var canUpdate = projectFileUpdater.CanUpdateProjectFile(XElement.Parse(xml)); canUpdate.ShouldBe(false); }
public void CanUpdateProjectFileWithRazorClassLibraryProjectFileXml(string xml) { using var projectFileUpdater = new ProjectFileUpdater(this.log, this.fileSystem); var canUpdate = projectFileUpdater.CanUpdateProjectFile(XElement.Parse(xml)); canUpdate.ShouldBe(true); }
public void UpdatePropertyGroup_Returns_NotNull() { var projectFile = Path.GetTempFileName(); File.WriteAllText(projectFile, CSharpProjectFileContentsWithout); var sut = new ProjectFileUpdater(projectFile); sut.UpdatePropertyGroup(AutoRestConstants.PropertyGroups) .Should() .NotBeNull(); }
public static async Task UpdatePropertyGroupsAsync( this Project project, IReadOnlyDictionary <string, string> properties) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); project.Save(); var projectFileUpdater = new ProjectFileUpdater(project.FileName); projectFileUpdater.UpdatePropertyGroup(properties); }
public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string xml) { var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false); var xmlRoot = XElement.Parse(xml); ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer !); var expectedXml = XElement.Parse(@" <Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <AssemblyVersion>2.0.0.0</AssemblyVersion> </PropertyGroup> </Project>"); xmlRoot.ToString().ShouldBe(expectedXml.ToString()); }
public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsModified(string xml) { using var projectFileUpdater = new ProjectFileUpdater(log, fileSystem); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false); var xmlRoot = XElement.Parse(xml); projectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer); var expectedXml = XElement.Parse(@" <Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>2.0.0.0</AssemblyVersion> </PropertyGroup> </Project>"); xmlRoot.ToString().ShouldBe(expectedXml.ToString()); }
public void UpdateProjectFileAddsVersionToFile(string xml) { var fileName = Path.Combine(Path.GetTempPath(), "TestProject.csproj"); VerifyAssemblyInfoFile(xml, fileName, AssemblyVersioningScheme.MajorMinorPatch, verify: (fs, variables) => { using var projectFileUpdater = new ProjectFileUpdater(log, fs); projectFileUpdater.Execute(variables, new AssemblyInfoContext(Path.GetTempPath(), false, fileName)); var expectedXml = @" <Project Sdk=""Microsoft.NET.Sdk""> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <AssemblyVersion>2.3.1.0</AssemblyVersion> <FileVersion>2.3.1.0</FileVersion> <InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion> </PropertyGroup> </Project>"; var transformedXml = fs.ReadAllText(fileName); transformedXml.ShouldBe(XElement.Parse(expectedXml).ToString()); }); }