• 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.62
/Support/Key2Joy.Tests/BuildMarkdownDocs/Util/TypeUtilTests.cs
1
using BuildMarkdownDocs.Util;
2
using System;
3
using Microsoft.VisualStudio.TestTools.UnitTesting;
4
using System.Reflection;
5
using System.Linq;
6

7
namespace Key2Joy.Tests.BuildMarkdownDocs.Util;
8

9
[TestClass]
10
public class TypeUtilTests
11
{
12
    public void TestParameterlessMethod()
13
    { }
×
14

15
    public void TestMethodWithParameters(string p1, int p2)
16
    { }
×
17

18
    public void TestMethodWithParameters2(int p1, string p2)
19
    { }
×
20

21
    public static void TestStaticMethodWithParameters(bool p1, string p2)
22
    { }
×
23

24
    public class NestedType
25
    { }
26

27
    public static MethodInfo GetMethodInfoWithSignature(string targetMethodInThisClass, out string signature)
28
    {
29
        var thisType = typeof(TypeUtilTests);
6✔
30
        var thisFullClassName = thisType.FullName;
6✔
31

32
        signature = $"M:{thisFullClassName}.{targetMethodInThisClass}";
6✔
33

34
        var methodInfo = thisType.GetMethod(targetMethodInThisClass);
6✔
35
        return methodInfo;
6✔
36
    }
37

38
    [TestMethod]
39
    public void CleanTypeName_WithNullable()
40
    {
41
        var typeName = "System.Nullable{System.Int32}";
1✔
42
        var result = TypeUtil.CleanTypeName(typeName);
1✔
43
        Assert.AreEqual("System.Nullable`1[System.Int32]", result);
1✔
44
    }
1✔
45

46
    [TestMethod]
47
    public void CleanTypeName_WithoutNullable()
48
    {
49
        var typeName = "System.String";
1✔
50
        var result = TypeUtil.CleanTypeName(typeName);
1✔
51
        Assert.AreEqual("System.String", result);
1✔
52
    }
1✔
53

54
    [TestMethod]
55
    public void GetType_WithExistingType()
56
    {
57
        var typeName = "System.String";
1✔
58
        var type = TypeUtil.GetType(typeName);
1✔
59
        Assert.IsNotNull(type);
1✔
60
        Assert.AreEqual(typeof(string), type);
1✔
61
    }
1✔
62

63
    [TestMethod]
64
    public void GetType_WithNonExistingType()
65
    {
66
        var typeName = "Non.Existing.Type";
1✔
67
        var type = TypeUtil.GetType(typeName);
1✔
68
        Assert.IsNull(type);
1✔
69
    }
1✔
70

71
    [TestMethod]
72
    public void GetType_WithNestedType()
73
    {
74
        var thisClassName = typeof(TypeUtilTests).FullName;
1✔
75
        var typeName = $"{thisClassName}+NestedType";
1✔
76
        var type = TypeUtil.GetType(typeName);
1✔
77
        Assert.IsNotNull(type);
1✔
78
        Assert.AreEqual(typeof(NestedType), type);
1✔
79
    }
1✔
80

81
    [TestMethod]
82
    public void ParseParameterTypes_WithMultipleTypes()
83
    {
84
        var parameters = "System.Int32, System.String";
1✔
85
        var types = TypeUtil.ParseParameterTypes(parameters);
1✔
86
        Assert.AreEqual(2, types.Length);
1✔
87
        Assert.IsTrue(types.Contains(typeof(int)));
1✔
88
        Assert.IsTrue(types.Contains(typeof(string)));
1✔
89
    }
1✔
90

91
    [TestMethod]
92
    public void ParseParameterTypes_WithEmptyString()
93
    {
94
        var parameters = "";
1✔
95
        var types = TypeUtil.ParseParameterTypes(parameters);
1✔
96
        Assert.AreEqual(0, types.Length);
1✔
97
    }
1✔
98

99
    [TestMethod]
100
    [ExpectedException(typeof(ArgumentException))]
101
    public void GetMethodInfo_WithInvalidType()
102
    {
103
        var signature = "M:Invalid.Type.Method";
1✔
104
        TypeUtil.GetMethodInfo(signature);
1✔
105
    }
×
106

107
    [TestMethod]
108
    public void GetMethodInfo_ValidSignature_ReturnsMethodInfo()
109
    {
110
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestParameterlessMethod), out var signature);
1✔
111
        var methodInfo = TypeUtil.GetMethodInfo(signature);
