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

Replace Nunit with xUnit #801

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f086708
Updated Nunit packages and fixed breaking changes
asos-gurpreetsingh Aug 8, 2024
f05f136
migrate to xunit
asos-gurpreetsingh Aug 9, 2024
c70d8c4
fix working path for dotnet restore
asos-gurpreetsingh Aug 9, 2024
8a06267
use release version as environment variable
asos-gurpreetsingh Aug 9, 2024
16d626c
use default value for release version on feature branch
asos-gurpreetsingh Aug 9, 2024
10cae54
add input to workflow dispatch
asos-gurpreetsingh Aug 9, 2024
80c4010
use latest system.resources package
asos-gurpreetsingh Aug 9, 2024
ff42779
resolve some of the pending todo tasks
asos-gurpreetsingh Aug 9, 2024
b2c0aee
Revert "resolve some of the pending todo tasks"
asos-gurpreetsingh Aug 12, 2024
9108f85
revert changes not related to xunit migration
asos-gurpreetsingh Aug 12, 2024
e71d41c
add GenerateResourceUsePreserializedResources to allow dotnet build
asos-gurpreetsingh Aug 12, 2024
6ddc8d8
make setup private
asos-gurpreetsingh Aug 13, 2024
fe0d1e9
fix build versions on assembly
asos-gurpreetsingh Aug 13, 2024
063406c
Add input description
asos-gurpreetsingh Aug 13, 2024
518104a
add missing build parameter
asos-gurpreetsingh Aug 13, 2024
b2e2e7f
Update src/ServiceBusExplorer.Tests/ServiceBusExplorer.Tests.csproj
asos-gurpreetsingh Aug 15, 2024
b58e26a
Update src/ServiceBusExplorer.Tests/ServiceBusExplorer.Tests.csproj
asos-gurpreetsingh Aug 15, 2024
7584126
set file version and build version on assemblies
asos-gurpreetsingh Sep 21, 2024
fa10234
Merge branch 'feature/upgrade-nunit' of https://github.com/asos-gurpr…
asos-gurpreetsingh Sep 21, 2024
e069ffe
file broken file after merge
asos-gurpreetsingh Sep 21, 2024
1b799c5
run tests with existing build output
asos-gurpreetsingh Sep 21, 2024
1c323ba
fix version test
asos-gurpreetsingh Sep 21, 2024
bac86ff
split tests to files with suitable names
asos-gurpreetsingh Sep 22, 2024
f51761a
separate assembly and file versions
asos-gurpreetsingh Oct 20, 2024
e106b17
refactored unit tests to read expected versions from project files
asos-gurpreetsingh Oct 20, 2024
0318c45
check versions against assembly names
asos-gurpreetsingh Oct 20, 2024
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
54 changes: 13 additions & 41 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ on:
release-version:
required: true
type: string
default: '0.0.0'
cache-build:
required: false
type: boolean
default: false
workflow_dispatch:

inputs:
release-version:
required: false
type: string
default: '0.0.0'
env:
SOLUTION_FILE_PATH: .\src
BUILD_CONFIGURATION: Release
Expand All @@ -21,27 +24,15 @@ jobs:
build_test_publish:
name: Build and run unit tests
runs-on: windows-2022
env:
NUnitVersion: '3.16.3'
steps:
- name: Install NUnit Console Runner and VS project extension
run: |
Install-Package NUnit.ConsoleRunner -Force -RequiredVersion $env:NUnitVersion
Install-Package NUnit.Extension.VSProjectLoader -Force -RequiredVersion '3.9.0'

- name: Git configuration
run: git config --global core.autocrlf false

- uses: actions/checkout@v4

- name: Add MSBuild for VS 2022 to PATH
uses: microsoft/setup-msbuild@v2
with:
vs-version: '[17.2,18.0)'

- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore $env:SOLUTION_FILE_PATH
working-directory: ${{env.SOLUTION_FILE_PATH}}
run: dotnet restore

- name: Show version
run: echo "Building version ${{ inputs.release-version }}"
Expand All @@ -50,37 +41,18 @@ jobs:
env:
ReleaseVersion: ${{ inputs.release-version }}
run: |
$numberVersion = .\GetNumberVersion -Version ${{env.ReleaseVersion}}
Write-Host "Using release version: $env:ReleaseVersion"
$numberVersion = .\GetNumberVersion -Version $env:ReleaseVersion
echo "Setting numberVersion to $numberVersion"
echo "NUMBER_VERSION=$numberVersion" >> $env:GITHUB_ENV

