• 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

94.67
/Support/Key2Joy.Tests/Core/Mapping/Actions/Scripting/BaseScriptActionWithEnvironmentTests.cs
1
using Key2Joy.Contracts.Mapping;
2
using Key2Joy.Contracts.Mapping.Actions;
3
using Key2Joy.Contracts.Mapping.Triggers;
4
using Key2Joy.Mapping;
5
using Key2Joy.Mapping.Actions;
6
using Key2Joy.Mapping.Actions.Scripting;
7
using Key2Joy.Mapping.Triggers;
8
using Microsoft.VisualStudio.TestTools.UnitTesting;
9
using Moq;
10
using System;
11
using System.Collections.Generic;
12
using System.Threading.Tasks;
13

14
namespace Key2Joy.Tests.Core.Mapping.Actions.Scripting;
15

16
internal class TestInputBag : AbstractInputBag
17
{
18
}
19

20
internal class TestTriggerListener : AbstractTriggerListener
21
{
22
    public override void AddMappedOption(AbstractMappedOption mappedOption) => throw new NotImplementedException();
×
23

24
    public override bool GetIsTriggered(AbstractTrigger trigger) => throw new NotImplementedException();
×
25

26
    public override void StartListening(ref IList<AbstractTriggerListener> allListeners) => throw new NotImplementedException();
×
27

28
    public override void StopListening() => throw new NotImplementedException();
×
29
}
30

31
public struct ExposedMethodWithAction
32
{
33
    public ExposedMethod ExposedMethod { get; set; }
116✔
34
    public AbstractAction Action { get; set; }
116✔
35
}
36

37
public class MockEnvironment : IDisposable
38
{
39
    public List<ExposedEnumeration> ExposedEnumerations = new();
3✔
40
    public List<ExposedMethodWithAction> ExposedMethodsWithActions = new();
3✔
41

42
    public void Dispose()
43
    { }
1✔
44
}
45

46
public class TestScriptActionWithEnvironment : BaseScriptActionWithEnvironment<MockEnvironment>
47
{
48
    public TestScriptActionWithEnvironment()
49
        : base("TestAction")
4✔
50
    { }
4✔
51

52
    public TestScriptActionWithEnvironment(string name, string script)
53
        : base(name)
2✔
54
        => this.Script = script;
2✔
55

56
    public override MockEnvironment MakeEnvironment()
57
        => new();
2✔
58

59
    public override void RegisterScriptingEnum(ExposedEnumeration enumeration)
60
        => this.Environment.ExposedEnumerations.Add(enumeration);
840✔
61

62
    public override void RegisterScriptingMethod(ExposedMethod exposedMethod, AbstractAction scriptActionInstance)
63
        => this.Environment.ExposedMethodsWithActions.Add(new ExposedMethodWithAction()
116✔
64
        {
116✔
65
            ExposedMethod = exposedMethod,
116✔
66
            Action = scriptActionInstance
116✔
67
        });
116✔
68

69
    public MockEnvironment GetEnvironment()
70
            => this.Environment;
2✔
71
}
72

73
[TestClass]
74
public class BaseScriptActionWithEnvironmentTests
75
{
76
    [TestInitialize]
77
    public void Initialize()
78
    {
79
        ActionsRepository.Buffer();
5✔
80
        TriggersRepository.Buffer();
5✔
81
        ExposedEnumerationRepository.Buffer();
5✔
82
    }
5✔
83

84
    [TestMethod]
85
    public async Task SetupEnvironment_ReturnsEnvironment()
86
    {
87
        var mockAction = new Mock<TestScriptActionWithEnvironment>
1✔
88
        {
1✔
89
            CallBase = true
1✔
90
        };
1✔
91

92
        var environment = mockAction.Object.SetupEnvironment();
1✔
93

94
        Assert.IsNotNull(environment);
1✔
95
    }
1✔
96

97
    [TestMethod]
98
    public async Task RetireEnvironment_SetsIsRetiredToTrue()
99
    {
100
        var mockAction = new Mock<TestScriptActionWithEnvironment>
1✔
101
        {
1✔
102
            CallBase = true
1✔
103
        };
1✔
104

105
        mockAction.Object.RetireEnvironment();
1✔
106

107
        Assert.IsTrue(mockAction.Object.IsRetired);
1✔
108
    }
1✔
109

110
    [TestMethod]
111
    public void MakeEnvironment_ReusesExistingEnvironments()
112
    {
113
        var mockAction = new Mock<TestScriptActionWithEnvironment>() { CallBase = true };
1✔
114
        mockAction.Setup(a => a.MakeEnvironment()).Returns(new MockEnvironment());
1✔
115

116
        var previousEnvironment = mockAction.Object.SetupEnvironment();
1✔
117
        var nextEnvironment = mockAction.Object.SetupEnvironment();
1✔
118

119
        Assert.AreEqual(previousEnvironment, nextEnvironment);
1✔
120
    }
1✔
121

122
    [TestMethod]
123
    public async Task Execute_ReactivatesRetiredEnvironment()
124
    {
125
        var mockAction = new Mock<TestScriptActionWithEnvironment>
1✔
126
        {
1✔
127
            CallBase = true
1✔
128
        };
1✔
129
        mockAction.Object.RetireEnvironment();
1✔
130

131
        await mockAction.Object.Execute(new TestInputBag());
1✔
132

133
        Assert.IsFalse(mockAction.Object.IsRetired);
1✔
134
    }
1✔
135

136
    [TestMethod]
137
    public void OnStartListening_SetsEnvironmentFromExistingScriptAction()
138
    {
139
        var firstAction = new Mock<TestScriptActionWithEnvironment>(
1✔
140
            "FirstAction",
1✔
141
            @"var first = 1;"
1✔
142
        );
1✔
143
        var secondAction = new Mock<TestScriptActionWithEnvironment>(
1✔
144
            "SecondAction",
1✔
145
            @"var second = 2;"
1✔
146
        );
1✔
147

148
        IList<AbstractAction> allActions = new List<AbstractAction> {
1✔
149
            firstAction.Object,
1✔
150
            secondAction.Object
1✔
151
        };
1✔
152

153
        secondAction.Object.OnStartListening(new TestTriggerListener(), ref allActions);
1✔
154

155
        Assert.AreEqual(
1✔
156
            firstAction.Object.GetEnvironment(),
1✔
157
            secondAction.Object.GetEnvironment()
1✔
158
        );
1✔
159
        // Even though the environment is the same, the script action scripts remain separate.
160
        Assert.AreNotEqual(
1✔
161
            firstAction.Object.Script,
1✔
162
            secondAction.Object.Script
1✔
163
        );
1✔
164
    }
1✔
165
}
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