1✔
112

113
        Assert.IsNotNull(methodInfo);
1✔
114
        Assert.AreEqual(expectedMethodInfo, methodInfo);
1✔
115
    }
1✔
116

117
    [TestMethod]
118
    public void GetMethodInfo_ValidSignatureWithEmptyParams_ReturnsMethodInfo()
119
    {
120
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestParameterlessMethod), out var signature);
1✔
121
        signature += "()";
1✔
122
        var methodInfo = TypeUtil.GetMethodInfo(signature);
1✔
123

124
        Assert.IsNotNull(methodInfo);
1✔
125
        Assert.AreEqual(expectedMethodInfo, methodInfo);
1✔
126
    }
1✔
127

128
    [TestMethod]
129
    public void GetMethodInfo_ValidSignatureWithParams_ReturnsMethodInfo()
130
    {
131
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestMethodWithParameters), out var signature);
1✔
132
        signature += "(System.String,System.Int32)";
1✔
133
        var methodInfo = TypeUtil.GetMethodInfo(signature);
1✔
134

135
        Assert.IsNotNull(methodInfo);
1✔
136
        Assert.AreEqual(expectedMethodInfo, methodInfo);
1✔
137
    }
1✔
138

139
    [TestMethod]
140
    public void GetMethodInfo_ValidSignatureWithParams2_WrongParams_ThrowsArgumentException()
141
    {
142
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestMethodWithParameters2), out var signature);
1✔
143
        var invalidSignature = $"{signature}(System.String,System.Int32)"; // wrong order (doesnt exist)
1✔
144

145
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(invalidSignature));
2✔
146
    }
1✔
147

148
    [TestMethod]
149
    public void GetMethodInfo_ValidSignatureWithParams2_ReturnsMethodInfo()
150
    {
151
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestMethodWithParameters2), out var signature);
1✔
152
        signature += "(System.Int32,System.String)";
1✔
153
        var methodInfo = TypeUtil.GetMethodInfo(signature);
1✔
154

155
        Assert.IsNotNull(methodInfo);
1✔
156
        Assert.AreEqual(expectedMethodInfo, methodInfo);
1✔
157
    }
1✔
158

159
    [TestMethod]
160
    public void GetMethodInfo_ValidSignatureWithParamsStatic_ReturnsMethodInfo()
161
    {
162
        var expectedMethodInfo = GetMethodInfoWithSignature(nameof(TestStaticMethodWithParameters), out var signature);
1✔
163
        signature += "(System.Boolean,System.String)";
1✔
164
        var methodInfo = TypeUtil.GetMethodInfo(signature);
1✔
165

166
        Assert.IsNotNull(methodInfo);
1✔
167
        Assert.AreEqual(expectedMethodInfo, methodInfo);
1✔
168
    }
1✔
169

170
    [TestMethod]
171
    public void GetMethodInfo_InvalidSignature_ThrowsArgumentException()
172
    {
173
        var invalidSignature = "InvalidSignature";
1✔
174

175
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(invalidSignature));
2✔
176
    }
1✔
177

178
    [TestMethod]
179
    public void GetMethodInfo_SignatureWithInvalidType_ThrowsArgumentException()
180
    {
181
        var invalidTypeSignature = "M:InvalidType.MethodName";
1✔
182

183
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(invalidTypeSignature));
2✔
184
    }
1✔
185

186
    [TestMethod]
187
    public void GetMethodInfo_SignatureWithInvalidMethod_ThrowsArgumentException()
188
    {
189
        var invalidMethodSignature = "M:Namespace.ClassName.InvalidMethod";
1✔
190

191
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(invalidMethodSignature));
2✔
192
    }
1✔
193

194
    [TestMethod]
195
    public void GetMethodInfo_SignatureWithInvalidParameter_ThrowsArgumentException()
196
    {
197
        var invalidParameterSignature = "M:Namespace.ClassName.MethodName(InvalidParameter)";
1✔
198

199
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(invalidParameterSignature));
2✔
200
    }
1✔
201

202
    [TestMethod]
203
    public void GetMethodInfo_SignatureWithNonexistentType_ThrowsArgumentException()
204
    {
205
        var nonexistentTypeSignature = "M:NonexistentNamespace.NonexistentClass.NonexistentMethod()";
1✔
206

207
        Assert.ThrowsException<ArgumentException>(() => TypeUtil.GetMethodInfo(nonexistentTypeSignature));
2✔
208
    }
1✔
209
}
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

© 2026 Coveralls, Inc