- name: Set fileversion on all .NET Framework assemblies and assembly version on the exe
env:
ReleaseVersion: ${{ inputs.release-version }}
run: |
$sbeFileName = "$env:GITHUB_WORKSPACE\src\ServiceBusExplorer\Properties\AssemblyInfo.cs"
.\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyVersion' -Version ${{env.NUMBER_VERSION}}
.\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}}
.\SetVersion -FileName $sbeFileName -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}}

$commonInfoFile = "$env:GITHUB_WORKSPACE\src\Common\Properties\AssemblyInfo.cs"
.\SetVersion -FileName $commonInfoFile -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}}
.\SetVersion -FileName $commonInfoFile -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}}

$notificationHubsInfoFile = "$env:GITHUB_WORKSPACE\src\NotificationHubs\Properties\AssemblyInfo.cs"
.\SetVersion -FileName $notificationHubsInfoFile -PropertyName 'AssemblyFileVersion' -Version ${{env.NUMBER_VERSION}}
.\SetVersion -FileName $notificationHubsInfoFile -PropertyName 'AssemblyInformationalVersion' -VersionString ${{env.ReleaseVersion}}

- name: Build
run: |
msbuild /m /property:Configuration=${{env.BUILD_CONFIGURATION}},FileVersion=${{env.NUMBER_VERSION}},InformationalVersion=${{inputs.release-version}} ${{env.SOLUTION_FILE_PATH}}
working-directory: ${{env.SOLUTION_FILE_PATH}}
run: dotnet build -c ${{env.BUILD_CONFIGURATION}} /p:AssemblyVersion=${{env.NUMBER_VERSION}} /p:InformationalVersion=${{inputs.release-version}}
asos-gurpreetsingh marked this conversation as resolved.
Show resolved Hide resolved

- name: Run tests
run: |
$process = Start-Process -FilePath "C:\Program Files\PackageManagement\NuGet\Packages\NUnit.ConsoleRunner.$env:NUnitVersion\tools\nunit3-console.exe" -ArgumentList "$env:GITHUB_WORKSPACE\src\ServiceBusExplorer.Tests\ServiceBusExplorer.Tests.csproj", "--config=${{env.BUILD_CONFIGURATION}}" -PassThru
Wait-Process -InputObject $process
Get-Content -Path .\TestResult.xml
if ($process.ExitCode -ne 0) {throw "Unit tests failed (exit code = $($process.ExitCode))" }
working-directory: ${{env.SOLUTION_FILE_PATH}}
run: dotnet test -c ${{env.BUILD_CONFIGURATION}}

