Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 5 additions & 19 deletions src/c#/DrivelutionTest/Core/DriverUpdaterFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,11 @@ public void IsPlatformSupported_ReturnsBooleanValue()
[Fact]
public void CreateValidator_WithoutParameters_ReturnsNonNullInstance()
{
// Skip on MacOS and Unknown platforms
var platform = DrivelutionFactory.GetCurrentPlatform();
if (platform == "MacOS" || platform == "Unknown")
{
if (platform == "Unknown")
return;
}

// Act
var validator = DrivelutionFactory.CreateValidator();

// Assert
Assert.NotNull(validator);
Assert.IsAssignableFrom<IDriverValidator>(validator);
}
Expand All @@ -98,17 +92,11 @@ public void CreateValidator_WithoutParameters_ReturnsNonNullInstance()
[Fact]
public void CreateBackup_WithoutParameters_ReturnsNonNullInstance()
{
// Skip on MacOS and Unknown platforms
var platform = DrivelutionFactory.GetCurrentPlatform();
if (platform == "MacOS" || platform == "Unknown")
{
if (platform == "Unknown")
return;
}

// Act
var backup = DrivelutionFactory.CreateBackup();

// Assert
Assert.NotNull(backup);
Assert.IsAssignableFrom<IDriverBackup>(backup);
}
Expand All @@ -120,17 +108,15 @@ public void CreateBackup_WithoutParameters_ReturnsNonNullInstance()
[Fact]
public void Create_OnSupportedPlatform_DoesNotThrow()
{
// Skip on MacOS as it's not yet implemented
var platform = DrivelutionFactory.GetCurrentPlatform();
if (platform == "MacOS")

if (platform == "Unknown")
{
// MacOS should throw PlatformNotSupportedException
Assert.Throws<PlatformNotSupportedException>(() => DrivelutionFactory.Create());
return;
}

// Act & Assert - should not throw on Windows/Linux
// Windows, Linux, and MacOS should all work
var exception = Record.Exception(() => DrivelutionFactory.Create());
Assert.Null(exception);
}
Expand Down
28 changes: 28 additions & 0 deletions src/c#/DrivelutionTest/Execution/CommandResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using GeneralUpdate.Drivelution.Core.Execution;

namespace DrivelutionTest.Execution;

public class CommandResultTests
{
[Fact]
public void Success_WhenExitCodeZero_ReturnsTrue()
{
var result = new CommandResult { ExitCode = 0 };
Assert.True(result.Success);
}

[Fact]
public void Success_WhenExitCodeNonZero_ReturnsFalse()
{
var result = new CommandResult { ExitCode = 1 };
Assert.False(result.Success);
}

[Fact]
public void ToString_IncludesExitCode()
{
var result = new CommandResult { ExitCode = 0, StandardOutput = "hello" };
Assert.Contains("0", result.ToString());
Assert.Contains("hello", result.ToString());
}
}
8 changes: 2 additions & 6 deletions src/c#/DrivelutionTest/GeneralDrivelutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public async Task QuickUpdateAsync_WithCancellationToken_CanBeCancelled()
// Act & Assert
// Should either complete quickly or throw cancellation exception
var exception = await Record.ExceptionAsync(
() => GeneralDrivelution.QuickUpdateAsync(driverInfo, cts.Token));
() => GeneralDrivelution.QuickUpdateAsync(driverInfo, cancellationToken: cts.Token));

// Either succeeded, failed gracefully, or was cancelled
Assert.True(exception == null || exception is OperationCanceledException);
Expand All @@ -274,14 +274,10 @@ public void GetPlatformInfo_ReportsCorrectSupportStatus()
var platformInfo = GeneralDrivelution.GetPlatformInfo();

// Assert
if (platformInfo.Platform == "Windows" || platformInfo.Platform == "Linux")
if (platformInfo.Platform == "Windows" || platformInfo.Platform == "Linux" || platformInfo.Platform == "MacOS")
{
Assert.True(platformInfo.IsSupported);
}
else if (platformInfo.Platform == "MacOS")
{
Assert.False(platformInfo.IsSupported); // MacOS not yet implemented
}
}

/// <summary>
Expand Down
80 changes: 80 additions & 0 deletions src/c#/DrivelutionTest/Models/NewModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using GeneralUpdate.Drivelution.Abstractions.Models;

namespace DrivelutionTest.Models;

/// <summary>
/// Tests for the new model classes added during the refactoring.
/// </summary>
public class NewModelTests
{
[Fact]
public void UpdateProgress_HasExpectedDefaults()
{
var progress = new UpdateProgress();
Assert.Equal(UpdateStatus.NotStarted, progress.CurrentStatus);
Assert.Equal(string.Empty, progress.StepName);
Assert.Equal(0, progress.Percentage);
Assert.Equal(0, progress.StepIndex);
Assert.Equal(0, progress.TotalSteps);
}

[Fact]
public void UpdateProgress_ToString_IncludesAllFields()
{
var progress = new UpdateProgress
{
Percentage = 50,
StepName = "Validate",
StepIndex = 1,
TotalSteps = 4,
Message = "Checking"
};

var str = progress.ToString();
Assert.Contains("50", str);
Assert.Contains("Validate", str);
Assert.Contains("2/4", str);
Assert.Contains("Checking", str);
}

[Fact]
public void BatchUpdateResult_AllSucceeded_WhenAllPass()
{
var result = new BatchUpdateResult
{
SucceededCount = 3,
FailedCount = 0
};
result.AllSucceeded = result.FailedCount == 0;

Assert.True(result.AllSucceeded);
}

[Fact]
public void BatchUpdateResult_AllSucceeded_WhenAnyFail()
{
var result = new BatchUpdateResult
{
SucceededCount = 2,
FailedCount = 1
};
result.AllSucceeded = result.FailedCount == 0;

Assert.False(result.AllSucceeded);
}

[Fact]
public void DriverUpdateEntry_HoldsResult()
{
var updateResult = new UpdateResult { Success = true };
var entry = new DriverUpdateEntry
{
DriverInfo = new DriverInfo { Name = "test" },
Success = true,
Result = updateResult
};

Assert.Same(updateResult, entry.Result);
Assert.True(entry.Success);
}
}
Loading
Loading