diff --git a/MinecraftJars.Tests/VersionTests.cs b/MinecraftJars.Tests/VersionTests.cs index 65cd49f..d0efed8 100644 --- a/MinecraftJars.Tests/VersionTests.cs +++ b/MinecraftJars.Tests/VersionTests.cs @@ -9,8 +9,16 @@ public class VersionTests private static readonly MinecraftJar MinecraftJar = new(); private static IEnumerable Projects() => MinecraftJar.GetProviders().SelectMany(p => p.Projects.Select(t => t.Name)); - + [TestCaseSource(nameof(Projects)), Order(1)] + public void GetProjectsByName_Success(string projectName) + { + Assert.DoesNotThrow(() => MinecraftJar.GetProject(projectName)); + TestContext.Progress.WriteLine("{0}: Project found by name {1}", + nameof(GetProjectsByName_Success), projectName); + } + + [TestCaseSource(nameof(Projects)), Order(2)] public async Task GetVersions_Success(string projectName) { var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); @@ -23,7 +31,7 @@ public async Task GetVersions_Success(string projectName) nameof(GetVersions_Success), versions.Count, project.Name); } - [Test, Order(2)] + [Test, Order(3)] public async Task GetVersions_MaxRecordsMax( [ValueSource(nameof(Projects))] string projectName, [Values(5, 10)] int maxRecords) @@ -40,7 +48,7 @@ public async Task GetVersions_MaxRecordsMax( nameof(GetVersions_MaxRecordsMax), versions.Count, project.Name, maxRecords); } - [TestCaseSource(nameof(Projects)), Order(3)] + [TestCaseSource(nameof(Projects)), Order(4)] public async Task GetVersions_SpecificVersion(string projectName) { var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); @@ -66,7 +74,7 @@ public async Task GetVersions_SpecificVersion(string projectName) [TestCase("Spigot")] [TestCase("Paper")] [TestCase("Velocity")] - [Order(4)] + [Order(5)] public async Task GetVersions_ContainsSnapshot(string projectName) { var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); @@ -89,7 +97,7 @@ public async Task GetVersions_ContainsSnapshot(string projectName) [TestCase("Spigot")] [TestCase("Paper")] [TestCase("Velocity")] - [Order(5)] + [Order(6)] public async Task GetVersions_ContainsNoSnapshot(string projectName) { var project = MinecraftJar.GetProjects().Single(p => p.Name.Equals(projectName)); diff --git a/MinecraftJars/IMinecraftJar.cs b/MinecraftJars/IMinecraftJar.cs index 0460c29..705634e 100644 --- a/MinecraftJars/IMinecraftJar.cs +++ b/MinecraftJars/IMinecraftJar.cs @@ -13,12 +13,12 @@ public interface IMinecraftJar /// /// Return a list of all providers offering a certain project group /// - IEnumerable GetProviders(Group group); + IEnumerable GetProviders(ProjectGroup projectGroup); /// /// Return a specific provider /// - IMinecraftProvider GetProvider(string provider); + IMinecraftProvider GetProvider(string providerName); /// /// Return the provider for the provided Project @@ -33,5 +33,10 @@ public interface IMinecraftJar /// /// Return a list of all projects for a certain type (e.g. all proxies) /// - IEnumerable GetProjects(Group group); + IEnumerable GetProjects(ProjectGroup projectGroup); + + /// + /// Return project by it's name + /// + IMinecraftProject GetProject(string projectName); } \ No newline at end of file diff --git a/MinecraftJars/MinecraftJar.cs b/MinecraftJars/MinecraftJar.cs index d45f7c7..d9819f7 100644 --- a/MinecraftJars/MinecraftJar.cs +++ b/MinecraftJars/MinecraftJar.cs @@ -34,37 +34,48 @@ public IEnumerable GetProviders() return _providers; } - public IEnumerable GetProviders(Group group) + public IEnumerable GetProviders(ProjectGroup projectGroup) { - var providers = new List(); - - providers.AddRange(GetProviders() - .Where(p => p.Projects.Any(t => t.Group == group))); - - return providers; + return from provider in GetProviders() + from project in provider.Projects + where project.ProjectGroup == projectGroup + select provider; } - public IMinecraftProvider GetProvider(string provider) + public IMinecraftProvider GetProvider(string providerName) { - return _providers - .Single(p => p.Name.Equals(provider)); + return (from provider in GetProviders() + where provider.Name.Equals(providerName) + select provider).Single(); } public IMinecraftProvider GetProvider(IMinecraftProject project) { - return _providers - .Single(p => p.Projects.Contains(project)); + return (from provider in GetProviders() + where provider.Projects.Contains(project) + select provider).Single(); } public IEnumerable GetProjects() { - return GetProviders() - .SelectMany(p => p.Projects); + return from provider in GetProviders() + from project in provider.Projects + select project; } - public IEnumerable GetProjects(Group group) + public IEnumerable GetProjects(ProjectGroup projectGroup) + { + return from provider in GetProviders() + from project in provider.Projects + where project.ProjectGroup == projectGroup + select project; + } + + public IMinecraftProject GetProject(string projectName) { - return GetProviders() - .SelectMany(p => p.Projects.Where(t => t.Group == group)); + return (from provider in GetProviders() + from project in provider.Projects + where project.Name.Equals(projectName) + select project).Single(); } } \ No newline at end of file