Skip to content

Commit

Permalink
Adding more tests, fixing bugs in the process (#48)
Browse files Browse the repository at this point in the history
* Add config manager tests

* legacy config and mapping profile tests (should fix #42)

* remove comment, problem was caused by transfer across appdomain (or to/fro scripting environment)

* Test core functionality #48 + includes minor refactoring to be able to test + added docs

* Add interop tests + implement and test async test utility (refactors away from singletons)

* fix not all tests running in workflow

* config and interop tests

* Refactor and allow mocking global input hook class

* add capture action test

* Make Execute override optional for script only methods

* add dependency injection + refactor and try test gamepad service

* Refactor config singleton to using dependency injection

* add tests for scripting

* add tests for plugin set + fix plugin showing as loaded even if checksum match failed

* fix tests failing because it relied on config exist (I guess the test order was accidentally correct earlier, this means we should really fix cleanup so we catch this sooner)

* refactor docs code + fix wrong enum summary

* refactor docs builder and start testing it a bit

* fix cmd project structure

* ignore designer files in tests

* cleanup and refactor UI code + show latest version in help

* truncate listview action column

* allow user config to minimize app when pressing X (defaults to shut down app) resolves #45
  • Loading branch information
luttje authored Oct 18, 2023
1 parent 9c9f869 commit 14b7ce9
Show file tree
Hide file tree
Showing 193 changed files with 32,318 additions and 23,981 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,5 @@ jobs:
- name: Cache the build output
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}\bin
${{ github.workspace }}\Support\Key2Joy.Tests\bin\Key2Joy.Tests
path: ${{ github.workspace }}
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-
8 changes: 1 addition & 7 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ jobs:
permissions:
contents: write
steps:
- run: echo 'The triggering workflow passed, building a pre-release'
- uses: actions/checkout@v3
- name: Restore build from cache
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}\bin
${{ github.workspace }}\Support\Key2Joy.Tests\bin\Key2Joy.Tests
path: ${{ github.workspace }}
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-
- name: Archive Pre-release
uses: thedoctor0/zip-release@0.7.1
with:
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@ jobs:
run-tests:
runs-on: windows-latest
steps:
- run: echo 'The triggering workflow passed, testing it'
- uses: actions/checkout@v3
- name: Setup .NET CLI
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Restore build from cache
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}\bin
${{ github.workspace }}\Support\Key2Joy.Tests\bin\Key2Joy.Tests
path: ${{ github.workspace }}
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-
- name: Restore dependencies
run: dotnet restore
- name: Run Key2Joy Tests
run: dotnet test --no-build --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat="lcov" /p:CoverletOutput="${{ github.workspace }}/coverage/lcov.info"
run: dotnet test --no-build --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat="lcov" /p:CoverletOutput="${{ github.workspace }}/coverage/lcov.info" /p:IncludeTestAssembly=true /p:ExcludeByFile="**/*.Designer.cs"
- name: Coveralls for Key2Joy
uses: coverallsapp/github-action@v2
89 changes: 49 additions & 40 deletions Core/Key2Joy.Contracts/Mapping/Actions/AbstractAction.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Key2Joy.Contracts.Mapping.Triggers;

namespace Key2Joy.Contracts.Mapping.Actions;

