Skip to content

Commit e3a98f9

Browse files
authored
Merge pull request #94 from Umplify/issue_93
Made the necessary amendments in the code per issue #93
2 parents 2dc6c00 + 893eac1 commit e3a98f9

21 files changed

+464
-380
lines changed

azure-pipeline-PR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ steps:
1717
displayName: 'Use .NET 6.0 sdk'
1818
inputs:
1919
packageType: sdk
20-
version: 6.0.100
20+
version: 6.0.101
2121
installationPath: $(Agent.ToolsDirectory)/dotnet
2222
- script: echo Started restoring the source code
2323
- task: DotNetCoreCLI@2

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ steps:
1919
displayName: 'Use .NET 6.0 sdk'
2020
inputs:
2121
packageType: sdk
22-
version: 6.0.100
22+
version: 6.0.101
2323
installationPath: $(Agent.ToolsDirectory)/dotnet
2424
- script: echo Started restoring the source code
2525
- task: DotNetCoreCLI@2
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
using Microsoft.Extensions.Configuration;
22
using Microsoft.Extensions.DependencyInjection;
3+
using System.Collections.Generic;
34
using System.Threading.Tasks;
45
using Xunit.Microsoft.DependencyInjection.Abstracts;
56
using Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
67

7-
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures
8+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;
9+
10+
public class TestFixture : TestBedFixture
811
{
9-
public class TestFixture : TestBedFixture
10-
{
11-
protected override void AddServices(IServiceCollection services, IConfiguration configuration)
12-
=> services
13-
.AddTransient<ICalculator, Calculator>()
14-
.Configure<Options>(config => configuration.GetSection("Options").Bind(config));
12+
protected override void AddServices(IServiceCollection services, IConfiguration? configuration)
13+
=> services
14+
.AddTransient<ICalculator, Calculator>()
15+
.Configure<Options>(config => configuration?.GetSection("Options").Bind(config));
1516

16-
protected override ValueTask DisposeAsyncCore()
17-
=> new();
17+
protected override ValueTask DisposeAsyncCore()
18+
=> new();
1819

19-
protected override string GetConfigurationFile()
20-
=> "appsettings.json";
20+
protected override IEnumerable<string> GetConfigurationFiles()
21+
{
22+
yield return "appsettings.json";
2123
}
2224
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
global using Microsoft.Extensions.Configuration;
2+
global using Microsoft.Extensions.DependencyInjection;
3+
global using System.Collections.Generic;
4+
global using System.Threading.Tasks;
5+
global using Xunit.Abstractions;
6+
global using Xunit.Microsoft.DependencyInjection.Abstracts;
7+
global using Xunit.Microsoft.DependencyInjection.Attributes;
8+
global using Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;
9+
global using Xunit.Microsoft.DependencyInjection.ExampleTests.Services;

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/IntegrationTests.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Microsoft.Extensions.Options;
2-
using System.Threading.Tasks;
3-
using Xunit.Abstractions;
4-
using Xunit.Microsoft.DependencyInjection.Abstracts;
5-
using Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;
6-
using Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
72
using Options = Xunit.Microsoft.DependencyInjection.ExampleTests.Services.Options;
83

94
namespace Xunit.Microsoft.DependencyInjection.ExampleTests
@@ -21,8 +16,8 @@ public void Test1(int x, int y)
2116
{
2217
var calculator = _fixture.GetService<ICalculator>(_testOutputHelper);
2318
var option = _fixture.GetService<IOptions<Options>>(_testOutputHelper);
24-
var calculated = calculator.Add(x, y);
25-
var expected = option.Value.Rate * (x + y);
19+
var calculated = calculator?.Add(x, y);
20+
var expected = option?.Value.Rate * (x + y);
2621
Assert.True(expected == calculated);
2722
}
2823

@@ -32,8 +27,8 @@ public void Test2(int x, int y)
3227
{
3328
var calculator = _fixture.GetScopedService<ICalculator>(_testOutputHelper);
3429
var option = _fixture.GetScopedService<IOptions<Options>>(_testOutputHelper);
35-
var calculated = calculator.Add(x, y);
36-
var expected = option.Value.Rate * (x + y);
30+
var calculated = calculator?.Add(x, y);
31+
var expected = option?.Value.Rate * (x + y);
3732
Assert.True(expected == calculated);
3833
}
3934

@@ -42,6 +37,6 @@ protected override void Clear()
4237
}
4338

4439
protected override ValueTask DisposeAsyncCore()
45-
=> new ValueTask();
40+
=> new();
4641
}
4742
}
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
using Microsoft.Extensions.Options;
22

