Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
namespace DendroDocs.Extensions.Tests;

[TestClass]
public partial class IEnumerableTypeDescriptionExtensionsTests
{
[TestMethod]
public void First_NullTypes_Should_Throw()
{
// Assign
IEnumerable<TypeDescription> types = default!;

// Act
Action action = () => types.First("System.Object");

// Assert
action.ShouldThrow<ArgumentNullException>()
.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<InvalidOperationException>();
}

[TestMethod]
public void First_EmptyCollection_Should_Throw()
{
// Assign
var types = Array.Empty<TypeDescription>();

// Act
Action action = () => types.First("TestType");

// Assert
action.ShouldThrow<InvalidOperationException>();
}

[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<InvalidOperationException>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace DendroDocs.Extensions.Tests;

public partial class IEnumerableTypeDescriptionExtensionsTests
{
[TestMethod]
public void FirstOrDefault_NullTypes_Should_Throw()
{
// Assign
IEnumerable<TypeDescription> types = default!;

// Act
Action action = () => types.FirstOrDefault("System.Object");

// Assert
action.ShouldThrow<ArgumentNullException>()
.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<TypeDescription>();

// 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
namespace DendroDocs.Extensions.Tests;

public partial class IEnumerableTypeDescriptionExtensionsTests
{
[TestMethod]
public void GetInvocationConsequenceStatements_NullTypes_Should_Throw()
{
// Assign
IEnumerable<TypeDescription> types = default!;
var invocation = new InvocationDescription("TestType", "TestMethod");

// Act
Action action = () => types.GetInvocationConsequenceStatements(invocation);

// Assert
action.ShouldThrow<ArgumentNullException>()
.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<If>().ShouldHaveSingleItem();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace DendroDocs.Extensions.Tests;

public partial class IEnumerableTypeDescriptionExtensionsTests
{
[TestMethod]
public void GetInvocationConsequences_NullTypes_Should_Throw()
{
// Assign
IEnumerable<TypeDescription> types = default!;
var invocation = new InvocationDescription("TestType", "TestMethod");

// Act
Action action = () => types.GetInvocationConsequences(invocation);

// Assert
action.ShouldThrow<ArgumentNullException>()
.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);
}
}
Loading