Skip to content

Commit 86110c1

Browse files
committed
More test refactoring.
1 parent 0945992 commit 86110c1

File tree

106 files changed

+3716
-474368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+3716
-474368
lines changed

ReferenceFinder/ReferenceFinderTool.cs

+184-185
Large diffs are not rendered by default.

TestCommon/Context.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NUnit.Framework;
2+
3+
namespace UnityDataTools.TestCommon;
4+
5+
public class Context
6+
{
7+
public string UnityDataFolder { get; }
8+
public string UnityDataVersion { get; }
9+
public string TestDataFolder { get; }
10+
public string ExpectedDataFolder { get; }
11+
public ExpectedData ExpectedData { get; } = new();
12+
13+
private Context(string folder)
14+
{
15+
var di = new DirectoryInfo(folder);
16+
17+
UnityDataFolder = folder;
18+
UnityDataVersion = di.Name;
19+
TestDataFolder = di.Parent.FullName;
20+
ExpectedDataFolder = Path.Combine(di.Parent.Parent.FullName, "ExpectedData", UnityDataVersion);
21+
22+
ExpectedData.Load(ExpectedDataFolder);
23+
}
24+
25+
public static IEnumerable<Context> GetAll()
26+
{
27+
if (m_Cache.TryGetValue(TestContext.CurrentContext.TestDirectory, out var cases))
28+
{
29+
return cases;
30+
}
31+
32+
cases = new List<Context>();
33+
m_Cache[TestContext.CurrentContext.TestDirectory] = cases;
34+
foreach (var folder in Directory.EnumerateDirectories(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data")))
35+
{
36+
cases.Add(new Context(folder));
37+
}
38+
39+
return cases;
40+
}
41+
42+
private static Dictionary<string, List<Context>> m_Cache = new();
43+
}
File renamed without changes.

TestCommon/ExpectedData.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Newtonsoft.Json;
2+
3+
namespace UnityDataTools.TestCommon;
4+
5+
public class ExpectedData
6+
{
7+
private Dictionary<string, object> m_ExpectedValues = new();
8+
9+
public void Add(string key, object value)
10+
{
11+
m_ExpectedValues[key] = value;
12+
}
13+
14+
public object Get(string key)
15+
{
16+
return m_ExpectedValues[key];
17+
}
18+
19+
public void Save(string path)
20+
{
21+
var settings = new JsonSerializerSettings();
22+
settings.TypeNameHandling = TypeNameHandling.All;
23+
24+
File.WriteAllText(Path.Combine(path, "ExpectedValues.json"), JsonConvert.SerializeObject(m_ExpectedValues, Formatting.Indented, settings));
25+
}
26+
27+
public void Load(string path)
28+
{
29+
path = Path.Combine(path, "ExpectedValues.json");
30+
31+
if (!File.Exists(path))
32+
{
33+
return;
34+
}
35+
36+
var settings = new JsonSerializerSettings();
37+
settings.TypeNameHandling = TypeNameHandling.All;
38+
39+
m_ExpectedValues = JsonConvert.DeserializeObject<Dictionary<string, object>>(File.ReadAllText(path), settings);
40+
}
41+
}

TestCommon/TestCommon.csproj

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<RootNamespace>TestCommon</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<None Include="Data\**" CopyToOutputDirectory="PreserveNewest" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16+
<PackageReference Include="NUnit" Version="3.13.3" />
17+
</ItemGroup>
18+
19+
</Project>

TestCommon/TestForAllVersions.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using NUnit.Framework;
2+
3+
namespace UnityDataTools.TestCommon;
4+
5+
[TestFixtureSource(typeof(Context), nameof(Context.GetAll))]
6+
public class TestForAllVersions
7+
{
8+
protected Context Context;
9+
10+
public TestForAllVersions(Context context)
11+
{
12+
Context = context;
13+
}
14+
}

0 commit comments

Comments
 (0)