Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about TUnitLogger #590

Closed
StefH opened this issue Sep 22, 2024 · 6 comments
Closed

Questions about TUnitLogger #590

StefH opened this issue Sep 22, 2024 · 6 comments

Comments

@StefH
Copy link

StefH commented Sep 22, 2024

1 TUnitLogger Context?

I want to redirect my own logger to the TUnitLogger instance.

This is the class:

public sealed class TUnitWireMockLogger : IWireMockLogger
{
    private readonly TUnitLogger _tUnitLogger;

    /// <summary>
    /// Create a new instance on the <see cref="TUnitWireMockLogger"/>.
    /// </summary>
    /// <param name="tUnitLogger">Represents a class which can be used to provide test output.</param>
    public TUnitWireMockLogger(TUnitLogger tUnitLogger)
    {
        _tUnitLogger = Guard.NotNull(tUnitLogger);
    }

    // . . .

Which is used like:

public class TUnitTests
{
    private IWireMockLogger _logger = null!;

    [Before(Test)]
    public void BeforeTest(TestContext context)
    {
        _logger = new TUnitWireMockLogger(context.GetDefaultLogger());
    }

    [Test]
    public async Task Test_TUnitWireMockLogger()
    {
        // . . .
    } 
}

Question:
Is this there a way to inject the TestContext in the [Test] instead of [Before(Test)]?

2 conflicts in SelfRegisteredExtensions?

I've created a new project WireMock.Net.TUnit.csproj which includes the TUnit NuGet.
And I've a test-project test\WireMock.Net.TUnitTests.csproj which also includes the TUnit NuGet.

When building I get the warning:

D:\a\WireMock.Net\WireMock.Net\test\WireMock.Net.TUnitTests\obj\Release\net8.0\TestPlatformEntryPoint.cs(13,9): warning CS0436: The type 'SelfRegisteredExtensions' in 'D:\a\WireMock.Net\WireMock.Net\test\WireMock.Net.TUnitTests\obj\Release\net8.0\AutoRegisteredExtensions.cs' conflicts with the imported type 'SelfRegisteredExtensions' in 'WireMock.Net.TUnit, Version=1.6.3.0, Culture=neutral, PublicKeyToken=c8d65537854e1f03'. Using the type defined in 'D:\a\WireMock.Net\WireMock.Net\test\WireMock.Net.TUnitTests\obj\Release\net8.0\AutoRegisteredExtensions.cs'. [D:\a\WireMock.Net\WireMock.Net\test\WireMock.Net.TUnitTests\WireMock.Net.TUnitTests.csproj]

Is this defined behavior?

Note that xUnit has a NuGet xUnit.abstractions which includes the ITestOutputHelper which is similar to TUnitLogger.

@thomhurst
Copy link
Owner

Is this there a way to inject the TestContext in the [Test] instead of [Before(Test)]?

You can grab it statically: TestContext.Current

2 conflicts in SelfRegisteredExtensions?

Yeah this happens if you use the TUnit package in a library project, and reference that in your test project.
The plan is for library projects to reference TUnit.Core only - Similar to xUnit.abstractions - But it's not ready yet. I'm going to try to get that working in the next week or so hopefully.

@thomhurst
Copy link
Owner

Does that solve everything for you for now @StefH ?

@StefH
Copy link
Author

StefH commented Sep 22, 2024

Yes. Thanks for the explanation.
I'll close this now.

Maybe tag me here once the refactoring related to TUnit.Core is done.

@StefH StefH closed this as completed Sep 22, 2024
@thomhurst
Copy link
Owner

Yes. Thanks for the explanation. I'll close this now.

Maybe tag me here once the refactoring related to TUnit.Core is done.

I've just pushed out v0.1.807.

It should allow you to use TUnit.Core in your library projects.

Let me know if you still run into problems!

@StefH
Copy link
Author

StefH commented Sep 23, 2024

It works.

But I have another question ;-)

Any plans to strong name this library?

CSC : warning CS8002: Referenced assembly 'TUnit.Core, Version=0.1.807.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.

@thomhurst
Copy link
Owner

It's on the to-do list: #520

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

No branches or pull requests

2 participants