-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle beta versions of ha * Update HomeAssistantClient.cs * Update GlobalUsings.cs * add test and helper
- Loading branch information
Showing
4 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Client/NetDaemon.HassClient.Tests/HelperTest/VersionHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace NetDaemon.HassClient.Tests.HelperTest; | ||
|
||
public class VersionHelperTests | ||
{ | ||
[Theory] | ||
[InlineData("2022.8.12", "2022.8.12")] | ||
[InlineData("2022.8.0b7", "2022.8.0")] | ||
[InlineData("2022.9.0", "2022.9.0")] | ||
[InlineData("2022.9.0b1", "2022.9.0")] | ||
public void WithoutBeta_ValidInput_ReturnsExpectedVersion(string input, string expectedOutput) | ||
{ | ||
// Arrange | ||
var expectedVersion = new Version(expectedOutput); | ||
|
||
// Act | ||
var parsedVersion = VersionHelper.ReplaceBeta(input); | ||
|
||
// Assert | ||
Assert.Equal(expectedVersion, parsedVersion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Client/NetDaemon.HassClient/Internal/Helpers/VersionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace NetDaemon.Client.Internal.Helpers; | ||
|
||
internal static partial class VersionHelper | ||
{ | ||
public static Version ReplaceBeta(string version) | ||
=> Version.Parse(BetaVersion().Replace(version, ".0")); | ||
|
||
|
||
[GeneratedRegex("\\.0b\\d+$")] | ||
private static partial Regex BetaVersion(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters