• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6557152774

18 Oct 2023 06:36AM UTC coverage: 52.519% (+39.8%) from 12.718%
6557152774

push

github

web-flow
Adding more tests, fixing bugs in the process (#48)

* 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

696 of 1757 branches covered (0.0%)

Branch coverage included in aggregate %.

4597 of 4597 new or added lines in 138 files covered. (100.0%)

3619 of 6459 relevant lines covered (56.03%)

17089.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.27
/Core/Key2Joy.Core/Mapping/Actions/Scripting/BaseScriptActionWithEnvironment.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text.Json.Serialization;
4
using System.Threading.Tasks;
5
using Key2Joy.Contracts.Mapping.Actions;
6
using Key2Joy.Contracts.Mapping.Triggers;
7

8
namespace Key2Joy.Mapping.Actions.Scripting;
9

10
public abstract class BaseScriptActionWithEnvironment<TEnvironment> : BaseScriptAction
11
{
12
    protected TEnvironment Environment;
13
    protected Guid EnvironmentId { get; private set; }
7✔
14

15
    [JsonIgnore]
16
    public bool IsRetired { get; private set; }
7✔
17

18
    public BaseScriptActionWithEnvironment(string name)
19
        : base(name)
14✔
20
    { }
14✔
21

22
    public TEnvironment SetupEnvironment()
23
    {
24
        if (this.Environment is not null and IDisposable disposableEnvironment)
7✔
25
        {
26
            disposableEnvironment.Dispose();
1✔
27
        }
28

29
        this.EnvironmentId = Guid.NewGuid();
7✔
30
        this.Environment = this.MakeEnvironment();
7✔
31
        this.RegisterEnvironmentObjects();
7✔
32

33
        // If we're started, find other actions with the same scripting environment and set their environment to this one
34
        if (this.IsStarted)
7!
35
        {
36
            foreach (var otherAction in this.OtherActions)
×
37
            {
38
                if (otherAction is BaseScriptActionWithEnvironment<TEnvironment> scriptAction)
×
39
                {
40
                    scriptAction.IsRetired = false;
×
41
                    scriptAction.Environment = this.Environment;
×
42
                    scriptAction.EnvironmentId = this.EnvironmentId;
×
43
                }
44
            }
45
        }
46

47
        return this.Environment;
7✔
48
    }
49

50
    public void RetireEnvironment() => this.IsRetired = true;
2✔
51

52
    public override async Task Execute(AbstractInputBag inputBag)
53
    {
54
        if (this.IsRetired)
2✔
55
        {
56
            this.IsRetired = false;
1✔
57
            this.SetupEnvironment();
1✔
58
        }
59
    }
2✔
60

61
    public abstract TEnvironment MakeEnvironment();
62

63
    public virtual void RegisterEnvironmentObjects()
64
    {
65
        var actionTypes = ActionsRepository.GetAllActions();
7✔
66
        this.cachedFile = null;
7✔
67

68
        // Register all scripting available action methods and enumerations
69
        foreach (var pair in actionTypes)
434✔
70
        {
71
            var actionFactory = pair.Value;
210✔
72

73
            foreach (var exposedEnumeration in ExposedEnumerationRepository.GetAllExposedEnumerations())
3,360✔
74
            {
75
                this.RegisterScriptingEnum(exposedEnumeration);
1,470✔
76
            }
77

78
            foreach (var exposedMethods in actionFactory.ExposedMethods)
826✔
79
            {
80
                var instance = this.IsStarted ?
203!
81
                    this.MakeStartedAction(actionFactory)
203✔
82
                    : MakeAction(actionFactory);
203✔
83

84
                this.RegisterScriptingMethod(
203✔
85
                    exposedMethods,
203✔
86
                    instance);
203✔
87
            }
88
        }
89
    }
7✔
90

91
    public override void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
92
    {
93
        base.OnStartListening(listener, ref otherActions);
×
94

95
        foreach (var otherAction in otherActions)
×
96
        {
97
            if (otherAction is BaseScriptActionWithEnvironment<TEnvironment> scriptAction
×
98
                && scriptAction.IsStarted)
×
99
            {
100
                // Use an existing environment if it exists
101
                // This is so multiple actions all share the same scripting environment (and thus global variables).
102
                this.Environment = scriptAction.Environment;
×
103
                this.EnvironmentId = scriptAction.EnvironmentId;
×
104

105
                if (this.Environment != null)
×
106
                {
107
                    return;
×
108
                }
109
            }
110
        }
111

112
        this.SetupEnvironment();
×
113
    }
×
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc