Skip to content

Commit 6b8b062

Browse files
FredrikAugustKpaubert
authored andcommittedMar 5, 2021
Migrate from NUnit to xUnit
1 parent 8f06d0f commit 6b8b062

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed
 

‎Backend.sln

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backend", "Backend.csproj", "{07A4DC6F-5677-4088-8095-6048D06A0934}"
44
EndProject
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackendTests", "BackendTests\BackendTests.csproj", "{5D584475-4CD1-4FE6-98AB-D44429403B5C}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackendTests", "BackendTests\BackendTests.csproj", "{4CCDDE27-DDF4-4F6C-9689-C300F362EF9A}"
66
EndProject
77
Global
88
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -14,9 +14,9 @@ Global
1414
{07A4DC6F-5677-4088-8095-6048D06A0934}.Debug|Any CPU.Build.0 = Debug|Any CPU
1515
{07A4DC6F-5677-4088-8095-6048D06A0934}.Release|Any CPU.ActiveCfg = Release|Any CPU
1616
{07A4DC6F-5677-4088-8095-6048D06A0934}.Release|Any CPU.Build.0 = Release|Any CPU
17-
{5D584475-4CD1-4FE6-98AB-D44429403B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18-
{5D584475-4CD1-4FE6-98AB-D44429403B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
19-
{5D584475-4CD1-4FE6-98AB-D44429403B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
20-
{5D584475-4CD1-4FE6-98AB-D44429403B5C}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{4CCDDE27-DDF4-4F6C-9689-C300F362EF9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{4CCDDE27-DDF4-4F6C-9689-C300F362EF9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{4CCDDE27-DDF4-4F6C-9689-C300F362EF9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{4CCDDE27-DDF4-4F6C-9689-C300F362EF9A}.Release|Any CPU.Build.0 = Release|Any CPU
2121
EndGlobalSection
2222
EndGlobal

‎BackendTests/BackendTests.csproj

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Bogus" Version="33.0.2" />
11-
<PackageReference Include="NUnit" Version="3.13.1" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="1.3.0">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
1420
</ItemGroup>
1521

1622
<ItemGroup>

‎BackendTests/UnitTests/MetAPITests.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Backend.Mocks.MetAPI;
44
using Backend.Models.MetAPI.POCO;
55
using Backend.utils;
6-
using NUnit.Framework;
6+
using Xunit;
77

88
namespace BackendTests.UnitTests
99
{
@@ -15,30 +15,29 @@ public class MetAPITests
1515
private float _lon;
1616
private Random _random;
1717

18-
[SetUp]
19-
public void Setup()
18+
public MetAPITests()
2019
{
2120
_random = new Random();
2221
_lon = (float) _random.NextDouble() * (63.433f - 63.42f) + 63.42f;
2322
_lat = (float) _random.NextDouble() * (10.4f - 10.38f) + 10.38f;
2423
_forecast = Compact.GenerateSampleForecast(_lon, _lat);
2524
}
2625

27-
[Test]
26+
[Fact]
2827
public void MetAPIShouldReturnData()
2928
{
3029
Assert.NotNull(_forecast);
3130
}
3231

33-
[Test]
32+
[Fact]
3433
public void MetAPIShouldReturnCorrectCoordinates()
3534
{
36-
Assert.That("Feature", Is.EqualTo(_forecast.Type).NoClip);
37-
Assert.That(_lon, Is.EqualTo(_forecast.ForecastGeometry.Coordinates[0]).Within(0.0001).Percent);
38-
Assert.That(_lat, Is.EqualTo(_forecast.ForecastGeometry.Coordinates[1]).Within(0.0001).Percent);
35+
Assert.Equal("Feature", _forecast.Type);
36+
Assert.Equal(_lon, _forecast.ForecastGeometry.Coordinates[0], 3);
37+
Assert.Equal(_lat, _forecast.ForecastGeometry.Coordinates[1], 3);
3938
}
4039

41-
[Test]
40+
[Fact]
4241
public void MetAPIShouldReturnCorrectSymbolCode()
4342
{
4443
Assert.Contains(_forecast.ForecastProperties.Timeseries[0].ForecastData.Next1Hours.Summary.SymbolCode,

‎BackendTests/UnitTests/PopulationInNorwayTests.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,52 @@
22
using Backend.Mocks.SSB;
33
using Backend.Models.SSB.POCO;
44
using Backend.utils;
5-
using NUnit.Framework;
5+
using Xunit;
66

77
namespace BackendTests.UnitTests
88
{
99
public class PopulationInNorwayTests
1010
{
11-
private Random _r;
11+
private readonly Random _r;
1212
private readonly int _numMunicipalities = NorwayTools.MunicipalityCodeToIndex.Count;
1313
private readonly int _numYears = NorwayTools.YearToIndex.Count;
14-
private PopulationPerMunicipalityNorway _population;
14+
private readonly PopulationPerMunicipalityNorway _population;
1515

16-
[SetUp]
17-
public void Setup()
16+
public PopulationInNorwayTests()
1817
{
1918
_r = new Random();
2019
_population = MockPopulationInNorway.GenerateSamplePopulationsInNorway();
2120
}
2221

23-
[Test]
22+
[Fact]
2423
public void PopulationInNorwayAPIShouldReturnData()
2524
{
2625
Assert.NotNull(_population);
2726
}
2827

29-
[Test]
28+
[Fact]
3029
public void PopulationInNorwayShouldIncreasePerMunicipality()
3130
{
3231
var randomSample = _r.Next(_numMunicipalities, _population.Dataset.Value.Count - 1);
3332
var currYearPopulation = _population.Dataset.Value[randomSample];
3433
var prevYearPopulation = _population.Dataset.Value[randomSample - _numMunicipalities];
35-
Assert.Greater(currYearPopulation, prevYearPopulation);
36-
Assert.That(currYearPopulation - prevYearPopulation <= 500);
37-
Assert.That(currYearPopulation - prevYearPopulation >= 1);
34+
35+
Assert.True(currYearPopulation > prevYearPopulation);
36+
Assert.True(currYearPopulation - prevYearPopulation <= 500);
37+
Assert.True(currYearPopulation - prevYearPopulation >= 1);
3838
}
3939

40-
[Test]
40+
[Fact]
4141
public void PopulationInNorwayCorrectLabelAndSource()
4242
{
43-
Assert.AreEqual("07459: Befolkning, etter region, år og statistikkvariabel", _population.Dataset.Label);
44-
Assert.AreEqual("Statistisk sentralbyrå", _population.Dataset.Source);
43+
Assert.Equal("07459: Befolkning, etter region, år og statistikkvariabel", _population.Dataset.Label);
44+
Assert.Equal("Statistisk sentralbyrå", _population.Dataset.Source);
4545
}
4646

47-
[Test]
47+
[Fact]
4848
public void PopulationInNorwayGeneratesCorrectAmountOfData()
4949
{
50-
Assert.AreEqual(_numMunicipalities * _numYears, _population.Dataset.Value.Count);
50+
Assert.Equal(_numMunicipalities * _numYears, _population.Dataset.Value.Count);
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)