Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ModuleManager.Collections; | ||
|
||
namespace ModuleManager | ||
{ | ||
public class PatchList | ||
{ | ||
public class ModPass | ||
{ | ||
public readonly List<UrlDir.UrlConfig> beforePatches = new List<UrlDir.UrlConfig>(0); | ||
public readonly List<UrlDir.UrlConfig> forPatches = new List<UrlDir.UrlConfig>(0); | ||
public readonly List<UrlDir.UrlConfig> afterPatches = new List<UrlDir.UrlConfig>(0); | ||
|
||
public readonly string name; | ||
|
||
public ModPass(string name) | ||
{ | ||
this.name = name; | ||
} | ||
} | ||
|
||
public class ModPassCollection : IEnumerable<ModPass> | ||
{ | ||
private readonly ModPass[] passesArray; | ||
private readonly Dictionary<string, ModPass> passesDict; | ||
|
||
public ModPassCollection(IEnumerable<string> modList) | ||
{ | ||
int count = modList.Count(); | ||
passesArray = new ModPass[count]; | ||
passesDict = new Dictionary<string, ModPass>(count); | ||
|
||
int i = 0; | ||
foreach (string mod in modList) | ||
{ | ||
ModPass pass = new ModPass(mod); | ||
passesArray[i] = pass; | ||
passesDict.Add(mod, pass); | ||
i++; | ||
} | ||
} | ||
|
||
public ModPass this[string name] => passesDict[name]; | ||
|
||
public bool HasMod(string name) => passesDict.ContainsKey(name); | ||
|
||
public ArrayEnumerator<ModPass> GetEnumerator() => new ArrayEnumerator<ModPass>(passesArray); | ||
IEnumerator<ModPass> IEnumerable<ModPass>.GetEnumerator() => GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
public readonly List<UrlDir.UrlConfig> firstPatches = new List<UrlDir.UrlConfig>(); | ||
public readonly List<UrlDir.UrlConfig> legacyPatches = new List<UrlDir.UrlConfig>(); | ||
public readonly List<UrlDir.UrlConfig> finalPatches = new List<UrlDir.UrlConfig>(); | ||
|
||
public readonly ModPassCollection modPasses; | ||
|
||
public PatchList(IEnumerable<string> modList) | ||
{ | ||
modPasses = new ModPassCollection(modList); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
using ModuleManager; | ||
|
||
namespace ModuleManagerTests | ||
{ | ||
public class PatchListTest | ||
{ | ||
[Fact] | ||
public void TestConstructor() | ||
{ | ||
PatchList list = new PatchList(new string[0]); | ||
|
||
Assert.NotNull(list.firstPatches); | ||
Assert.NotNull(list.legacyPatches); | ||
Assert.NotNull(list.finalPatches); | ||
Assert.NotNull(list.modPasses); | ||
} | ||
|
||
[Fact] | ||
public void TestModPasses__HasMod() | ||
{ | ||
PatchList list = new PatchList(new[] { "mod1", "mod2" }); | ||
|
||
PatchList.ModPassCollection collection = list.modPasses; | ||
|
||
Assert.True(collection.HasMod("mod1")); | ||
Assert.True(collection.HasMod("mod2")); | ||
Assert.False(collection.HasMod("mod3")); | ||
} | ||
|
||
[Fact] | ||
public void TestModPasses__Accessor() | ||
{ | ||
PatchList list = new PatchList(new[] { "mod1", "mod2" }); | ||
|
||
PatchList.ModPass pass1 = list.modPasses["mod1"]; | ||
Assert.NotNull(pass1); | ||
Assert.Equal("mod1", pass1.name); | ||
Assert.NotNull(pass1.beforePatches); | ||
Assert.Equal(0, pass1.beforePatches.Capacity); | ||
Assert.NotNull(pass1.forPatches); | ||
Assert.Equal(0, pass1.forPatches.Capacity); | ||
Assert.NotNull(pass1.afterPatches); | ||
Assert.Equal(0, pass1.afterPatches.Capacity); | ||
|
||
PatchList.ModPass pass2 = list.modPasses["mod2"]; | ||
Assert.NotNull(pass2); | ||
Assert.Equal("mod2", pass2.name); | ||
Assert.NotNull(pass2.beforePatches); | ||
Assert.Equal(0, pass2.beforePatches.Capacity); | ||
Assert.NotNull(pass2.forPatches); | ||
Assert.Equal(0, pass2.forPatches.Capacity); | ||
Assert.NotNull(pass2.afterPatches); | ||
Assert.Equal(0, pass2.afterPatches.Capacity); | ||
|
||
Assert.Throws<KeyNotFoundException>(delegate | ||
{ | ||
PatchList.ModPass mod3 = list.modPasses["mod3"]; | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void TestModPasses__Enumeration() | ||
{ | ||
PatchList list = new PatchList(new[] { "mod1", "mod2" }); | ||
|
||
PatchList.ModPass[] passes = new PatchList.ModPass[] { list.modPasses["mod1"], list.modPasses["mod2"] }; | ||
|
||
Assert.Equal(passes, list.modPasses); | ||
} | ||
} | ||
} |