- name: Cache build
uses: actions/[email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.22.0-beta.1" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Azure.ResourceManager.EventGrid" Version="1.1.0-beta.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.24" />
Expand Down
27 changes: 13 additions & 14 deletions src/ServiceBusExplorer.Tests/Helpers/ConversionHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,48 @@

using System;
using System.Globalization;
using ServiceBusExplorer.Helpers;
using ServiceBusExplorer.Utilities.Helpers;
using NUnit.Framework;
using FluentAssertions;
using Xunit;

#endregion

namespace ServiceBusExplorer.Tests.Helpers
{
[TestFixture]
public class ConversionHelperTests
{
[Test]
[Fact]
public void MapStringTypeToCLRType_ValueIsGuidObject_ReturnsEqualGuidObject()
{
var guid = new Guid("2E9DB8C4-8803-4BD7-B860-8932CF13835E");
var convertedGuid = ConversionHelper.MapStringTypeToCLRType("Guid", guid);
Assert.AreEqual(guid, convertedGuid);
convertedGuid.Should().BeEquivalentTo(guid);
}

[Test]
[Fact]
public void MapStringTypeToCLRType_ValueIsGuidString_ReturnsEqualGuidObject()
{
var guidStr = "2E9DB8C4-8803-4BD7-B860-8932CF13835E";
var convertedGuid = ConversionHelper.MapStringTypeToCLRType("Guid", guidStr);
Assert.AreEqual(guidStr.ToLower(), convertedGuid.ToString());
convertedGuid.ToString().Should().BeEquivalentTo(guidStr);
}

[Theory]
[TestCase("00:00:00")]
[TestCase("3:44:55")]
[TestCase("03:44:55")]
[TestCase("1:00:00:00.0000000")] // one day
[InlineData("00:00:00")]
[InlineData("3:44:55")]
[InlineData("03:44:55")]
[InlineData("1:00:00:00.0000000")] // one day
public void MapStringTypeToCLRType_ValueIsTimeSpanString_ReturnsEqualTimespanObject(string timespanStr)
{
var convertedTimespan = ConversionHelper.MapStringTypeToCLRType("TimeSpan", timespanStr);
Assert.AreEqual(convertedTimespan, TimeSpan.Parse(timespanStr, CultureInfo.InvariantCulture));
convertedTimespan.Should().BeEquivalentTo(TimeSpan.Parse(timespanStr, CultureInfo.InvariantCulture));
}

[Test]
[Fact]
public void MapStringTypeToCLRType_ValueIsTimeSpan_ReturnsEqualTimespanObject()
{
var convertedTimespan = ConversionHelper.MapStringTypeToCLRType("TimeSpan", TimeSpan.Zero);
Assert.AreEqual(convertedTimespan, TimeSpan.Zero);
convertedTimespan.Should().Be(TimeSpan.Zero);
}
}
}
35 changes: 17 additions & 18 deletions src/ServiceBusExplorer.Tests/Helpers/JsonSerializerHelperTest.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
using ServiceBusExplorer.Helpers;
using ServiceBusExplorer.Utilities.Helpers;
using NUnit.Framework;
using ServiceBusExplorer.Utilities.Helpers;
using FluentAssertions;
using Xunit;

namespace ServiceBusExplorer.Tests.Helpers
{
[TestFixture]
public class JsonSerializerHelperTest
{
[Test]
[Fact]
public void IsJson_ReturnsFalse_WhenNullInput()
{
var result = JsonSerializerHelper.IsJson(null);

Assert.AreEqual(result, false);
result.Should().BeFalse();
}

[Test]
[Fact]
public void IndentJson_ValueIsNotJson_ReturnsOriginalString()
{
var myOriginalString = "This is a full text string that is not a JSON";
var indented = JsonSerializerHelper.Indent(myOriginalString);

Assert.AreEqual(indented, myOriginalString);
indented.Should().Be(myOriginalString);
}

[Test]
[Fact]
public void IndentJson_ValueIsXml_ReturnsOriginalString()
{
var myOriginalString = "<sample><title>XML tile</title><alternate language=\"en\">A tile made from some classical XML content.</language></sample>";
var indented = JsonSerializerHelper.Indent(myOriginalString);

Assert.AreEqual(indented, myOriginalString);
indented.Should().Be(myOriginalString);
}

[Test]
[Fact]
public void IndentJson_ValueIsJson_ReturnsIndentedString()
{
var json = "{prop1:\"val1\",prop2:2,\"prop3\":[1, 2, 3],prop4:{subProp1:1,subProp2:\"string\",subProp3:[\"a\",\"b\",\"c\"]}}";
Expand All @@ -57,10 +56,10 @@ public void IndentJson_ValueIsJson_ReturnsIndentedString()
}";
var indented = JsonSerializerHelper.Indent(json);

Assert.AreEqual(indented, expectedResult);
indented.Should().Be(expectedResult);
}

[Test]
[Fact]
public void IndentJson_ValueIsJson_DoesNotChangeDateFormat()
{
var json = @"{""dateIso"":""2018-05-14T00:00:00Z"",""dateMicrosoft"":""/Date(1526256000000)/""}";
Expand All @@ -70,20 +69,20 @@ public void IndentJson_ValueIsJson_DoesNotChangeDateFormat()
}";
var indented = JsonSerializerHelper.Indent(json);

Assert.AreEqual(expectedResult, indented);
expectedResult.Should().Be(indented);
}

[Test]
[Fact]
public void IndentJson_ValueIsMalformedJson_ReturnsOriginalJson()
{
var json = @"{""Field1"":""Value1"",""Field1"":""Value2""}";
var expectedResult = @"{""Field1"":""Value1"",""Field1"":""Value2""}";
var indented = JsonSerializerHelper.Indent(json);

Assert.AreEqual(expectedResult, indented);
expectedResult.Should().Be(indented);
}

[Test]
[Fact]
public void IndentJson_ValueHasTypeHandling_ReturnsIndentedStringWithTypeHandling()
{
var json = "{\"$type\":\"MyAwesomeLibrary.MyAwesomeClass\",prop1:1,prop2:2,obj:{\"$type\":\"MyAwesomeLibrary.MyOtherAwesomeClass\",default:true}}";
Expand All @@ -98,7 +97,7 @@ public void IndentJson_ValueHasTypeHandling_ReturnsIndentedStringWithTypeHandlin
}";
var indented = JsonSerializerHelper.Indent(json);

Assert.AreEqual(indented, expectedResult);
indented.Should().Be(expectedResult);
}
}
}
Loading