3-
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services
3+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
4+
5+
public class Calculator : ICalculator
46
{
5-
public class Calculator : ICalculator
6-
{
7-
private readonly Options _option;
7+
private readonly Options _option;
88

9-
public Calculator(IOptions<Options> option)
10-
=> _option = option.Value;
9+
public Calculator(IOptions<Options> option)
10+
=> _option = option.Value;
1111

12-
public int Add(int x, int y)
13-
=> (x + y) * _option.Rate;
14-
}
12+
public int Add(int x, int y)
13+
=> (x + y) * _option.Rate;
1514
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services
1+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
2+
3+
public interface ICalculator
24
{
3-
public interface ICalculator
4-
{
5-
int Add(int x, int y);
6-
}
5+
int Add(int x, int y);
76
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services
1+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Services;
2+
3+
public class Options
24
{
3-
public class Options
4-
{
5-
public int Rate { get; set; }
6-
}
5+
public int Rate { get; set; }
76
}
Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
using System.Threading.Tasks;
2-
using Xunit.Microsoft.DependencyInjection.Attributes;
3-
4-
namespace Xunit.Microsoft.DependencyInjection.ExampleTests
5-
{
6-
[TestCaseOrderer("Xunit.Microsoft.DependencyInjection.TestsOrder.TestPriorityOrderer", "Xunit.Microsoft.DependencyInjection")]
7-
public class UnitTests
8-
{
9-
[Fact, TestOrder(1)]
10-
public void Test1()
11-
=> Assert.True(1 == 1);
1+
namespace Xunit.Microsoft.DependencyInjection.ExampleTests;
122

13-
[Fact, TestOrder(2)]
14-
public void Test2()
15-
=> Assert.False(1 == 0);
3+
[TestCaseOrderer("Xunit.Microsoft.DependencyInjection.TestsOrder.TestPriorityOrderer", "Xunit.Microsoft.DependencyInjection")]
4+
public class UnitTests
5+
{
6+
[Fact, TestOrder(1)]
7+
public void Test1()
8+
=> Assert.True(1 == 1);
169

17-
[Fact, TestOrder(3)]
18-
public async Task Test3()
19-
{
20-
await Task.Delay(3000);
21-
Assert.True(1 == 1);
22-
}
10+
[Fact, TestOrder(2)]
11+
public void Test2()
12+
=> Assert.False(1 == 0);
2313

24-
[Fact, TestOrder(4)]
25-
public async Task Test4()
26-
{
27-
await Task.Delay(5000);
28-
Assert.True(1 > 0);
29-
}
14+
[Fact, TestOrder(3)]
15+
public async Task Test3()
16+
{
17+
await Task.Delay(3000);
18+
Assert.True(1 == 1);
19+
}
20+
21+
[Fact, TestOrder(4)]
22+
public async Task Test4()
23+
{
24+
await Task.Delay(5000);
25+
Assert.True(1 > 0);
3026
}
3127
}
Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<LangVersion>10.0</LangVersion>
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
<IsPackable>false</IsPackable>
7+
<Nullable>enable</Nullable>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
</PropertyGroup>
810

9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
11-
<PackageReference Include="xunit" Version="2.4.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
13-
<PackageReference Include="coverlet.collector" Version="3.1.0" />
14-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
15-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
16-
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
20-
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
21-
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
15+
<PackageReference Include="coverlet.collector" Version="3.1.0" />
16+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
22+
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
23+
</ItemGroup>
2224

23-
<ItemGroup>
24-
<Folder Include="Fixtures\" />
25-
<Folder Include="Services\" />
26-
</ItemGroup>
27-
<ItemGroup>
28-
<None Remove="appsettings.json" />
29-
</ItemGroup>
30-
<ItemGroup>
31-
<Content Include="appsettings.json">
32-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33-
</Content>
34-
</ItemGroup>
35-
<ItemGroup>
36-
<ProjectReference Include="..\..\src\Xunit.Microsoft.DependencyInjection.csproj" />
37-
</ItemGroup>
25+
<ItemGroup>
26+
<Folder Include="Fixtures\" />
27+
<Folder Include="Services\" />
28+
</ItemGroup>
29+
<ItemGroup>
30+
<None Remove="appsettings.json" />
31+
</ItemGroup>
32+
<ItemGroup>
33+
<Content Include="appsettings.json">
34+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
35+
</Content>
36+
</ItemGroup>
37+
<ItemGroup>
38+
<ProjectReference Include="..\..\src\Xunit.Microsoft.DependencyInjection.csproj" />
39+
</ItemGroup>
3840
</Project>

0 commit comments

Comments
 (0)