forked from icsharpcode/CodeConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFileRewriter.cs
More file actions
40 lines (35 loc) · 1.42 KB
/
TestFileRewriter.cs
File metadata and controls
40 lines (35 loc) · 1.42 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ICSharpCode.CodeConverter.Tests.TestRunners;
public static class TestFileRewriter
{
private static readonly Lazy<Dictionary<string, string>> FileContents = new(GetTestFileContents);
private static Dictionary<string, string> GetTestFileContents()
{
return Directory.GetFiles(GetTestSourceDirectoryPath(), "*Tests.cs", SearchOption.AllDirectories)
.ToDictionary(f => f, s => File.ReadAllText(s, Encoding.UTF8));
}
private static string GetTestSourceDirectoryPath()
{
string assemblyDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath);
string testSourceDirectoryPath = Path.Combine(assemblyDir, "..", "..", "..");
return testSourceDirectoryPath;
}
public static void UpdateFiles(string expected, string actual)
{
lock (FileContents) {
foreach (var fileContent in FileContents.Value) {
var newFc = fileContent.Value.Replace(expected.Replace("\"", "\"\""), actual.Replace("\"", "\"\""));
if (fileContent.Value != newFc) {
FileContents.Value[fileContent.Key] = newFc;
File.WriteAllText(fileContent.Key, newFc, Encoding.UTF8);
return;
}
}
}
}
}