public abstract class AbstractAction : AbstractMappingAspect
{
[JsonIgnore]
public bool IsStarted { get; set; }

protected AbstractTriggerListener Listener { get; set; }

protected IList<AbstractAction> OtherActions;

public abstract Task Execute(AbstractInputBag inputBag = null);

public virtual string GetNameDisplay() => this.Name;

public AbstractAction(string name)
: base(name) { }

public virtual void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
=> this.SetStartData(listener, ref otherActions);

public virtual void OnStopListening(AbstractTriggerListener listener)
{
this.IsStarted = false;

this.Listener = null;
}

public void SetStartData(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
{
this.IsStarted = true;
this.Listener = listener;
this.OtherActions = otherActions;
}
}
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Key2Joy.Contracts.Mapping.Triggers;
using Key2Joy.Contracts.Util;

namespace Key2Joy.Contracts.Mapping.Actions;

public abstract class AbstractAction : AbstractMappingAspect
{
[JsonIgnore]
public bool IsStarted { get; set; }

protected AbstractTriggerListener Listener { get; set; }

protected IList<AbstractAction> OtherActions;

/// <summary>
/// This method is called to execute the action. It can optionally be override, by
/// default it throws a NotImplementedException, which is useful for actions that
/// only have a script implementation (on other methods).
/// </summary>
/// <param name="inputBag"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public virtual Task Execute(AbstractInputBag inputBag = null) => throw new System.NotImplementedException();

public virtual string GetNameDisplay() => this.Name;

public AbstractAction(string name)
: base(name) { }

public virtual void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
=> this.SetStartData(listener, ref otherActions);

public virtual void OnStopListening(AbstractTriggerListener listener)
{
this.IsStarted = false;

this.Listener = null;
}

public void SetStartData(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
{
this.IsStarted = true;
this.Listener = listener;
this.OtherActions = otherActions;
}
}
115 changes: 65 additions & 50 deletions Core/Key2Joy.Contracts/Mapping/Triggers/AbstractTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
using System;
using System.Text.Json.Serialization;

namespace Key2Joy.Contracts.Mapping.Triggers;

public abstract class AbstractTrigger : AbstractMappingAspect
{
public event EventHandler<TriggerExecutingEventArgs> Executing;

[JsonIgnore]
public AbstractInputBag LastInputBag { get; protected set; }
[JsonIgnore]
public DateTime LastActivated { get; protected set; }
[JsonIgnore]
public bool ExecutedLastActivation { get; protected set; }

public AbstractTrigger(string name)
: base(name) { }

/// <summary>
/// Must return a singleton listener that will listen for triggers.
///
/// When the user starts their mappings, this listener will be given each relevant mapping to look for.
/// </summary>
/// <returns>Singleton trigger listener</returns>
public abstract AbstractTriggerListener GetTriggerListener();

/// <summary>
/// Must return an input value unique in the profile. Like a Keys combination or an AxisDirection.
/// Will be used to quickly lookup input triggers and their corresponding action
/// </summary>
/// <returns></returns>
public abstract string GetUniqueKey();

public virtual bool GetShouldExecute()
{
TriggerExecutingEventArgs eventArgs = new();

Executing?.Invoke(this, eventArgs);

return !eventArgs.Handled;
}

public virtual void DoActivate(AbstractInputBag inputBag, bool executed = false)
{
this.LastActivated = DateTime.Now;
this.LastInputBag = inputBag;
this.ExecutedLastActivation = executed;
}
}
using System;
using System.Text.Json.Serialization;

namespace Key2Joy.Contracts.Mapping.Triggers;

public abstract class AbstractTrigger : AbstractMappingAspect
{
public event EventHandler<TriggerExecutingEventArgs> Executing;

[JsonIgnore]
public AbstractInputBag LastInputBag { get; protected set; }

[JsonIgnore]
public DateTime LastActivated { get; protected set; }

[JsonIgnore]
public bool ExecutedLastActivation { get; protected set; }

public AbstractTrigger(string name)
: base(name) { }

/// <summary>
/// Must return a singleton listener that will listen for triggers.
///
/// When the user starts their mappings, this listener will be given each relevant mapping to look for.
/// </summary>
/// <returns>Singleton trigger listener</returns>
public abstract AbstractTriggerListener GetTriggerListener();

/// <summary>
/// Must return an input value unique in the profile. Like a Keys combination or an AxisDirection.
/// Will be used to quickly lookup input triggers and their corresponding action
/// </summary>
/// <returns></returns>
public abstract string GetUniqueKey();

/// <summary>
/// Through this the trigger can decide if it wants to execute. By default it calls the
/// <see cref="Executing"/> event and executes if it's not handled.
/// This method is only called after the trigger listener has asked which mapped options
/// should even be considered to excecute through <see cref="AbstractTriggerListener.TriggerActivating"/>.
/// </summary>
/// <returns></returns>
public virtual bool GetShouldExecute()
{
TriggerExecutingEventArgs eventArgs = new();

Executing?.Invoke(this, eventArgs);

return !eventArgs.Handled;
}

/// <summary>
/// Called when the trigger has been considered for triggering. By default it just registers
/// the last activation time and input bag.
/// </summary>
/// <param name="inputBag"></param>
/// <param name="executed"></param>
public virtual void DoActivate(AbstractInputBag inputBag, bool executed = false)
{
this.LastActivated = DateTime.Now;
this.LastInputBag = inputBag;
this.ExecutedLastActivation = executed;
}
}
Loading

0 comments on commit 14b7ce9

Please sign in to comment.