Skip to content

Commit

Permalink
Added test report, to show broken tests, and then fixed the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Sep 26, 2023
1 parent 2a80156 commit 632733b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Build and Test

on: [ push, pull_request ]

permissions:
contents: read
actions: read
checks: write

env:
IS_CI_BUILD: 'true'
SOLUTION_PATH: 'src/SaaStack.sln'
Expand All @@ -25,7 +30,28 @@ jobs:
- name: Build for Testing
run: dotnet build --configuration ${{env.TESTINGONLY_BUILD_CONFIGURATION}} "${{env.SOLUTION_PATH}}"
- name: Unit Test
run: dotnet test --no-build --verbosity normal --configuration ${{env.TESTINGONLY_BUILD_CONFIGURATION}} --filter:Category="Unit" --collect:"XPlat Code Coverage" --results-directory:"src/TestResults/csharp" --logger:"trx" --logger:"junit;LogFileName={assembly}.junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --test-adapter-path:. "${{env.SOLUTION_PATH}}"
continue-on-error: false
run: >
dotnet test --no-build --verbosity normal
--configuration ${{env.TESTINGONLY_BUILD_CONFIGURATION}}
--filter:Category="Unit" --collect:"XPlat Code Coverage" --results-directory:"src/TestResults/csharp"
--logger:"trx"
--logger:"junit;LogFileName={assembly}.junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
--test-adapter-path:. "${{env.SOLUTION_PATH}}"
- name: Integration Test
continue-on-error: true
run: dotnet test --no-build --verbosity normal --configuration ${{env.TESTINGONLY_BUILD_CONFIGURATION}} --filter:Category="Integration.Web" --collect:"XPlat Code Coverage" --results-directory:"src/TestResults/csharp" --logger:"trx" --logger:"junit;LogFileName={assembly}.junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --test-adapter-path:. "${{env.SOLUTION_PATH}}"
run: >
dotnet test --no-build --verbosity normal
--configuration ${{env.TESTINGONLY_BUILD_CONFIGURATION}}
--filter:Category="Integration.Web" --collect:"XPlat Code Coverage" --results-directory:"src/TestResults/csharp"
--logger:"trx"
--logger:"junit;LogFileName={assembly}.junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
--test-adapter-path:. "${{env.SOLUTION_PATH}}"
- name: Testing Report
uses: dorny/[email protected]
if: success() || failure()
with:
name: All Tests
path: 'src/TestResults/csharp/**/*.trx'
reporter: dotnet-trx
fail-on-error: 'false'
17 changes: 10 additions & 7 deletions src/Common.UnitTests/Extensions/DateTimeExtensionsSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public void WhenToIso8601WithLocalTime_ThenReturnsUtcTime()

var result = time.ToIso8601();

result.Should().Be("2023-09-23T23:00:00.0000000Z");
var offset = TimeZoneInfo.Local.GetUtcOffset(time);
var offsetTime = time.Subtract(offset);

result.Should().Be($"2023-09-{offsetTime.Day:D2}T{offsetTime.Hour:D2}:{offsetTime.Minute:D2}:00.0000000Z");
}

[Fact]
Expand Down Expand Up @@ -50,9 +53,9 @@ public void WhenToUnixSecondsWithLocalTime_ThenReturnsUtcTime()

var result = time.ToUnixSeconds();

//HACK: result varies according to the local timezone (of the code running) including daylight savings
var localTzOffsetMilliseconds = (long)TimeZoneInfo.Local.GetUtcOffset(time).Seconds;
var expected = 1695510000L + localTzOffsetMilliseconds;
var offset = TimeZoneInfo.Local.GetUtcOffset(time);
var offsetTime = time.Subtract(offset);
var expected = (long)offsetTime.Subtract(DateTime.UnixEpoch).TotalSeconds;

result.Should().Be(expected);
}
Expand Down Expand Up @@ -82,9 +85,9 @@ public void WhenToUnixMilliSecondsWithLocalTime_ThenReturnsUtcTime()

var result = time.ToUnixMilliSeconds();

//HACK: result varies according to the local timezone (of the code running) including daylight savings
var localTzOffsetMilliseconds = (long)TimeZoneInfo.Local.GetUtcOffset(time).Milliseconds;
var expected = 1695510000000L + localTzOffsetMilliseconds;
var offset = TimeZoneInfo.Local.GetUtcOffset(time);
var offsetTime = time.Subtract(offset);
var expected = (long)offsetTime.Subtract(DateTime.UnixEpoch).TotalMilliseconds;

result.Should().Be(expected);
}
Expand Down

0 comments on commit 632733b

Please sign in to comment.