Skip to content

Commit

Permalink
Add unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 30, 2024
1 parent aa7cbf1 commit 197dfd2
Show file tree
Hide file tree
Showing 39 changed files with 569 additions and 275 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Test
run: dotnet test GangsTest --no-build --verbosity normal
- name: Build
run: dotnet build --no-restore
- name: Test
Expand Down
14 changes: 13 additions & 1 deletion Gangs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsAPI", "GangsAPI\GangsAPI.csproj", "{787D12D8-1310-4042-ADCE-102E517F269E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsImpl", "GangsImpl\GangsImpl.csproj", "{3EA38296-9022-4874-8309-872388D884DE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsPlugin", "GangsPlugin\GangsPlugin.csproj", "{3EA38296-9022-4874-8309-872388D884DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsTest", "GangsTest\GangsTest.csproj", "{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GangsImpl.Memory", "GangsImpl.Memory\GangsImpl.Memory.csproj", "{140E1706-30E8-4440-AAA0-56E8DD32F054}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -18,5 +22,13 @@ Global
{3EA38296-9022-4874-8309-872388D884DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3EA38296-9022-4874-8309-872388D884DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3EA38296-9022-4874-8309-872388D884DE}.Release|Any CPU.Build.0 = Release|Any CPU
{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1D1E7C7-BDF3-4238-9025-4FEB2B7DAB89}.Release|Any CPU.Build.0 = Release|Any CPU
{140E1706-30E8-4440-AAA0-56E8DD32F054}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{140E1706-30E8-4440-AAA0-56E8DD32F054}.Debug|Any CPU.Build.0 = Debug|Any CPU
{140E1706-30E8-4440-AAA0-56E8DD32F054}.Release|Any CPU.ActiveCfg = Release|Any CPU
{140E1706-30E8-4440-AAA0-56E8DD32F054}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using GangsAPI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace GangsImpl.Extensions;
namespace GangsAPI.Extensions;

public static class ServiceCollectionExtensions {
/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions GangsAPI/GangsAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.263" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
</ItemGroup>
<ItemGroup>
<Reference Include="CounterStrikeSharp.API">
<HintPath>..\..\..\..\..\.nuget\packages\counterstrikesharp.api\1.0.263\lib\net8.0\CounterStrikeSharp.API.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions GangsAPI/IBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GangsAPI;

public interface IBehavior : IDisposable {
void Start();
void IDisposable.Dispose() { }
}
8 changes: 4 additions & 4 deletions GangsAPI/IPluginBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace GangsAPI;

public interface IPluginBehavior : IDisposable {
void IDisposable.Dispose() { }
public interface IPluginBehavior : IBehavior {
internal void Start(BasePlugin? plugin) { }

internal void Start(BasePlugin plugin) { }
void Start(BasePlugin? plugin, bool hotReload) { Start(plugin); }

void Start(BasePlugin plugin, bool hotReload) { Start(plugin); }
void IBehavior.Start() { Start(null); }
}
54 changes: 27 additions & 27 deletions GangsAPI/Permissions/IGangRank.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
namespace GangsAPI.Permissions;

public interface IGangRank {
string Name { get; }
int Rank { get; }
Permissions Perms { get; }

[Flags]
public enum Permissions {
/// <summary>
/// The member may invite others to the gang.
/// The member may invite others to the gang.
/// </summary>
INVITE_OTHERS = 1 << 0,

/// <summary>
/// The member may kick others from the gang.
/// The member may kick others from the gang.
/// </summary>
KICK_OTHERS = 1 << 1,

/// <summary>
/// The member may deposit money into the gang bank.
/// This also allows the member to use their own personal
/// funds to purchase perks for the gang.
/// The member may deposit money into the gang bank.
/// This also allows the member to use their own personal
/// funds to purchase perks for the gang.
/// </summary>
BANK_DEPOSIT = 1 << 2,

/// <summary>
/// The member may withdraw money from the gang bank.
/// This also allows the member to use the gang's funds
/// to purchase perks for the gang.
/// The member may withdraw money from the gang bank.
/// This also allows the member to use the gang's funds
/// to purchase perks for the gang.
/// </summary>
BANK_WITHDRAW = 1 << 3,

/// <summary>
/// The member may promote others, the maximum rank that
/// they may promote to is determined by the rank system.
/// The member may promote others, the maximum rank that
/// they may promote to is determined by the rank system.
/// </summary>
PROMOTE_OTHERS = 1 << 4,

/// <summary>
/// The member may demote others.
/// The member may demote others.
/// </summary>
DEMOTE_OTHERS = 1 << 5,

/// <summary>
/// The member may purchase perks for the gang.
/// The member may purchase perks for the gang.
/// </summary>
PURCHASE_PERKS = 1 << 6,

/// <summary>
/// The member may manage or configure perks for the gang.
/// The member may manage or configure perks for the gang.
/// </summary>
MANAGE_PERKS = 1 << 7,

/// <summary>
/// The member may manage the ranks of the gang, regardless
/// of rank system, the member will not be able to manage
/// their own rank.
/// The member may manage the ranks of the gang, regardless
/// of rank system, the member will not be able to manage
/// their own rank.
/// </summary>
MANAGE_RANKS = 1 << 8,

/// <summary>
/// The member may create new ranks for the gang.
/// All ranks created must not have a rank higher than
/// the member's current rank. Depending on the rank system,
/// these ranks may also be required to have a rank lower
/// than the member's current rank.
/// The member may create new ranks for the gang.
/// All ranks created must not have a rank higher than
/// the member's current rank. Depending on the rank system,
/// these ranks may also be required to have a rank lower
/// than the member's current rank.
/// </summary>
CREATE_RANKS = 1 << 9,

/// <summary>
/// The member has full access to all permissions.
/// The member has full access to all permissions.
/// </summary>
ADMINISTRATOR = 1 << 10,

/// <summary>
/// The member is the owner of the gang, and can not be kicked.
/// The member is the owner of the gang, and can not be kicked.
/// </summary>
OWNER = 1 << 11
}

string Name { get; }
int Rank { get; }
Permissions Perms { get; }
}
2 changes: 1 addition & 1 deletion GangsAPI/Permissions/IPermDictator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace GangsAPI.Permissions;

/// <summary>
/// The dictator of permissions.
/// The dictator of permissions.
/// </summary>
public interface IPermDictator : IPluginBehavior {
bool CanTarget(IGangRank source, IGangRank target);
Expand Down
32 changes: 16 additions & 16 deletions GangsAPI/Services/IGangManager.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
using GangsAPI.Struct;
using GangsAPI.Struct.Gang;
using GangsAPI.Struct.Gang;

namespace GangsAPI.Services;

/// <summary>
/// A manager for gangs. Allows for the creation, retrieval, updating, and deletion of gangs.
/// The Gang Manager should not be used to manage perks or stats.
/// Use the respective <see cref="IPerkManager"/> and <see cref="IStatManager"/> to manage those.
/// A manager for gangs. Allows for the creation, retrieval, updating, and deletion of gangs.
/// The Gang Manager should not be used to manage perks or stats.
/// Use the respective <see cref="IPerkManager" /> and <see cref="IStatManager" /> to manage those.
/// </summary>
public interface IGangManager : IPluginBehavior {
/// <summary>
/// Gets all gangs.
/// Gets all gangs.
/// </summary>
/// <returns>The collection of all gangs, or an empty collection if there are none.</returns>
Task<IEnumerable<IGang>> GetGangs();

/// <summary>
/// Gets a gang by its ID.
/// Gets a gang by its ID.
/// </summary>
/// <param name="id">The gang associated with the given id, or null if there is not one.</param>
/// <returns></returns>
Task<IGang?> GetGang(int id);

/// <summary>
/// Gets a gang by the steam ID of one of its members.
/// In theory, a player could be in multiple gangs, but this method
/// in which case this behavior is undefined.
/// Gets a gang by the steam ID of one of its members.
/// In theory, a player could be in multiple gangs, but this method
/// in which case this behavior is undefined.
/// </summary>
/// <param name="steam"></param>
/// <returns></returns>
Task<IGang?> GetGang(ulong steam);

/// <summary>
/// Pushes a gang to the database.
/// Used for updating or creating gangs.
/// Pushes a gang to the database.
/// Used for updating or creating gangs.
/// </summary>
/// <param name="gang"></param>
/// <returns>True if the update was successful</returns>
Task<bool> PushGang(IGang gang);

/// <summary>
/// Deletes a gang by its ID.
/// Deletes a gang by its ID.
/// </summary>
/// <param name="id">The ID of the gang to delete.</param>
/// <returns>True if deletion was succesful</returns>
Task<bool> DeleteGang(int id);

/// <summary>
/// Creates a gang with the given name and owner.
/// Creates a gang with the given name and owner.
/// </summary>
/// <param name="name">The name of the gang</param>
/// <param name="owner">The owner of the gang</param>
/// <returns>The newly created (and populated, specifically the id) gang.
/// If there was an error, this method will return null.
/// <returns>
/// The newly created (and populated, specifically the id) gang.
/// If there was an error, this method will return null.
/// </returns>
Task<IGang?> CreateGang(string name, ulong owner);

Expand Down
8 changes: 8 additions & 0 deletions GangsAPI/Services/IGangStatManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using GangsAPI.Struct.Stat;

namespace GangsAPI.Services;

public interface IGangStatManager {
Task<IGangStat<V>?> GetForGang<V>(int key, string id);
Task<bool> PushToGang<V>(int key, string id, V value);
}
52 changes: 0 additions & 52 deletions GangsAPI/Services/IPerkManager.cs

This file was deleted.

13 changes: 6 additions & 7 deletions GangsAPI/Services/IPlayerManager.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using GangsAPI.Struct;
using GangsAPI.Struct.Gang;
using GangsAPI.Struct.Gang;

namespace GangsAPI.Services;

/// <summary>
/// A manager for players. Allows for the retrieval and creation of players.
/// A manager for players. Allows for the retrieval and creation of players.
/// </summary>
public interface IPlayerManager : IPluginBehavior {
/// <summary>
/// Gets a player by their SteamID64, creating them if they do not exist.
/// Gets a player by their SteamID64, creating them if they do not exist.
/// </summary>
/// <param name="steamId">The SteamID64 of the player.</param>
/// <returns>The player, or null if there was an error creating one.</returns>
Task<IGangPlayer?> GetPlayer(ulong steamId);

/// <summary>
/// Gets a player by their SteamID64.
/// Gets a player by their SteamID64.
/// </summary>
/// <param name="steamId">The SteamID64 of the player.</param>
/// <param name="create">True if the manager should create a new player if they don't exist.</param>
Expand All @@ -28,15 +27,15 @@ public interface IPlayerManager : IPluginBehavior {
}

/// <summary>
/// Creates a new player.
/// Creates a new player.
/// </summary>
/// <param name="steamId">The SteamID64 of the player.</param>
/// <param name="name">The name of the player.</param>
/// <returns>The new player.</returns>
Task<IGangPlayer> CreatePlayer(ulong steamId, string? name = null);

/// <summary>
/// Deletes a player and all of their associated data.
/// Deletes a player and all of their associated data.
/// </summary>
/// <param name="steamId">The SteamID64 of the player.</param>
/// <returns>True if the player was deleted, false otherwise.</returns>
Expand Down
8 changes: 8 additions & 0 deletions GangsAPI/Services/IPlayerStatManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using GangsAPI.Struct.Stat;

namespace GangsAPI.Services;

public interface IPlayerStatManager {
Task<IGangStat<V>?> GetForPlayer<V>(ulong key, string id);
Task<bool> PushToPlayer<V>(ulong key, string id, V value);
}
Loading

0 comments on commit 197dfd2

Please sign in to comment.