Skip to content

Commit

Permalink
Create special GameData subdirectory
Browse files Browse the repository at this point in the history
It's special
  • Loading branch information
blowfishpro committed Apr 21, 2018
1 parent 0aa64b5 commit ae2a14f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions TestUtils/UrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace TestUtils
{
public static class UrlBuilder
{
private static readonly FieldInfo UrlDir__field__type;
private static readonly FieldInfo UrlDir__field__name;
private static readonly FieldInfo UrlDir__field__root;
private static readonly FieldInfo UrlDir__field__parent;
Expand All @@ -18,9 +19,11 @@ public static class UrlBuilder
static UrlBuilder()
{
FieldInfo[] UrlDirFields = typeof(UrlDir).GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo[] UrlDirFields__DirectoryType = UrlDirFields.Where(field => field.FieldType == typeof(UrlDir.DirectoryType)).ToArray();
FieldInfo[] UrlDirFields__string = UrlDirFields.Where(field => field.FieldType == typeof(string)).ToArray();
FieldInfo[] UrlDirFields__UrlDir = UrlDirFields.Where(field => field.FieldType == typeof(UrlDir)).ToArray();

UrlDir__field__type = UrlDirFields__DirectoryType[0];
UrlDir__field__name = UrlDirFields__string[0];
UrlDir__field__root = UrlDirFields__UrlDir[0];
UrlDir__field__parent = UrlDirFields__UrlDir[1];
Expand Down Expand Up @@ -67,6 +70,29 @@ public static UrlDir CreateDir(string url, UrlDir parent = null)
return current;
}

public static UrlDir CreateGameData(UrlDir root = null)
{
if (root == null)
{
root = CreateRoot();
}
else
{
UrlDir potentialGameData = root.children.FirstOrDefault(dir => dir.type == UrlDir.DirectoryType.GameData && dir.name == "");
if (potentialGameData != null) return potentialGameData;
}

UrlDir gameData = CreateRoot();
UrlDir__field__name.SetValue(gameData, "");
UrlDir__field__type.SetValue(gameData, UrlDir.DirectoryType.GameData);
UrlDir__field__root.SetValue(gameData, root);
UrlDir__field__parent.SetValue(gameData, root);

root.children.Add(gameData);

return gameData;
}

public static UrlDir.UrlFile CreateFile(string path, UrlDir parent = null)
{
int sepIndex = path.LastIndexOf('/');
Expand Down
39 changes: 39 additions & 0 deletions TestUtilsTests/UrlBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,45 @@ public void TestCreateDir__Url__AlreadyExists()
Assert.Contains(dir1, root.AllDirectories);
}

[Fact]
public void TestCreateGameData()
{
UrlDir gameData = UrlBuilder.CreateGameData();

Assert.Equal("", gameData.name);
Assert.Equal("", gameData.url);
Assert.Equal(UrlDir.DirectoryType.GameData, gameData.type);
UrlDir root = Assert.IsType<UrlDir>(gameData.root);
Assert.Same(root, gameData.parent);
Assert.Equal("root", root.name);
Assert.Null(root.parent);
Assert.Same(root, root.root);
Assert.Contains(gameData, root.children);
}

[Fact]
public void TestCreateGameData__SpecifyRoot()
{
UrlDir root = UrlBuilder.CreateRoot();
UrlDir gameData = UrlBuilder.CreateGameData(root);

Assert.Equal("", gameData.name);
Assert.Equal("", gameData.url);
Assert.Equal(UrlDir.DirectoryType.GameData, gameData.type);
Assert.Same(root, gameData.parent);
Assert.Contains(gameData, root.children);
}

[Fact]
public void TestCreateGameData__SpecifyRoot__GameDataAlreadyExists()
{
UrlDir root = UrlBuilder.CreateRoot();
UrlDir gameData1 = UrlBuilder.CreateGameData(root);
UrlDir gameData2 = UrlBuilder.CreateGameData(root);

Assert.Same(gameData1, gameData2);
}

[Fact]
public void TestCreateFile()
{
Expand Down

0 comments on commit ae2a14f

Please sign in to comment.