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
Expand Up @@ -3,13 +3,10 @@

namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;

public class Calculator : ICalculator
public class Calculator(ILogger<Calculator> logger, IOptions<Options> option) : ICalculator
{
private readonly Options _option;
private readonly ILogger<Calculator> _logger;

public Calculator(ILogger<Calculator> logger, IOptions<Options> option)
=> (_logger, _option) = (logger, option.Value);
private readonly Options _option = option.Value;
private readonly ILogger<Calculator> _logger = logger;

public Task<int> AddAsync(int x, int y)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Fixtures\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 3 additions & 6 deletions src/Abstracts/TestBed.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
namespace Xunit.Microsoft.DependencyInjection.Abstracts;

public class TestBed<TFixture> : IDisposable, IClassFixture<TFixture>, IAsyncDisposable
public class TestBed<TFixture>(ITestOutputHelper testOutputHelper, TFixture fixture) : IDisposable, IClassFixture<TFixture>, IAsyncDisposable
where TFixture : class
{
protected readonly ITestOutputHelper _testOutputHelper;
protected readonly TFixture _fixture;
protected readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
protected readonly TFixture _fixture = fixture;
private bool _disposedValue;
private bool _disposedAsync;

public TestBed(ITestOutputHelper testOutputHelper, TFixture fixture)
=> (_testOutputHelper, _fixture) = (testOutputHelper, fixture);

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
Expand Down
7 changes: 2 additions & 5 deletions src/Attributes/TestOrderAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
namespace Xunit.Microsoft.DependencyInjection.Attributes;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class TestOrderAttribute : Attribute
public class TestOrderAttribute(int priority) : Attribute
{
public TestOrderAttribute(int priority)
=> Priority = priority;

public int Priority { get; }
public int Priority { get; } = priority;
}
12 changes: 3 additions & 9 deletions src/Logging/OutputLogger.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
namespace Xunit.Microsoft.DependencyInjection.Logging;

public class OutputLogger : ILogger
public class OutputLogger(string categoryName, ITestOutputHelper testOutputHelper) : ILogger
{
private readonly ITestOutputHelper _testOutputHelper;
private readonly string _categoryName;
private readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
private readonly string _categoryName = categoryName;

public OutputLogger(ITestOutputHelper testOutputHelper)
: this("Tests", testOutputHelper)
{
}

public OutputLogger(string categoryName, ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
_categoryName = categoryName;
}

public IDisposable? BeginScope<TState>(TState state) where TState : notnull
=> new NoOpDisposable();

Expand Down
7 changes: 2 additions & 5 deletions src/Logging/OutputLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
namespace Xunit.Microsoft.DependencyInjection.Logging;

public class OutputLoggerProvider : ILoggerProvider
public class OutputLoggerProvider(ITestOutputHelper testOutputHelper) : ILoggerProvider
{
private readonly ITestOutputHelper _testOutputHelper;

public OutputLoggerProvider(ITestOutputHelper testOutputHelper)
=> _testOutputHelper = testOutputHelper;
private readonly ITestOutputHelper _testOutputHelper = testOutputHelper;

public ILogger CreateLogger(string categoryName)
=> new OutputLogger(categoryName, _testOutputHelper);
Expand Down