Skip to content

Commit 3a0689a

Browse files
committed
#222 Adopted primary constructors
1 parent 4245560 commit 3a0689a

File tree

9 files changed

+24
-45
lines changed

9 files changed

+24
-45
lines changed

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Fixtures/RemoteCalculatorFixture.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class RemoteCalculatorFixture : TestBedFixture
66
{
77
public WebApplicationFactory<Program> Factory { get; }
88

9-
public RemoteCalculatorFixture(IMessageSink messageSink)
9+
public RemoteCalculatorFixture()
1010
{
1111
Factory = new WebApplicationFactory<Program>();
1212
}
@@ -25,11 +25,3 @@ protected override IEnumerable<TestAppSettings> GetTestAppSettings()
2525
yield return new() { Filename = "appsettings.json", IsOptional = false };
2626
}
2727
}
28-
29-
public class StaticClientFactory(HttpClient client) : IHttpClientFactory
30-
{
31-
public HttpClient CreateClient(string name)
32-
{
33-
return client;
34-
}
35-
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;
2+
3+
public class StaticClientFactory(HttpClient client) : IHttpClientFactory
4+
{
5+
public HttpClient CreateClient(string name)
6+
{
7+
return client;
8+
}
9+
}

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Services/Calculator.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
55

6-
public class Calculator : ICalculator
6+
public class Calculator(ILogger<Calculator> logger, IOptions<Options> option) : ICalculator
77
{
8-
private readonly Options _option;
9-
private readonly ILogger<Calculator> _logger;
10-
11-
public Calculator(ILogger<Calculator> logger, IOptions<Options> option)
12-
=> (_logger, _option) = (logger, option.Value);
8+
private readonly Options _option = option.Value;
9+
private readonly ILogger<Calculator> _logger = logger;
1310

1411
public Task<int> AddAsync(int x, int y)
1512
{

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Services/RemoteCalculator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
88

9-
public class RemoteCalculator(
10-
ILogger<Calculator> logger,
11-
IOptions<Options> option,
12-
IHttpClientFactory factory) : ICalculator
9+
public class RemoteCalculator(ILogger<Calculator> logger, IOptions<Options> option, IHttpClientFactory factory) : ICalculator
1310
{
1411
private readonly Options _option = option.Value;
1512

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<Folder Include="Fixtures\" />
3130
<Folder Include="Services\" />
3231
</ItemGroup>
3332
<ItemGroup>

src/Abstracts/TestBed.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
namespace Xunit.Microsoft.DependencyInjection.Abstracts;
22

3-
public class TestBed<TFixture> : IDisposable, IClassFixture<TFixture>, IAsyncDisposable
3+
public class TestBed<TFixture>(ITestOutputHelper testOutputHelper, TFixture fixture) : IDisposable, IClassFixture<TFixture>, IAsyncDisposable
44
where TFixture : class
55
{
6-
protected readonly ITestOutputHelper _testOutputHelper;
7-
protected readonly TFixture _fixture;
6+
protected readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
7+
protected readonly TFixture _fixture = fixture;
88
private bool _disposedValue;
99
private bool _disposedAsync;
1010

11-
public TestBed(ITestOutputHelper testOutputHelper, TFixture fixture)
12-
=> (_testOutputHelper, _fixture) = (testOutputHelper, fixture);
13-
1411
protected virtual void Dispose(bool disposing)
1512
{
1613
if (!_disposedValue)
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
namespace Xunit.Microsoft.DependencyInjection.Attributes;
22

33
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
4-
public class TestOrderAttribute : Attribute
4+
public class TestOrderAttribute(int priority) : Attribute
55
{
6-
public TestOrderAttribute(int priority)
7-
=> Priority = priority;
8-
9-
public int Priority { get; }
6+
public int Priority { get; } = priority;
107
}

src/Logging/OutputLogger.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
namespace Xunit.Microsoft.DependencyInjection.Logging;
22

3-
public class OutputLogger : ILogger
3+
public class OutputLogger(string categoryName, ITestOutputHelper testOutputHelper) : ILogger
44
{
5-
private readonly ITestOutputHelper _testOutputHelper;
6-
private readonly string _categoryName;
5+
private readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
6+
private readonly string _categoryName = categoryName;
77

88
public OutputLogger(ITestOutputHelper testOutputHelper)
99
: this("Tests", testOutputHelper)
1010
{
1111
}
1212

13-
public OutputLogger(string categoryName, ITestOutputHelper testOutputHelper)
14-
{
15-
_testOutputHelper = testOutputHelper;
16-
_categoryName = categoryName;
17-
}
18-
1913
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
2014
=> new NoOpDisposable();
2115

src/Logging/OutputLoggerProvider.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
namespace Xunit.Microsoft.DependencyInjection.Logging;
22

3-
public class OutputLoggerProvider : ILoggerProvider
3+
public class OutputLoggerProvider(ITestOutputHelper testOutputHelper) : ILoggerProvider
44
{
5-
private readonly ITestOutputHelper _testOutputHelper;
6-
7-
public OutputLoggerProvider(ITestOutputHelper testOutputHelper)
8-
=> _testOutputHelper = testOutputHelper;
5+
private readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
96

107
public ILogger CreateLogger(string categoryName)
118
=> new OutputLogger(categoryName, _testOutputHelper);

0 commit comments

Comments
 (0)