public void HasChanges_WhenXDocumentDoesNotMatchFileContent_Success() { // Arrange using (var randomProjectDirectory = TestDirectory.Create()) { var filePath = Path.Combine(randomProjectDirectory, "propsXML.xml"); var internalSubset = @"<!ENTITY greeting ""Hello""> <!ENTITY name ""NuGet Client ""> <!ENTITY sayhello ""&greeting; &name;"">"; var newValue = "&sayhello;"; XDocument doc = BuildAssetsUtils.GenerateEmptyImportsFile(); doc.Save(filePath); XDocument newdoc = XDocument.Load(filePath); newdoc.AddFirst(new XDocumentType("Project", null, null, internalSubset)); XAttribute attribute = newdoc.Root.Attributes(XName.Get("ToolsVersion")).FirstOrDefault(); attribute.Value = newValue; newdoc.Save(filePath); string newxml = File.ReadAllText(filePath); File.WriteAllText(filePath, newxml.Replace("&", "&")); //Act & Assert Assert.True(BuildAssetsUtils.HasChanges(doc, filePath, NullLogger.Instance)); } }
public void HasChanges_WhenXDocumentMatchesFileContent_Fails() { // Arrange using (var randomProjectDirectory = TestDirectory.Create()) { var filePath = Path.Combine(randomProjectDirectory, "propsXML.xml"); XDocument doc = BuildAssetsUtils.GenerateEmptyImportsFile(); doc.Save(filePath); //Act bool result = BuildAssetsUtils.HasChanges(doc, filePath, NullLogger.Instance); Assert.False(result); } }