mcilspy/tests/fixtures/TestAssembly.cs
Ryan Malloy 70c4a4a39a test: comprehensive test suite for mcilspy MCP server
Add complete test coverage for the mcilspy package:

- T7: Create TestAssembly.dll fixture with known types/members
- T1: Integration tests using real assembly (metadata reader + ILSpy wrapper)
- T2: MCP tool tests with mocked wrapper for each @mcp.tool()
- T3: Error path tests for regex, file not found, invalid assemblies
- T4: Concurrency tests with asyncio.gather() for parallel operations
- T5: Docstring coverage tests using AST introspection
- T6: Timeout behavior tests for 5-minute subprocess timeout

Test summary:
- 147 tests passing
- 14 skipped (ilspycmd-dependent integration tests)
- 73% code coverage
- All ruff linting checks pass
2026-02-08 11:40:57 -07:00

215 lines
5.0 KiB
C#

using System;
using System.Threading.Tasks;
namespace TestNamespace
{
/// <summary>
/// A test class with various members for testing the mcilspy MCP server.
/// </summary>
public class TestClass
{
// Constants for testing string search
public const string API_KEY = "test-secret-key";
public const string BASE_URL = "https://api.example.com";
public const int MAX_RETRIES = 3;
// Fields
public static readonly string BaseUrl = "https://api.example.com";
private int _privateField;
protected string _protectedField;
internal double _internalField;
// Properties
public string Name { get; set; }
public int Age { get; private set; }
public virtual bool IsActive { get; set; }
// Events
public event EventHandler OnChange;
public event EventHandler<string> OnMessage;
// Constructors
public TestClass()
{
Name = "Default";
Age = 0;
}
public TestClass(string name, int age)
{
Name = name;
Age = age;
}
// Methods
public void DoSomething()
{
Console.WriteLine("Hello from DoSomething");
OnChange?.Invoke(this, EventArgs.Empty);
}
public string GetGreeting()
{
return $"Hello, {Name}!";
}
public static int Add(int a, int b)
{
return a + b;
}
protected virtual void OnPropertyChanged(string propertyName)
{
OnMessage?.Invoke(this, propertyName);
}
private void PrivateMethod()
{
_privateField = 42;
}
}
/// <summary>
/// Interface for testing interface discovery.
/// </summary>
public interface ITestService
{
void Execute();
Task<string> ExecuteAsync();
string ServiceName { get; }
}
/// <summary>
/// Another interface for inheritance testing.
/// </summary>
public interface IConfigurable
{
void Configure(string settings);
}
/// <summary>
/// Struct for testing struct discovery.
/// </summary>
public struct TestStruct
{
public int Value;
public string Label;
public TestStruct(int value, string label)
{
Value = value;
Label = label;
}
public override string ToString() => $"{Label}: {Value}";
}
/// <summary>
/// Enum for testing enum discovery.
/// </summary>
public enum TestEnum
{
None = 0,
First = 1,
Second = 2,
Third = 3
}
/// <summary>
/// Delegate for testing delegate discovery.
/// </summary>
public delegate void TestDelegate(string message);
/// <summary>
/// Delegate with return type.
/// </summary>
public delegate bool ValidationDelegate<T>(T value);
/// <summary>
/// Service implementation for testing class relationships.
/// </summary>
public class TestServiceImpl : ITestService, IConfigurable
{
private string _config;
public string ServiceName => "TestService";
public void Execute()
{
Console.WriteLine($"Executing with config: {_config}");
}
public Task<string> ExecuteAsync()
{
return Task.FromResult($"Async result from {ServiceName}");
}
public void Configure(string settings)
{
_config = settings;
}
}
/// <summary>
/// Nested class for testing nested type discovery.
/// </summary>
public class OuterClass
{
public class NestedClass
{
public string Value { get; set; }
}
private class PrivateNestedClass
{
public int Secret { get; set; }
}
public NestedClass CreateNested() => new NestedClass();
}
/// <summary>
/// Abstract class for testing abstract type discovery.
/// </summary>
public abstract class AbstractBase
{
public abstract void AbstractMethod();
public virtual void VirtualMethod() { }
protected string BaseProperty { get; set; }
}
/// <summary>
/// Derived class for testing inheritance.
/// </summary>
public class DerivedClass : AbstractBase
{
public override void AbstractMethod()
{
Console.WriteLine("Implemented abstract method");
}
public override void VirtualMethod()
{
base.VirtualMethod();
Console.WriteLine("Overridden virtual method");
}
}
}
namespace TestNamespace.SubNamespace
{
/// <summary>
/// Class in a sub-namespace for testing namespace filtering.
/// </summary>
public class SubClass
{
public const string CONNECTION_STRING = "Server=localhost;Database=test";
public void SubMethod()
{
Console.WriteLine("Sub namespace method");
}
}
}