private void CreateGenereatedFiles(Dictionary <NuGetPackageInfo, SlnxHandler> debugItems, List <NuGetPackage> debugPackages) { var refs = CreatPackageReferenceContent(debugItems); FixProjectFiles(); var debugInfo = CreateNuGetDebugContent(debugItems, debugPackages); var slnxConfig = debugInfo; foreach (var r in refs) { if (slnxConfig.ContainsKey(r.Key)) { var importedNode = slnxConfig[r.Key].ImportNode(r.Value.DocumentElement.FirstChild, true); slnxConfig[r.Key].DocumentElement.AppendChild(importedNode); } else { slnxConfig.Add(r.Key, r.Value); } } foreach (var cfg in slnxConfig) { string prettyContent = XDocument.Parse(cfg.Value.OuterXml).ToString(); _fileWriter.WriteAllText(Path.Join(cfg.Key.FullDir, CsProject.ImportSlnxConfigName), prettyContent); } }
static void CreateMsBuildPropertiesTarget(SlnxHandler slnx) { string outDir = slnx.SlnxDirectory; _logger.Info("Creating MS Build targets in {0}", outDir); var content = new StringBuilder(); var keys = GetAllKeys(slnx); content.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); content.AppendLine("<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"); content.AppendLine(" <PropertyGroup>"); foreach (var key in keys) { var value = slnx.SafeExpandEnvironmentVariables(Environment.GetEnvironmentVariable(key)); content.AppendLine($" <{key}>{value}</{key}>"); } content.AppendLine("\n <MsBuildGeneratedProperties Condition=\" '$(MsBuildGeneratedProperties)' == '' \">"); foreach (var key in keys) { var value = slnx.SafeExpandEnvironmentVariables(Environment.GetEnvironmentVariable(key)); content.AppendLine($" {key}={value};"); } content.AppendLine(" </MsBuildGeneratedProperties>"); content.AppendLine(" </PropertyGroup>"); content.AppendLine("</Project>"); _fileWriter.WriteAllText(Path.Combine(outDir, "MsBuildGeneratedProperties.targets"), content.ToString()); }
public void SaveCsProjectToFile() { string projectNewContent = XDocument.Parse(_xml.OuterXml).ToString(); if (projectNewContent != _projectOriginalContent) { _fileWriter.WriteAllText(FullPath, projectNewContent); _projectOriginalContent = projectNewContent; } }
// TODO: Callername will only work for when directly called by the test method, // need to look at how to get name of the method in the stack trace which has the [Fact] attribute. // Work out how to access caller name and caller file path using reflection. public void Snapshot <T>( T input, bool overwriteExistingSnapshot = false, [CallerMemberName] string callerName = "", [CallerFilePath] string callerFilePath = "") { var callerMethodInfo = new CallerMethodInfo(callerName, callerFilePath); var json = JsonConvert.SerializeObject(input); if (_fileExistenceChecker.Exists(callerMethodInfo)) { var snapshotJson = _fileReader.ReadAllText(callerMethodInfo); try { Assert.Equal(snapshotJson, json); } catch (EqualException exception) { if (overwriteExistingSnapshot) { _fileWriter.WriteAllText(callerMethodInfo, json); } else { throw new SnapshotException(exception, $"For this test to pass, the json in '{callerMethodInfo.SnapshotFilePath}' needs to be updated.\n" + "\n" + $"'{callerMethodInfo.SnapshotFilePath}' can be updated in two ways: \n" + " By running \'.Snapshot(T input, true)\', where true indicates that the existing snapshot should be overwritten.\n" + $" By manually editing '{callerMethodInfo.SnapshotFilePath}'.\n"); } } } else { _directoryCreator.CreateDirectory(callerMethodInfo.SnapshotDirectoryPath); _fileWriter.WriteAllText(callerMethodInfo, json); // TODO: Alert test runner with a warning that a new snapshot json file has been created } }
public async Task WriteCoverageOutput(string text) { var outputFile = options.Output; if (!string.IsNullOrWhiteSpace(outputFile)) { if (fileProvider.GetFileInfo(outputFile).Exists) { logger.LogWarning($"output file '{outputFile}' already exists and will be overwritten."); } try { await fileWriter.WriteAllText(outputFile, text); } catch (Exception ex) { logger.LogError($"Failed to write data to output file '{outputFile}'."); logger.LogError(ex.ToString()); } } }
/// <summary> /// Saves the given document to the file system /// </summary> /// <param name="path">Name of the output file</param> /// <param name="document">Document that should be saved</param> /// <returns>True if the document could be saved</returns> public virtual bool Save(string path, T document) { return(_defaultFileWriter.WriteAllText(path, document.Print())); }