Skip to content

Commit 83fd3f2

Browse files
CopiloteNeRGy164
andauthored
Significantly improve code coverage by adding comprehensive test suite for extension methods
* Add comprehensive tests for IEnumerableTypeDescriptionExtensions missing methods * Add comprehensive edge case tests to improve code coverage --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com>
1 parent f866ce5 commit 83fd3f2

9 files changed

+935
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace DendroDocs.Extensions.Tests;
2+
3+
[TestClass]
4+
public partial class IEnumerableTypeDescriptionExtensionsTests
5+
{
6+
[TestMethod]
7+
public void First_NullTypes_Should_Throw()
8+
{
9+
// Assign
10+
IEnumerable<TypeDescription> types = default!;
11+
12+
// Act
13+
Action action = () => types.First("System.Object");
14+
15+
// Assert
16+
action.ShouldThrow<ArgumentNullException>()
17+
.ParamName.ShouldBe("types");
18+
}
19+
20+
[TestMethod]
21+
public void First_TypeExists_Should_ReturnType()
22+
{
23+
// Assign
24+
var types = new[]
25+
{
26+
new TypeDescription(TypeType.Class, "TestType1"),
27+
new TypeDescription(TypeType.Class, "TestType2")
28+
};
29+
30+
// Act
31+
var result = types.First("TestType1");
32+
33+
// Assert
34+
result.ShouldNotBeNull();
35+
result.FullName.ShouldBe("TestType1");
36+
}
37+
38+
[TestMethod]
39+
public void First_TypeDoesNotExist_Should_Throw()
40+
{
41+
// Assign
42+
var types = new[]
43+
{
44+
new TypeDescription(TypeType.Class, "TestType1"),
45+
new TypeDescription(TypeType.Class, "TestType2")
46+
};
47+
48+
// Act
49+
Action action = () => types.First("NonExistentType");
50+
51+
// Assert
52+
action.ShouldThrow<InvalidOperationException>();
53+
}
54+
55+
[TestMethod]
56+
public void First_EmptyCollection_Should_Throw()
57+
{
58+
// Assign
59+
var types = Array.Empty<TypeDescription>();
60+
61+
// Act
62+
Action action = () => types.First("TestType");
63+
64+
// Assert
65+
action.ShouldThrow<InvalidOperationException>();
66+
}
67+
68+
[TestMethod]
69+
public void First_CaseSensitiveSearch_Should_NotMatch()
70+
{
71+
// Assign
72+
var types = new[]
73+
{
74+
new TypeDescription(TypeType.Class, "testtype"),
75+
new TypeDescription(TypeType.Class, "AnotherType")
76+
};
77+
78+
// Act
79+
Action action = () => types.First("TestType");
80+
81+
// Assert
82+
action.ShouldThrow<InvalidOperationException>();
83+
}
84+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
namespace DendroDocs.Extensions.Tests;
2+
3+
public partial class IEnumerableTypeDescriptionExtensionsTests
4+
{
5+
[TestMethod]
6+
public void FirstOrDefault_NullTypes_Should_Throw()
7+
{
8+
// Assign
9+
IEnumerable<TypeDescription> types = default!;
10+
11+
// Act
12+
Action action = () => types.FirstOrDefault("System.Object");
13+
14+
// Assert
15+
action.ShouldThrow<ArgumentNullException>()
16+
.ParamName.ShouldBe("types");
17+
}
18+
19+
[TestMethod]
20+
public void FirstOrDefault_TypeExists_Should_ReturnType()
21+
{
22+
// Assign
23+
var types = new[]
24+
{
25+
new TypeDescription(TypeType.Class, "TestType1"),
26+
new TypeDescription(TypeType.Class, "TestType2")
27+
};
28+
29+
// Act
30+
var result = types.FirstOrDefault("TestType1");
31+
32+
// Assert
33+
result.ShouldNotBeNull();
34+
result.FullName.ShouldBe("TestType1");
35+
}
36+
37+
[TestMethod]
38+
public void FirstOrDefault_TypeDoesNotExist_Should_ReturnNull()
39+
{
40+
// Assign
41+
var types = new[]
42+
{
43+
new TypeDescription(TypeType.Class, "TestType1"),
44+
new TypeDescription(TypeType.Class, "TestType2")
45+
};
46+
47+
// Act
48+
var result = types.FirstOrDefault("NonExistentType");
49+
50+
// Assert
51+
result.ShouldBeNull();
52+
}
53+
54+
[TestMethod]
55+
public void FirstOrDefault_EmptyCollection_Should_ReturnNull()
56+
{
57+
// Assign
58+
var types = Array.Empty<TypeDescription>();
59+
60+
// Act
61+
var result = types.FirstOrDefault("TestType");
62+
63+
// Assert
64+
result.ShouldBeNull();
65+
}
66+
67+
[TestMethod]
68+
public void FirstOrDefault_CaseSensitiveSearch_Should_ReturnNull()
69+
{
70+
// Assign
71+
var types = new[]
72+
{
73+
new TypeDescription(TypeType.Class, "testtype"),
74+
new TypeDescription(TypeType.Class, "AnotherType")
75+
};
76+
77+
// Act
78+
var result = types.FirstOrDefault("TestType");
79+
80+
// Assert
81+
result.ShouldBeNull();
82+
}
83+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
namespace DendroDocs.Extensions.Tests;
2+
3+
public partial class IEnumerableTypeDescriptionExtensionsTests
4+
{
5+
[TestMethod]
6+
public void GetInvocationConsequenceStatements_NullTypes_Should_Throw()
7+
{
8+
// Assign
9+
IEnumerable<TypeDescription> types = default!;
10+
var invocation = new InvocationDescription("TestType", "TestMethod");
11+
12+
// Act
13+
Action action = () => types.GetInvocationConsequenceStatements(invocation);
14+
15+
// Assert
16+
action.ShouldThrow<ArgumentNullException>()
17+
.ParamName.ShouldBe("types");
18+
}
19+
20+
[TestMethod]
21+
public void GetInvocationConsequenceStatements_NoMatchingMethod_Should_ReturnOnlyOriginalInvocation()
22+
{
23+
// Assign
24+
var types = new[]
25+
{
26+
new TypeDescription(TypeType.Class, "TestType")
27+
};
28+
var invocation = new InvocationDescription("TestType", "NonExistentMethod");
29+
30+
// Act
31+
var result = types.GetInvocationConsequenceStatements(invocation);
32+
33+
// Assert
34+
result.ShouldHaveSingleItem();
35+
result[0].ShouldBe(invocation);
36+
}
37+
38+
[TestMethod]
39+
public void GetInvocationConsequenceStatements_MethodWithNoStatements_Should_ReturnOnlyOriginalInvocation()
40+
{
41+
// Assign
42+
var testType = new TypeDescription(TypeType.Class, "TestType");
43+
var method = new MethodDescription("void", "TestMethod");
44+
testType.AddMember(method);
45+
46+
var types = new[] { testType };
47+
var invocation = new InvocationDescription("TestType", "TestMethod");
48+
49+
// Act
50+
var result = types.GetInvocationConsequenceStatements(invocation);
51+
52+
// Assert
53+
result.ShouldHaveSingleItem();
54+
result[0].ShouldBe(invocation);
55+
}
56+
57+
[TestMethod]
58+
public void GetInvocationConsequenceStatements_MethodWithInvocationStatements_Should_ReturnAllStatements()
59+
{
60+
// Assign
61+
var testType1 = new TypeDescription(TypeType.Class, "TestType1");
62+
var method1 = new MethodDescription("void", "Method1");
63+
var nestedInvocation = new InvocationDescription("TestType2", "Method2");
64+
method1.Statements.Add(nestedInvocation);
65+
testType1.AddMember(method1);
66+
67+
var testType2 = new TypeDescription(TypeType.Class, "TestType2");
68+
var method2 = new MethodDescription("void", "Method2");
69+
testType2.AddMember(method2);
70+
71+
var types = new[] { testType1, testType2 };
72+
var originalInvocation = new InvocationDescription("TestType1", "Method1");
73+
74+
// Act
75+
var result = types.GetInvocationConsequenceStatements(originalInvocation);
76+
77+
// Assert
78+
result.Count.ShouldBe(2);
79+
result.ShouldContain(originalInvocation);
80+
result.ShouldContain(nestedInvocation);
81+
}
82+
83+
[TestMethod]
84+
public void GetInvocationConsequenceStatements_MethodWithNonInvocationStatements_Should_IncludeAllStatements()
85+
{
86+
// Assign
87+
var testType = new TypeDescription(TypeType.Class, "TestType");
88+
var method = new MethodDescription("void", "TestMethod");
89+
90+
var invocationStatement = new InvocationDescription("TestType", "AnotherMethod");
91+
var ifStatement = new If();
92+
method.Statements.Add(invocationStatement);
93+
method.Statements.Add(ifStatement);
94+
testType.AddMember(method);
95+
96+
var types = new[] { testType };
97+
var originalInvocation = new InvocationDescription("TestType", "TestMethod");
98+
99+
// Act
100+
var result = types.GetInvocationConsequenceStatements(originalInvocation);
101+
102+
// Assert
103+
result.Count.ShouldBe(3);
104+
result.ShouldContain(originalInvocation);
105+
result.ShouldContain(invocationStatement);
106+
result.OfType<If>().ShouldHaveSingleItem();
107+
}
108+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
namespace DendroDocs.Extensions.Tests;
2+
3+
public partial class IEnumerableTypeDescriptionExtensionsTests
4+
{
5+
[TestMethod]
6+
public void GetInvocationConsequences_NullTypes_Should_Throw()
7+
{
8+
// Assign
9+
IEnumerable<TypeDescription> types = default!;
10+
var invocation = new InvocationDescription("TestType", "TestMethod");
11+
12+
// Act
13+
Action action = () => types.GetInvocationConsequences(invocation);
14+
15+
// Assert
16+
action.ShouldThrow<ArgumentNullException>()
17+
.ParamName.ShouldBe("types");
18+
}
19+
20+
[TestMethod]
21+
public void GetInvocationConsequences_NoMatchingMethod_Should_ReturnOnlyOriginalInvocation()
22+
{
23+
// Assign
24+
var types = new[]
25+
{
26+
new TypeDescription(TypeType.Class, "TestType")
27+
};
28+
var invocation = new InvocationDescription("TestType", "NonExistentMethod");
29+
30+
// Act
31+
var result = types.GetInvocationConsequences(invocation);
32+
33+
// Assert
34+
result.ShouldHaveSingleItem();
35+
result[0].ShouldBe(invocation);
36+
}
37+
38+
[TestMethod]
39+
public void GetInvocationConsequences_MethodWithNoStatements_Should_ReturnOnlyOriginalInvocation()
40+
{
41+
// Assign
42+
var testType = new TypeDescription(TypeType.Class, "TestType");
43+
var method = new MethodDescription("void", "TestMethod");
44+
testType.AddMember(method);
45+
46+
var types = new[] { testType };
47+
var invocation = new InvocationDescription("TestType", "TestMethod");
48+
49+
// Act
50+
var result = types.GetInvocationConsequences(invocation);
51+
52+
// Assert
53+
result.ShouldHaveSingleItem();
54+
result[0].ShouldBe(invocation);
55+
}
56+
57+
[TestMethod]
58+
public void GetInvocationConsequences_MethodWithInvocationStatements_Should_ReturnAllConsequences()
59+
{
60+
// Assign
61+
var testType1 = new TypeDescription(TypeType.Class, "TestType1");
62+
var method1 = new MethodDescription("void", "Method1");
63+
var nestedInvocation = new InvocationDescription("TestType2", "Method2");
64+
method1.Statements.Add(nestedInvocation);
65+
testType1.AddMember(method1);
66+
67+
var testType2 = new TypeDescription(TypeType.Class, "TestType2");
68+
var method2 = new MethodDescription("void", "Method2");
69+
testType2.AddMember(method2);
70+
71+
var types = new[] { testType1, testType2 };
72+
var originalInvocation = new InvocationDescription("TestType1", "Method1");
73+
74+
// Act
75+
var result = types.GetInvocationConsequences(originalInvocation);
76+
77+
// Assert
78+
result.Count.ShouldBe(2);
79+
result.ShouldContain(originalInvocation);
80+
result.ShouldContain(nestedInvocation);
81+
}
82+
83+
[TestMethod]
84+
public void GetInvocationConsequences_DeepNestedInvocations_Should_ReturnAllLevels()
85+
{
86+
// Assign
87+
var testType1 = new TypeDescription(TypeType.Class, "TestType1");
88+
var method1 = new MethodDescription("void", "Method1");
89+
var invocation2 = new InvocationDescription("TestType2", "Method2");
90+
method1.Statements.Add(invocation2);
91+
testType1.AddMember(method1);
92+
93+
var testType2 = new TypeDescription(TypeType.Class, "TestType2");
94+
var method2 = new MethodDescription("void", "Method2");
95+
var invocation3 = new InvocationDescription("TestType3", "Method3");
96+
method2.Statements.Add(invocation3);
97+
testType2.AddMember(method2);
98+
99+
var testType3 = new TypeDescription(TypeType.Class, "TestType3");
100+
var method3 = new MethodDescription("void", "Method3");
101+
testType3.AddMember(method3);
102+
103+
var types = new[] { testType1, testType2, testType3 };
104+
var originalInvocation = new InvocationDescription("TestType1", "Method1");
105+
106+
// Act
107+
var result = types.GetInvocationConsequences(originalInvocation);
108+
109+
// Assert
110+
result.Count.ShouldBe(3);
111+
result.ShouldContain(originalInvocation);
112+
result.ShouldContain(invocation2);
113+
result.ShouldContain(invocation3);
114+
}
115+
}

0 commit comments

Comments
 (0)