-
Notifications
You must be signed in to change notification settings - Fork 58
Add comprehensive test suite for GeneralUpdate.Drivelution #140
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| using GeneralUpdate.Drivelution.Core; | ||
| using GeneralUpdate.Drivelution.Abstractions; | ||
| using GeneralUpdate.Drivelution.Abstractions.Configuration; | ||
| using Serilog; | ||
| using Serilog.Core; | ||
|
|
||
| namespace DrivelutionTest.Core; | ||
|
|
||
| /// <summary> | ||
| /// Tests for DriverUpdaterFactory class. | ||
| /// Validates platform detection, factory creation, and platform-specific implementations. | ||
| /// </summary> | ||
| public class DriverUpdaterFactoryTests | ||
| { | ||
| /// <summary> | ||
| /// Tests that Create method returns a non-null instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Create_WithoutParameters_ReturnsNonNullInstance() | ||
| { | ||
| // Arrange & Act | ||
| var updater = DriverUpdaterFactory.Create(); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(updater); | ||
| Assert.IsAssignableFrom<IGeneralDrivelution>(updater); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that Create method accepts custom logger. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Create_WithCustomLogger_ReturnsInstance() | ||
| { | ||
| // Arrange | ||
| var logger = new LoggerConfiguration() | ||
| .MinimumLevel.Debug() | ||
| .WriteTo.Console() | ||
| .CreateLogger(); | ||
|
|
||
| // Act | ||
| var updater = DriverUpdaterFactory.Create(logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(updater); | ||
| Assert.IsAssignableFrom<IGeneralDrivelution>(updater); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that Create method accepts custom options. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Create_WithCustomOptions_ReturnsInstance() | ||
| { | ||
| // Arrange | ||
| var options = new DriverUpdateOptions | ||
| { | ||
| LogLevel = "Debug", | ||
| LogFilePath = "./logs/test.log" | ||
| }; | ||
|
|
||
| // Act | ||
| var updater = DriverUpdaterFactory.Create(null, options); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(updater); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that GetCurrentPlatform returns a valid platform name. | ||
| /// </summary> | ||
| [Fact] | ||
| public void GetCurrentPlatform_ReturnsValidPlatformName() | ||
| { | ||
| // Act | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(platform); | ||
| Assert.Contains(platform, new[] { "Windows", "Linux", "MacOS", "Unknown" }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that IsPlatformSupported returns a boolean value. | ||
| /// </summary> | ||
| [Fact] | ||
| public void IsPlatformSupported_ReturnsBooleanValue() | ||
| { | ||
| // Act | ||
| var isSupported = DriverUpdaterFactory.IsPlatformSupported(); | ||
|
|
||
| // Assert | ||
| // Windows and Linux should be supported | ||
| Assert.True(isSupported || DriverUpdaterFactory.GetCurrentPlatform() == "MacOS" || DriverUpdaterFactory.GetCurrentPlatform() == "Unknown"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that CreateValidator returns a non-null instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CreateValidator_WithoutLogger_ReturnsNonNullInstance() | ||
| { | ||
| // Skip on MacOS and Unknown platforms | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
| if (platform == "MacOS" || platform == "Unknown") | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Act | ||
| var validator = DriverUpdaterFactory.CreateValidator(); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(validator); | ||
| Assert.IsAssignableFrom<IDriverValidator>(validator); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that CreateBackup returns a non-null instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CreateBackup_WithoutLogger_ReturnsNonNullInstance() | ||
| { | ||
| // Skip on MacOS and Unknown platforms | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
| if (platform == "MacOS" || platform == "Unknown") | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Act | ||
| var backup = DriverUpdaterFactory.CreateBackup(); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(backup); | ||
| Assert.IsAssignableFrom<IDriverBackup>(backup); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that CreateValidator with custom logger works correctly. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CreateValidator_WithCustomLogger_ReturnsInstance() | ||
| { | ||
| // Skip on MacOS and Unknown platforms | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
| if (platform == "MacOS" || platform == "Unknown") | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Arrange | ||
| var logger = new LoggerConfiguration() | ||
| .MinimumLevel.Debug() | ||
| .WriteTo.Console() | ||
| .CreateLogger(); | ||
|
|
||
| // Act | ||
| var validator = DriverUpdaterFactory.CreateValidator(logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(validator); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that CreateBackup with custom logger works correctly. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CreateBackup_WithCustomLogger_ReturnsInstance() | ||
| { | ||
| // Skip on MacOS and Unknown platforms | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
| if (platform == "MacOS" || platform == "Unknown") | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Arrange | ||
| var logger = new LoggerConfiguration() | ||
| .MinimumLevel.Debug() | ||
| .WriteTo.Console() | ||
| .CreateLogger(); | ||
|
|
||
| // Act | ||
| var backup = DriverUpdaterFactory.CreateBackup(logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(backup); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests that Create throws PlatformNotSupportedException on unsupported platforms. | ||
| /// This test documents expected behavior but cannot be easily tested on supported platforms. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Create_OnSupportedPlatform_DoesNotThrow() | ||
| { | ||
| // Skip on MacOS as it's not yet implemented | ||
| var platform = DriverUpdaterFactory.GetCurrentPlatform(); | ||
|
|
||
| if (platform == "MacOS") | ||
| { | ||
| // MacOS should throw PlatformNotSupportedException | ||
| Assert.Throws<PlatformNotSupportedException>(() => DriverUpdaterFactory.Create()); | ||
| return; | ||
| } | ||
|
|
||
| // Act & Assert - should not throw on Windows/Linux | ||
| var exception = Record.Exception(() => DriverUpdaterFactory.Create()); | ||
| Assert.Null(exception); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector" Version="6.0.4" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> | ||
| <PackageReference Include="xunit" Version="2.9.3" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" /> | ||
| <PackageReference Include="Moq" Version="4.20.72" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\GeneralUpdate.Drivelution\GeneralUpdate.Drivelution.csproj" /> | ||
| </ItemGroup> | ||
|
Comment on lines
+24
to
+26
|
||
|
|
||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DriverUpdaterFactory.Create()throwsPlatformNotSupportedExceptionon MacOS/unsupported platforms, so this test will fail when run there. Consider branching onGetCurrentPlatform()and asserting the exception for MacOS/Unknown (or skipping), so the test suite is portable across runners.