Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

Please check the following before creating a Pull Request

  • If this is a new feature or piece of functionality, have you started a discussion and gotten agreement on it?
  • If it fixes a bug or problem, is there an issue to track it? If not, create one first and link it please so there's clear visibility.
  • Did you write tests to ensure you code works properly?

Fixes #3884

Description

The property injection docs showed MethodDataSource returning IEnumerable<string>, which triggers TUnit0001 error. For property injection, the method must return the property's type directly—not an enumerable.

Before (incorrect):

[MethodDataSource(nameof(GetMethodData))]
public required string Property2 { get; init; }

public static IEnumerable<string> GetMethodData()
{
    yield return "method_data_1";
    yield return "method_data_2";
}

After (matches TUnit.TestProject/PropertySetterTests.cs):

[MethodDataSource(nameof(GetMethodData))]
public required string Property2 { get; init; }

public static string GetMethodData() => "method_data_value";
Original prompt

This section details on the original issue you should resolve

<issue_title>[Doc] Basic Property Injection Examples TUnit0001 Error</issue_title>
<issue_description>The code in https://tunit.dev/docs/test-lifecycle/property-injection#basic-property-injection-examples got an error in the version 1.2.11.

I Got the error TUnit0001: Attribute argument types 'System.Collections.Generic.IEnumerable<string>' don't match method parameter types 'string' in the line [MethodDataSource(nameof(GetMethodData))]

However in the code about this feature, is like this in the github:

[MethodDataSource(nameof(MethodData))]
public required string Property2 { get; init; }

public static string MethodData() => "2";

Could you please update the document?

BTW, can we get the feature like the document?</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update documentation for basic property injection examples Fix MethodDataSource example in property injection documentation Nov 29, 2025
Copilot AI requested a review from thomhurst November 29, 2025 21:36
@thomhurst thomhurst marked this pull request as ready for review November 29, 2025 21:45
@thomhurst thomhurst merged commit a233324 into main Nov 29, 2025
5 checks passed
@thomhurst thomhurst deleted the copilot/update-basic-property-injection-docs branch November 29, 2025 21:45
This was referenced Dec 1, 2025
This was referenced Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Doc] Basic Property Injection Examples TUnit0001 Error

2 participants