From c0a637ce2b77d886c1ccf1203ae8be0d8c7822de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:25:54 +0000 Subject: [PATCH 1/4] Initial plan From e6fbaca26583cea5c42c4905ef36d1977fd2c2b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:34:20 +0000 Subject: [PATCH 2/4] Add comprehensive tests for IEnumerableTypeDescriptionExtensions missing methods Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com> --- ...bleTypeDescriptionExtensionsTests.First.cs | 67 +++++++++ ...scriptionExtensionsTests.FirstOrDefault.cs | 66 +++++++++ ...ests.GetInvocationConsequenceStatements.cs | 108 +++++++++++++++ ...tensionsTests.GetInvocationConsequences.cs | 115 ++++++++++++++++ ...riptionExtensionsTests.GetInvokedMethod.cs | 94 +++++++++++++ ...iptionExtensionsTests.TraverseStatement.cs | 129 ++++++++++++++++++ 6 files changed, 579 insertions(+) create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequenceStatements.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequences.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs new file mode 100644 index 0000000..f6b2421 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs @@ -0,0 +1,67 @@ +namespace DendroDocs.Extensions.Tests; + +[TestClass] +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void First_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + + // Act + Action action = () => types.First("System.Object"); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void First_TypeExists_Should_ReturnType() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType1"), + new TypeDescription(TypeType.Class, "TestType2") + }; + + // Act + var result = types.First("TestType1"); + + // Assert + result.ShouldNotBeNull(); + result.FullName.ShouldBe("TestType1"); + } + + [TestMethod] + public void First_TypeDoesNotExist_Should_Throw() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType1"), + new TypeDescription(TypeType.Class, "TestType2") + }; + + // Act + Action action = () => types.First("NonExistentType"); + + // Assert + action.ShouldThrow(); + } + + [TestMethod] + public void First_EmptyCollection_Should_Throw() + { + // Assign + var types = Array.Empty(); + + // Act + Action action = () => types.First("TestType"); + + // Assert + action.ShouldThrow(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs new file mode 100644 index 0000000..2c9a7ef --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs @@ -0,0 +1,66 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void FirstOrDefault_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + + // Act + Action action = () => types.FirstOrDefault("System.Object"); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void FirstOrDefault_TypeExists_Should_ReturnType() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType1"), + new TypeDescription(TypeType.Class, "TestType2") + }; + + // Act + var result = types.FirstOrDefault("TestType1"); + + // Assert + result.ShouldNotBeNull(); + result.FullName.ShouldBe("TestType1"); + } + + [TestMethod] + public void FirstOrDefault_TypeDoesNotExist_Should_ReturnNull() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType1"), + new TypeDescription(TypeType.Class, "TestType2") + }; + + // Act + var result = types.FirstOrDefault("NonExistentType"); + + // Assert + result.ShouldBeNull(); + } + + [TestMethod] + public void FirstOrDefault_EmptyCollection_Should_ReturnNull() + { + // Assign + var types = Array.Empty(); + + // Act + var result = types.FirstOrDefault("TestType"); + + // Assert + result.ShouldBeNull(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequenceStatements.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequenceStatements.cs new file mode 100644 index 0000000..5b37722 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequenceStatements.cs @@ -0,0 +1,108 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void GetInvocationConsequenceStatements_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + Action action = () => types.GetInvocationConsequenceStatements(invocation); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void GetInvocationConsequenceStatements_NoMatchingMethod_Should_ReturnOnlyOriginalInvocation() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType") + }; + var invocation = new InvocationDescription("TestType", "NonExistentMethod"); + + // Act + var result = types.GetInvocationConsequenceStatements(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].ShouldBe(invocation); + } + + [TestMethod] + public void GetInvocationConsequenceStatements_MethodWithNoStatements_Should_ReturnOnlyOriginalInvocation() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvocationConsequenceStatements(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].ShouldBe(invocation); + } + + [TestMethod] + public void GetInvocationConsequenceStatements_MethodWithInvocationStatements_Should_ReturnAllStatements() + { + // Assign + var testType1 = new TypeDescription(TypeType.Class, "TestType1"); + var method1 = new MethodDescription("void", "Method1"); + var nestedInvocation = new InvocationDescription("TestType2", "Method2"); + method1.Statements.Add(nestedInvocation); + testType1.AddMember(method1); + + var testType2 = new TypeDescription(TypeType.Class, "TestType2"); + var method2 = new MethodDescription("void", "Method2"); + testType2.AddMember(method2); + + var types = new[] { testType1, testType2 }; + var originalInvocation = new InvocationDescription("TestType1", "Method1"); + + // Act + var result = types.GetInvocationConsequenceStatements(originalInvocation); + + // Assert + result.Count.ShouldBe(2); + result.ShouldContain(originalInvocation); + result.ShouldContain(nestedInvocation); + } + + [TestMethod] + public void GetInvocationConsequenceStatements_MethodWithNonInvocationStatements_Should_IncludeAllStatements() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + + var invocationStatement = new InvocationDescription("TestType", "AnotherMethod"); + var ifStatement = new If(); + method.Statements.Add(invocationStatement); + method.Statements.Add(ifStatement); + testType.AddMember(method); + + var types = new[] { testType }; + var originalInvocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvocationConsequenceStatements(originalInvocation); + + // Assert + result.Count.ShouldBe(3); + result.ShouldContain(originalInvocation); + result.ShouldContain(invocationStatement); + result.OfType().ShouldHaveSingleItem(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequences.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequences.cs new file mode 100644 index 0000000..d9704a4 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvocationConsequences.cs @@ -0,0 +1,115 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void GetInvocationConsequences_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + Action action = () => types.GetInvocationConsequences(invocation); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void GetInvocationConsequences_NoMatchingMethod_Should_ReturnOnlyOriginalInvocation() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType") + }; + var invocation = new InvocationDescription("TestType", "NonExistentMethod"); + + // Act + var result = types.GetInvocationConsequences(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].ShouldBe(invocation); + } + + [TestMethod] + public void GetInvocationConsequences_MethodWithNoStatements_Should_ReturnOnlyOriginalInvocation() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvocationConsequences(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].ShouldBe(invocation); + } + + [TestMethod] + public void GetInvocationConsequences_MethodWithInvocationStatements_Should_ReturnAllConsequences() + { + // Assign + var testType1 = new TypeDescription(TypeType.Class, "TestType1"); + var method1 = new MethodDescription("void", "Method1"); + var nestedInvocation = new InvocationDescription("TestType2", "Method2"); + method1.Statements.Add(nestedInvocation); + testType1.AddMember(method1); + + var testType2 = new TypeDescription(TypeType.Class, "TestType2"); + var method2 = new MethodDescription("void", "Method2"); + testType2.AddMember(method2); + + var types = new[] { testType1, testType2 }; + var originalInvocation = new InvocationDescription("TestType1", "Method1"); + + // Act + var result = types.GetInvocationConsequences(originalInvocation); + + // Assert + result.Count.ShouldBe(2); + result.ShouldContain(originalInvocation); + result.ShouldContain(nestedInvocation); + } + + [TestMethod] + public void GetInvocationConsequences_DeepNestedInvocations_Should_ReturnAllLevels() + { + // Assign + var testType1 = new TypeDescription(TypeType.Class, "TestType1"); + var method1 = new MethodDescription("void", "Method1"); + var invocation2 = new InvocationDescription("TestType2", "Method2"); + method1.Statements.Add(invocation2); + testType1.AddMember(method1); + + var testType2 = new TypeDescription(TypeType.Class, "TestType2"); + var method2 = new MethodDescription("void", "Method2"); + var invocation3 = new InvocationDescription("TestType3", "Method3"); + method2.Statements.Add(invocation3); + testType2.AddMember(method2); + + var testType3 = new TypeDescription(TypeType.Class, "TestType3"); + var method3 = new MethodDescription("void", "Method3"); + testType3.AddMember(method3); + + var types = new[] { testType1, testType2, testType3 }; + var originalInvocation = new InvocationDescription("TestType1", "Method1"); + + // Act + var result = types.GetInvocationConsequences(originalInvocation); + + // Assert + result.Count.ShouldBe(3); + result.ShouldContain(originalInvocation); + result.ShouldContain(invocation2); + result.ShouldContain(invocation3); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs new file mode 100644 index 0000000..5590cb5 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs @@ -0,0 +1,94 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void GetInvokedMethod_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + Action action = () => types.GetInvokedMethod(invocation); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void GetInvokedMethod_TypeNotFound_Should_ReturnEmptyList() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "TestType1") + }; + var invocation = new InvocationDescription("NonExistentType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void GetInvokedMethod_TypeFoundWithMatchingMethod_Should_ReturnMethods() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].Name.ShouldBe("TestMethod"); + } + + [TestMethod] + public void GetInvokedMethod_TypeFoundWithNonMatchingMethod_Should_ReturnEmptyList() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "DifferentMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void GetInvokedMethod_TypeFoundWithMultipleMatchingMethods_Should_ReturnAllMatches() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method1 = new MethodDescription("void", "TestMethod"); + var method2 = new MethodDescription("int", "TestMethod"); + testType.AddMember(method1); + testType.AddMember(method2); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.Count.ShouldBe(2); + result.All(m => m.Name == "TestMethod").ShouldBeTrue(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs new file mode 100644 index 0000000..2ee8a27 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs @@ -0,0 +1,129 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void TraverseStatement_NullTypes_Should_Throw() + { + // Assign + IEnumerable types = default!; + var statement = new InvocationDescription("TestType", "TestMethod"); + + // Act + Action action = () => types.TraverseStatement(statement); + + // Assert + action.ShouldThrow() + .ParamName.ShouldBe("types"); + } + + [TestMethod] + public void TraverseStatement_InvocationDescription_Should_ReturnConsequenceStatements() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.TraverseStatement(invocation); + + // Assert + result.ShouldHaveSingleItem(); + result[0].ShouldBe(invocation); + } + + [TestMethod] + public void TraverseStatement_SwitchStatement_Should_TraverseAllSections() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + + var switchStatement = new Switch { Expression = "value" }; + var section1 = new SwitchSection(); + section1.Labels.Add("case1"); + section1.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + + var section2 = new SwitchSection(); + section2.Labels.Add("case2"); + section2.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + + switchStatement.Sections.Add(section1); + switchStatement.Sections.Add(section2); + + // Act + var result = types.TraverseStatement(switchStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultSwitch = result[0].ShouldBeOfType(); + resultSwitch.Sections.Count.ShouldBe(2); + resultSwitch.Expression.ShouldBe("value"); + + // Check that each section has traversed statements + resultSwitch.Sections[0].Statements.ShouldHaveSingleItem(); + resultSwitch.Sections[1].Statements.ShouldHaveSingleItem(); + } + + [TestMethod] + public void TraverseStatement_IfStatement_Should_TraverseAllSections() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + + var ifStatement = new If(); + var section1 = new IfElseSection { Condition = "condition1" }; + section1.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + + var section2 = new IfElseSection { Condition = "condition2" }; + section2.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + + ifStatement.Sections.Add(section1); + ifStatement.Sections.Add(section2); + + // Act + var result = types.TraverseStatement(ifStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultIf = result[0].ShouldBeOfType(); + resultIf.Sections.Count.ShouldBe(2); + + // Check that each section has traversed statements and correct conditions + resultIf.Sections[0].Statements.ShouldHaveSingleItem(); + resultIf.Sections[0].Condition.ShouldBe("condition1"); + resultIf.Sections[1].Statements.ShouldHaveSingleItem(); + resultIf.Sections[1].Condition.ShouldBe("condition2"); + } + + [TestMethod] + public void TraverseStatement_UnknownStatementType_Should_ReturnEmptyList() + { + // Assign + var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; + var unknownStatement = new TestStatement(); // Create a mock statement type + + // Act + var result = types.TraverseStatement(unknownStatement); + + // Assert + result.ShouldBeEmpty(); + } + + // Helper class for testing unknown statement types + private class TestStatement : Statement + { + // This represents any statement type not handled by TraverseStatement + } +} \ No newline at end of file From c62963608cde6236bfc6c7113fd1093ce613a3b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:41:05 +0000 Subject: [PATCH 3/4] Add comprehensive edge case tests to improve code coverage Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com> --- ...ypeDescriptionExtensionsTests.EdgeCases.cs | 151 ++++++++++++++++++ ...ionDescriptionExtensionsTests.EdgeCases.cs | 96 +++++++++++ .../StringExtensionsTests.EdgeCases.cs | 121 ++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs create mode 100644 tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs new file mode 100644 index 0000000..d6fe6c8 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs @@ -0,0 +1,151 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class IEnumerableTypeDescriptionExtensionsTests +{ + [TestMethod] + public void First_CaseSensitiveSearch_Should_NotMatch() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "testtype"), + new TypeDescription(TypeType.Class, "AnotherType") + }; + + // Act + Action action = () => types.First("TestType"); + + // Assert + action.ShouldThrow(); + } + + [TestMethod] + public void FirstOrDefault_CaseSensitiveSearch_Should_ReturnNull() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "testtype"), + new TypeDescription(TypeType.Class, "AnotherType") + }; + + // Act + var result = types.FirstOrDefault("TestType"); + + // Assert + result.ShouldBeNull(); + } + + [TestMethod] + public void GetInvokedMethod_CaseSensitiveContainingType_Should_ReturnEmpty() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "testtype"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); // Different case + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void TraverseStatement_SwitchWithNoSections_Should_ReturnEmptySwitch() + { + // Assign + var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; + var switchStatement = new Switch { Expression = "value" }; + + // Act + var result = types.TraverseStatement(switchStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultSwitch = result[0].ShouldBeOfType(); + resultSwitch.Sections.ShouldBeEmpty(); + resultSwitch.Expression.ShouldBe("value"); + } + + [TestMethod] + public void TraverseStatement_IfWithNoSections_Should_ReturnEmptyIf() + { + // Assign + var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; + var ifStatement = new If(); + + // Act + var result = types.TraverseStatement(ifStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultIf = result[0].ShouldBeOfType(); + resultIf.Sections.ShouldBeEmpty(); + } + + [TestMethod] + public void GetInvokedMethod_MultipleTypesWithSameName_Should_ReturnFromFirstMatch() + { + // Assign + var testType1 = new TypeDescription(TypeType.Class, "TestType"); + var method1 = new MethodDescription("void", "TestMethod"); + testType1.AddMember(method1); + + var testType2 = new TypeDescription(TypeType.Class, "TestType"); // Same name + var method2 = new MethodDescription("int", "TestMethod"); + testType2.AddMember(method2); + + var types = new[] { testType1, testType2 }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldHaveSingleItem(); + var methodResult = result[0] as MethodDescription; + methodResult.ShouldNotBeNull(); + methodResult.ReturnType.ShouldBe("void"); // Should get the first match + } + + [TestMethod] + public void TraverseStatement_NestedSwitchInIf_Should_TraverseRecursively() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + + var ifStatement = new If(); + var ifSection = new IfElseSection { Condition = "condition" }; + + var nestedSwitch = new Switch { Expression = "nested" }; + var switchSection = new SwitchSection(); + switchSection.Labels.Add("case1"); + switchSection.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + nestedSwitch.Sections.Add(switchSection); + + ifSection.Statements.Add(nestedSwitch); + ifStatement.Sections.Add(ifSection); + + // Act + var result = types.TraverseStatement(ifStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultIf = result[0].ShouldBeOfType(); + resultIf.Sections.ShouldHaveSingleItem(); + + var resultIfSection = resultIf.Sections[0]; + resultIfSection.Statements.ShouldHaveSingleItem(); + var nestedSwitchResult = resultIfSection.Statements[0].ShouldBeOfType(); + nestedSwitchResult.Sections.ShouldHaveSingleItem(); + nestedSwitchResult.Sections[0].Statements.ShouldHaveSingleItem(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs new file mode 100644 index 0000000..1e86805 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs @@ -0,0 +1,96 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class InvocationDescriptionExtensionsTests +{ + [TestMethod] + public void MatchesMethod_InvocationNameCaseSensitive_Should_NotMatch() + { + // Assign + var method = new MethodDescription("void", "method"); + var invocation = new InvocationDescription("System.Object", "Method"); + + // Act + var result = invocation.MatchesMethod(method); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithExtraArgumentsAndNoOptionalParameters_Should_NotMatch() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithExactArgumentsAndSomeOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithPartialArgumentsMatchingOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithAllArgumentsAndOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + invocation.Arguments.Add(new ArgumentDescription("bool", "arg3")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } +} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs new file mode 100644 index 0000000..1284c38 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs @@ -0,0 +1,121 @@ +namespace DendroDocs.Extensions.Tests; + +public partial class StringExtensionsTests +{ + [TestMethod] + public void ToSentenceCase_StringWithSpaces_Should_HandleCorrectly() + { + // Assign + var input = "Test Method"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("Test Method"); // Space before capital M + } + + [TestMethod] + public void ToSentenceCase_StringWithSpecialCharacters_Should_HandleCorrectly() + { + // Assign + var input = "Test_Method$Name"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("Test_ Method$ Name"); // Spaces before capital letters + } + + [TestMethod] + public void ToSentenceCase_SingleCharacter_Should_HandleCorrectly() + { + // Assign + var input = "a"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("A"); + } + + [TestMethod] + public void ToSentenceCase_SingleUpperCharacter_Should_HandleCorrectly() + { + // Assign + var input = "A"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("A"); + } + + [TestMethod] + public void GenericTypes_NonGenericType_Should_ReturnEmptyList() + { + // Assign + var input = "System.String"; + + // Act + var result = input.GenericTypes(); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void IsGeneric_NonGenericTypeEndingWithGreaterThan_Should_ReturnFalse() + { + // Assign + var input = "SomeType>NotGeneric"; + + // Act + var result = input.IsGeneric(); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void IsGeneric_TypeWithAngleBracketsButNotAtEnd_Should_ReturnFalse() + { + // Assign + var input = "SomeNotAtEnd"; + + // Act + var result = input.IsGeneric(); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void ForDiagram_NonGenericSimpleType_Should_ReturnAsIs() + { + // Assign + var input = "String"; + + // Act + var result = input.ForDiagram(); + + // Assert + result.ShouldBe("String"); + } + + [TestMethod] + public void ForDiagram_TypeWithoutDots_Should_ReturnAsIs() + { + // Assign + var input = "SimpleType"; + + // Act + var result = input.ForDiagram(); + + // Assert + result.ShouldBe("SimpleType"); + } +} \ No newline at end of file From b3997b57a1584e3daa43dcea50d2cbe7752d353f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 12:59:17 +0000 Subject: [PATCH 4/4] Consolidate edge case tests into method-scoped files Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com> --- ...ypeDescriptionExtensionsTests.EdgeCases.cs | 151 ------------------ ...bleTypeDescriptionExtensionsTests.First.cs | 17 ++ ...scriptionExtensionsTests.FirstOrDefault.cs | 17 ++ ...riptionExtensionsTests.GetInvokedMethod.cs | 43 +++++ ...iptionExtensionsTests.TraverseStatement.cs | 70 ++++++++ ...ionDescriptionExtensionsTests.EdgeCases.cs | 96 ----------- ...riptionExtensionsTests.MatchesMethod.cs.cs | 14 ++ ...ionExtensionsTests.MatchesParameters.cs.cs | 78 +++++++++ .../StringExtensionsTests.EdgeCases.cs | 121 -------------- .../Extensions/StringExtensionsTests.cs | 117 ++++++++++++++ 10 files changed, 356 insertions(+), 368 deletions(-) delete mode 100644 tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs delete mode 100644 tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs delete mode 100644 tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs deleted file mode 100644 index d6fe6c8..0000000 --- a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.EdgeCases.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace DendroDocs.Extensions.Tests; - -public partial class IEnumerableTypeDescriptionExtensionsTests -{ - [TestMethod] - public void First_CaseSensitiveSearch_Should_NotMatch() - { - // Assign - var types = new[] - { - new TypeDescription(TypeType.Class, "testtype"), - new TypeDescription(TypeType.Class, "AnotherType") - }; - - // Act - Action action = () => types.First("TestType"); - - // Assert - action.ShouldThrow(); - } - - [TestMethod] - public void FirstOrDefault_CaseSensitiveSearch_Should_ReturnNull() - { - // Assign - var types = new[] - { - new TypeDescription(TypeType.Class, "testtype"), - new TypeDescription(TypeType.Class, "AnotherType") - }; - - // Act - var result = types.FirstOrDefault("TestType"); - - // Assert - result.ShouldBeNull(); - } - - [TestMethod] - public void GetInvokedMethod_CaseSensitiveContainingType_Should_ReturnEmpty() - { - // Assign - var testType = new TypeDescription(TypeType.Class, "testtype"); - var method = new MethodDescription("void", "TestMethod"); - testType.AddMember(method); - - var types = new[] { testType }; - var invocation = new InvocationDescription("TestType", "TestMethod"); // Different case - - // Act - var result = types.GetInvokedMethod(invocation); - - // Assert - result.ShouldBeEmpty(); - } - - [TestMethod] - public void TraverseStatement_SwitchWithNoSections_Should_ReturnEmptySwitch() - { - // Assign - var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; - var switchStatement = new Switch { Expression = "value" }; - - // Act - var result = types.TraverseStatement(switchStatement); - - // Assert - result.ShouldHaveSingleItem(); - var resultSwitch = result[0].ShouldBeOfType(); - resultSwitch.Sections.ShouldBeEmpty(); - resultSwitch.Expression.ShouldBe("value"); - } - - [TestMethod] - public void TraverseStatement_IfWithNoSections_Should_ReturnEmptyIf() - { - // Assign - var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; - var ifStatement = new If(); - - // Act - var result = types.TraverseStatement(ifStatement); - - // Assert - result.ShouldHaveSingleItem(); - var resultIf = result[0].ShouldBeOfType(); - resultIf.Sections.ShouldBeEmpty(); - } - - [TestMethod] - public void GetInvokedMethod_MultipleTypesWithSameName_Should_ReturnFromFirstMatch() - { - // Assign - var testType1 = new TypeDescription(TypeType.Class, "TestType"); - var method1 = new MethodDescription("void", "TestMethod"); - testType1.AddMember(method1); - - var testType2 = new TypeDescription(TypeType.Class, "TestType"); // Same name - var method2 = new MethodDescription("int", "TestMethod"); - testType2.AddMember(method2); - - var types = new[] { testType1, testType2 }; - var invocation = new InvocationDescription("TestType", "TestMethod"); - - // Act - var result = types.GetInvokedMethod(invocation); - - // Assert - result.ShouldHaveSingleItem(); - var methodResult = result[0] as MethodDescription; - methodResult.ShouldNotBeNull(); - methodResult.ReturnType.ShouldBe("void"); // Should get the first match - } - - [TestMethod] - public void TraverseStatement_NestedSwitchInIf_Should_TraverseRecursively() - { - // Assign - var testType = new TypeDescription(TypeType.Class, "TestType"); - var method = new MethodDescription("void", "TestMethod"); - testType.AddMember(method); - - var types = new[] { testType }; - - var ifStatement = new If(); - var ifSection = new IfElseSection { Condition = "condition" }; - - var nestedSwitch = new Switch { Expression = "nested" }; - var switchSection = new SwitchSection(); - switchSection.Labels.Add("case1"); - switchSection.Statements.Add(new InvocationDescription("TestType", "TestMethod")); - nestedSwitch.Sections.Add(switchSection); - - ifSection.Statements.Add(nestedSwitch); - ifStatement.Sections.Add(ifSection); - - // Act - var result = types.TraverseStatement(ifStatement); - - // Assert - result.ShouldHaveSingleItem(); - var resultIf = result[0].ShouldBeOfType(); - resultIf.Sections.ShouldHaveSingleItem(); - - var resultIfSection = resultIf.Sections[0]; - resultIfSection.Statements.ShouldHaveSingleItem(); - var nestedSwitchResult = resultIfSection.Statements[0].ShouldBeOfType(); - nestedSwitchResult.Sections.ShouldHaveSingleItem(); - nestedSwitchResult.Sections[0].Statements.ShouldHaveSingleItem(); - } -} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs index f6b2421..8e293f2 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs @@ -64,4 +64,21 @@ public void First_EmptyCollection_Should_Throw() // Assert action.ShouldThrow(); } + + [TestMethod] + public void First_CaseSensitiveSearch_Should_NotMatch() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "testtype"), + new TypeDescription(TypeType.Class, "AnotherType") + }; + + // Act + Action action = () => types.First("TestType"); + + // Assert + action.ShouldThrow(); + } } \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs index 2c9a7ef..a46c00f 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs @@ -63,4 +63,21 @@ public void FirstOrDefault_EmptyCollection_Should_ReturnNull() // Assert result.ShouldBeNull(); } + + [TestMethod] + public void FirstOrDefault_CaseSensitiveSearch_Should_ReturnNull() + { + // Assign + var types = new[] + { + new TypeDescription(TypeType.Class, "testtype"), + new TypeDescription(TypeType.Class, "AnotherType") + }; + + // Act + var result = types.FirstOrDefault("TestType"); + + // Assert + result.ShouldBeNull(); + } } \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs index 5590cb5..f3980c1 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs @@ -91,4 +91,47 @@ public void GetInvokedMethod_TypeFoundWithMultipleMatchingMethods_Should_ReturnA result.Count.ShouldBe(2); result.All(m => m.Name == "TestMethod").ShouldBeTrue(); } + + [TestMethod] + public void GetInvokedMethod_CaseSensitiveContainingType_Should_ReturnEmpty() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "testtype"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + var invocation = new InvocationDescription("TestType", "TestMethod"); // Different case + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void GetInvokedMethod_MultipleTypesWithSameName_Should_ReturnFromFirstMatch() + { + // Assign + var testType1 = new TypeDescription(TypeType.Class, "TestType"); + var method1 = new MethodDescription("void", "TestMethod"); + testType1.AddMember(method1); + + var testType2 = new TypeDescription(TypeType.Class, "TestType"); // Same name + var method2 = new MethodDescription("int", "TestMethod"); + testType2.AddMember(method2); + + var types = new[] { testType1, testType2 }; + var invocation = new InvocationDescription("TestType", "TestMethod"); + + // Act + var result = types.GetInvokedMethod(invocation); + + // Assert + result.ShouldHaveSingleItem(); + var methodResult = result[0] as MethodDescription; + methodResult.ShouldNotBeNull(); + methodResult.ReturnType.ShouldBe("void"); // Should get the first match + } } \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs index 2ee8a27..04dde29 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs @@ -121,6 +121,76 @@ public void TraverseStatement_UnknownStatementType_Should_ReturnEmptyList() result.ShouldBeEmpty(); } + [TestMethod] + public void TraverseStatement_SwitchWithNoSections_Should_ReturnEmptySwitch() + { + // Assign + var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; + var switchStatement = new Switch { Expression = "value" }; + + // Act + var result = types.TraverseStatement(switchStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultSwitch = result[0].ShouldBeOfType(); + resultSwitch.Sections.ShouldBeEmpty(); + resultSwitch.Expression.ShouldBe("value"); + } + + [TestMethod] + public void TraverseStatement_IfWithNoSections_Should_ReturnEmptyIf() + { + // Assign + var types = new[] { new TypeDescription(TypeType.Class, "TestType") }; + var ifStatement = new If(); + + // Act + var result = types.TraverseStatement(ifStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultIf = result[0].ShouldBeOfType(); + resultIf.Sections.ShouldBeEmpty(); + } + + [TestMethod] + public void TraverseStatement_NestedSwitchInIf_Should_TraverseRecursively() + { + // Assign + var testType = new TypeDescription(TypeType.Class, "TestType"); + var method = new MethodDescription("void", "TestMethod"); + testType.AddMember(method); + + var types = new[] { testType }; + + var ifStatement = new If(); + var ifSection = new IfElseSection { Condition = "condition" }; + + var nestedSwitch = new Switch { Expression = "nested" }; + var switchSection = new SwitchSection(); + switchSection.Labels.Add("case1"); + switchSection.Statements.Add(new InvocationDescription("TestType", "TestMethod")); + nestedSwitch.Sections.Add(switchSection); + + ifSection.Statements.Add(nestedSwitch); + ifStatement.Sections.Add(ifSection); + + // Act + var result = types.TraverseStatement(ifStatement); + + // Assert + result.ShouldHaveSingleItem(); + var resultIf = result[0].ShouldBeOfType(); + resultIf.Sections.ShouldHaveSingleItem(); + + var resultIfSection = resultIf.Sections[0]; + resultIfSection.Statements.ShouldHaveSingleItem(); + var nestedSwitchResult = resultIfSection.Statements[0].ShouldBeOfType(); + nestedSwitchResult.Sections.ShouldHaveSingleItem(); + nestedSwitchResult.Sections[0].Statements.ShouldHaveSingleItem(); + } + // Helper class for testing unknown statement types private class TestStatement : Statement { diff --git a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs deleted file mode 100644 index 1e86805..0000000 --- a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.EdgeCases.cs +++ /dev/null @@ -1,96 +0,0 @@ -namespace DendroDocs.Extensions.Tests; - -public partial class InvocationDescriptionExtensionsTests -{ - [TestMethod] - public void MatchesMethod_InvocationNameCaseSensitive_Should_NotMatch() - { - // Assign - var method = new MethodDescription("void", "method"); - var invocation = new InvocationDescription("System.Object", "Method"); - - // Act - var result = invocation.MatchesMethod(method); - - // Assert - result.ShouldBeFalse(); - } - - [TestMethod] - public void MatchesParameters_InvocationWithExtraArgumentsAndNoOptionalParameters_Should_NotMatch() - { - // Assign - var method = new MethodDescription("void", "Method"); - method.Parameters.Add(new ParameterDescription("string", "param1")); - - var invocation = new InvocationDescription("System.Object", "Method"); - invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); - invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); - - // Act - var result = invocation.MatchesParameters(method); - - // Assert - result.ShouldBeFalse(); - } - - [TestMethod] - public void MatchesParameters_InvocationWithExactArgumentsAndSomeOptionalParameters_Should_Match() - { - // Assign - var method = new MethodDescription("void", "Method"); - method.Parameters.Add(new ParameterDescription("string", "param1")); - method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); - method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); - - var invocation = new InvocationDescription("System.Object", "Method"); - invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); - - // Act - var result = invocation.MatchesParameters(method); - - // Assert - result.ShouldBeTrue(); - } - - [TestMethod] - public void MatchesParameters_InvocationWithPartialArgumentsMatchingOptionalParameters_Should_Match() - { - // Assign - var method = new MethodDescription("void", "Method"); - method.Parameters.Add(new ParameterDescription("string", "param1")); - method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); - method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); - - var invocation = new InvocationDescription("System.Object", "Method"); - invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); - invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); - - // Act - var result = invocation.MatchesParameters(method); - - // Assert - result.ShouldBeTrue(); - } - - [TestMethod] - public void MatchesParameters_InvocationWithAllArgumentsAndOptionalParameters_Should_Match() - { - // Assign - var method = new MethodDescription("void", "Method"); - method.Parameters.Add(new ParameterDescription("string", "param1")); - method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); - method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); - - var invocation = new InvocationDescription("System.Object", "Method"); - invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); - invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); - invocation.Arguments.Add(new ArgumentDescription("bool", "arg3")); - - // Act - var result = invocation.MatchesParameters(method); - - // Assert - result.ShouldBeTrue(); - } -} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesMethod.cs.cs b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesMethod.cs.cs index a7b8444..ca69fa7 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesMethod.cs.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesMethod.cs.cs @@ -74,4 +74,18 @@ public void MatchesMethod_InvocationNameNotEqualsMethodName_Should_NotMatch() // Assert result.ShouldBeFalse(); } + + [TestMethod] + public void MatchesMethod_InvocationNameCaseSensitive_Should_NotMatch() + { + // Assign + var method = new MethodDescription("void", "method"); + var invocation = new InvocationDescription("System.Object", "Method"); + + // Act + var result = invocation.MatchesMethod(method); + + // Assert + result.ShouldBeFalse(); + } } diff --git a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesParameters.cs.cs b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesParameters.cs.cs index a304bf9..e940437 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesParameters.cs.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/InvocationDescriptionExtensionsTests.MatchesParameters.cs.cs @@ -149,4 +149,82 @@ public void MatchesParameters_InvocationWithArguments_And_MethodWithMoreOptional // Assert result.ShouldBeTrue(); } + + [TestMethod] + public void MatchesParameters_InvocationWithExtraArgumentsAndNoOptionalParameters_Should_NotMatch() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithExactArgumentsAndSomeOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithPartialArgumentsMatchingOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } + + [TestMethod] + public void MatchesParameters_InvocationWithAllArgumentsAndOptionalParameters_Should_Match() + { + // Assign + var method = new MethodDescription("void", "Method"); + method.Parameters.Add(new ParameterDescription("string", "param1")); + method.Parameters.Add(new ParameterDescription("int", "param2") { HasDefaultValue = true }); + method.Parameters.Add(new ParameterDescription("bool", "param3") { HasDefaultValue = true }); + + var invocation = new InvocationDescription("System.Object", "Method"); + invocation.Arguments.Add(new ArgumentDescription("string", "arg1")); + invocation.Arguments.Add(new ArgumentDescription("int", "arg2")); + invocation.Arguments.Add(new ArgumentDescription("bool", "arg3")); + + // Act + var result = invocation.MatchesParameters(method); + + // Assert + result.ShouldBeTrue(); + } } diff --git a/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs b/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs deleted file mode 100644 index 1284c38..0000000 --- a/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.EdgeCases.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace DendroDocs.Extensions.Tests; - -public partial class StringExtensionsTests -{ - [TestMethod] - public void ToSentenceCase_StringWithSpaces_Should_HandleCorrectly() - { - // Assign - var input = "Test Method"; - - // Act - var result = input.ToSentenceCase(); - - // Assert - result.ShouldBe("Test Method"); // Space before capital M - } - - [TestMethod] - public void ToSentenceCase_StringWithSpecialCharacters_Should_HandleCorrectly() - { - // Assign - var input = "Test_Method$Name"; - - // Act - var result = input.ToSentenceCase(); - - // Assert - result.ShouldBe("Test_ Method$ Name"); // Spaces before capital letters - } - - [TestMethod] - public void ToSentenceCase_SingleCharacter_Should_HandleCorrectly() - { - // Assign - var input = "a"; - - // Act - var result = input.ToSentenceCase(); - - // Assert - result.ShouldBe("A"); - } - - [TestMethod] - public void ToSentenceCase_SingleUpperCharacter_Should_HandleCorrectly() - { - // Assign - var input = "A"; - - // Act - var result = input.ToSentenceCase(); - - // Assert - result.ShouldBe("A"); - } - - [TestMethod] - public void GenericTypes_NonGenericType_Should_ReturnEmptyList() - { - // Assign - var input = "System.String"; - - // Act - var result = input.GenericTypes(); - - // Assert - result.ShouldBeEmpty(); - } - - [TestMethod] - public void IsGeneric_NonGenericTypeEndingWithGreaterThan_Should_ReturnFalse() - { - // Assign - var input = "SomeType>NotGeneric"; - - // Act - var result = input.IsGeneric(); - - // Assert - result.ShouldBeFalse(); - } - - [TestMethod] - public void IsGeneric_TypeWithAngleBracketsButNotAtEnd_Should_ReturnFalse() - { - // Assign - var input = "SomeNotAtEnd"; - - // Act - var result = input.IsGeneric(); - - // Assert - result.ShouldBeFalse(); - } - - [TestMethod] - public void ForDiagram_NonGenericSimpleType_Should_ReturnAsIs() - { - // Assign - var input = "String"; - - // Act - var result = input.ForDiagram(); - - // Assert - result.ShouldBe("String"); - } - - [TestMethod] - public void ForDiagram_TypeWithoutDots_Should_ReturnAsIs() - { - // Assign - var input = "SimpleType"; - - // Act - var result = input.ForDiagram(); - - // Assert - result.ShouldBe("SimpleType"); - } -} \ No newline at end of file diff --git a/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.cs b/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.cs index 26dfb72..ed187f8 100644 --- a/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.cs +++ b/tests/DendroDocs.Client.Tests/Extensions/StringExtensionsTests.cs @@ -120,4 +120,121 @@ public void ForDiagramStripNamespacesFromTypes(string input, string expectation) // Assert result.ShouldBe(expectation); } + + [TestMethod] + public void ToSentenceCase_StringWithSpaces_Should_HandleCorrectly() + { + // Assign + var input = "Test Method"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("Test Method"); // Space before capital M + } + + [TestMethod] + public void ToSentenceCase_StringWithSpecialCharacters_Should_HandleCorrectly() + { + // Assign + var input = "Test_Method$Name"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("Test_ Method$ Name"); // Spaces before capital letters + } + + [TestMethod] + public void ToSentenceCase_SingleCharacter_Should_HandleCorrectly() + { + // Assign + var input = "a"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("A"); + } + + [TestMethod] + public void ToSentenceCase_SingleUpperCharacter_Should_HandleCorrectly() + { + // Assign + var input = "A"; + + // Act + var result = input.ToSentenceCase(); + + // Assert + result.ShouldBe("A"); + } + + [TestMethod] + public void GenericTypes_NonGenericType_Should_ReturnEmptyList() + { + // Assign + var input = "System.String"; + + // Act + var result = input.GenericTypes(); + + // Assert + result.ShouldBeEmpty(); + } + + [TestMethod] + public void IsGeneric_NonGenericTypeEndingWithGreaterThan_Should_ReturnFalse() + { + // Assign + var input = "SomeType>NotGeneric"; + + // Act + var result = input.IsGeneric(); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void IsGeneric_TypeWithAngleBracketsButNotAtEnd_Should_ReturnFalse() + { + // Assign + var input = "SomeNotAtEnd"; + + // Act + var result = input.IsGeneric(); + + // Assert + result.ShouldBeFalse(); + } + + [TestMethod] + public void ForDiagram_NonGenericSimpleType_Should_ReturnAsIs() + { + // Assign + var input = "String"; + + // Act + var result = input.ForDiagram(); + + // Assert + result.ShouldBe("String"); + } + + [TestMethod] + public void ForDiagram_TypeWithoutDots_Should_ReturnAsIs() + { + // Assign + var input = "SimpleType"; + + // Act + var result = input.ForDiagram(); + + // Assert + result.ShouldBe("SimpleType"); + } }