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..8e293f2 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.First.cs @@ -0,0 +1,84 @@ +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(); + } + + [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 new file mode 100644 index 0000000..a46c00f --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.FirstOrDefault.cs @@ -0,0 +1,83 @@ +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(); + } + + [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.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..f3980c1 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.GetInvokedMethod.cs @@ -0,0 +1,137 @@ +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(); + } + + [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 new file mode 100644 index 0000000..04dde29 --- /dev/null +++ b/tests/DendroDocs.Client.Tests/Extensions/IEnumerableTypeDescriptionExtensionsTests.TraverseStatement.cs @@ -0,0 +1,199 @@ +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(); + } + + [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 + { + // This represents any statement type not handled by TraverseStatement + } +} \ 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.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"); + } }