Skip to content

Commit

Permalink
Implement GetProject on MinecraftJar to get a project by it's name
Browse files Browse the repository at this point in the history
  • Loading branch information
tekgator committed Jun 3, 2023
1 parent 0d71dab commit c0f53c3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
18 changes: 13 additions & 5 deletions MinecraftJars.Tests/VersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ public class VersionTests
private static readonly MinecraftJar MinecraftJar = new();
private static IEnumerable<string> 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));
Expand All @@ -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)
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
11 changes: 8 additions & 3 deletions MinecraftJars/IMinecraftJar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface IMinecraftJar
/// <summary>
/// Return a list of all providers offering a certain project group
/// </summary>
IEnumerable<IMinecraftProvider> GetProviders(Group group);
IEnumerable<IMinecraftProvider> GetProviders(ProjectGroup projectGroup);

/// <summary>
/// Return a specific provider
/// </summary>
IMinecraftProvider GetProvider(string provider);
IMinecraftProvider GetProvider(string providerName);

/// <summary>
/// Return the provider for the provided Project
Expand All @@ -33,5 +33,10 @@ public interface IMinecraftJar
/// <summary>
/// Return a list of all projects for a certain type (e.g. all proxies)
/// </summary>
IEnumerable<IMinecraftProject> GetProjects(Group group);
IEnumerable<IMinecraftProject> GetProjects(ProjectGroup projectGroup);

/// <summary>
/// Return project by it's name
/// </summary>
IMinecraftProject GetProject(string projectName);
}
45 changes: 28 additions & 17 deletions MinecraftJars/MinecraftJar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,48 @@ public IEnumerable<IMinecraftProvider> GetProviders()
return _providers;
}

public IEnumerable<IMinecraftProvider> GetProviders(Group group)
public IEnumerable<IMinecraftProvider> GetProviders(ProjectGroup projectGroup)
{
var providers = new List<IMinecraftProvider>();

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<IMinecraftProject> GetProjects()
{
return GetProviders()
.SelectMany(p => p.Projects);
return from provider in GetProviders()
from project in provider.Projects
select project;
}

public IEnumerable<IMinecraftProject> GetProjects(Group group)
public IEnumerable<IMinecraftProject> 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();
}
}

0 comments on commit c0f53c3

Please sign in to comment.