Skip to content

Test: Expand SystemSettingsService test coverage to all catalog settings#93

Merged
DotDev262 merged 3 commits into
DotDev262:mainfrom
omnipotentchaos:expand-systemsettingscoverage
May 21, 2026
Merged

Test: Expand SystemSettingsService test coverage to all catalog settings#93
DotDev262 merged 3 commits into
DotDev262:mainfrom
omnipotentchaos:expand-systemsettingscoverage

Conversation

@omnipotentchaos

Copy link
Copy Markdown
Contributor

Test: Expand SystemSettingsService test coverage to all catalog settings

Related Issue

Closes #75

Proposed Changes

  • Expanded mock-based unit tests in SystemSettingsServiceTests.cs to achieve full test coverage for all 12 remaining catalog settings (for both GetTweaksAsync and GetCapturedSettingsAsync with all valid options).
  • Added robust coverage for setting edge cases: null setting inputs, empty settings dictionary, unknown setting keys, and invalid setting values.
  • Added verification tests for the strict security preset (baseline tweaks plus three strict registry settings).
  • Added output friendly name mapping validation tests for GetFriendlyName (known settings and unknown paths).
  • Formatted the codebase to be fully compliant with project standards via dotnet format.
  • Resolved compiler warning CS8625 in tests using a null-forgiving operator.

Type of Change

  • 🧪 Testing

Screenshots / Logs (if applicable)

  WinHome -> E:\GSSOC\WinHome\src\bin\Debug\net10.0-windows\win-x64\WinHome.dll
  WinHome.Tests -> E:\GSSOC\WinHome\tests\WinHome.Tests\bin\Debug\net10.0-windows\WinHome.Tests.dll
Test run for E:\GSSOC\WinHome\tests\WinHome.Tests\bin\Debug\net10.0-windows\WinHome.Tests.dll (.NETCoreApp,Version=v10.0)
Passed: 121, Failed: 3 (environment-specific: symlink creation privileges, uv, bun missing)
Total: 124, Duration: 1 m 19 s

Testing & Verification

  • I have run dotnet test and all 60+ cross-platform tests passed.
  • I have verified the changes on a Windows environment (if applicable).
  • I have added new unit tests to cover my changes.

GSSOC 2026 Checklist

  • I have read the Contribution Guidelines.
  • My code is formatted correctly (I have run dotnet format).
  • I have linked the PR to an approved issue.
  • I understand that a maintainer must apply the gssoc:approved label for this PR to count for points.

Copilot AI review requested due to automatic review settings May 21, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands SystemSettingsService unit test coverage to validate more catalog setting → registry tweak mappings and captured-setting translations, improving confidence in both generation and capture logic for Windows system tweaks.

Changes:

  • Added tests for the strict security preset and additional catalog settings (e.g., dark mode, taskbar alignment/widgets, file visibility, seconds-in-clock, explorer launch target, Bing search).
  • Added edge-case tests for GetTweaksAsync (null/empty settings, unknown keys, invalid values).
  • Added GetFriendlyName mapping tests (known tweaks and unknown paths).
Comments suppressed due to low confidence (1)

tests/WinHome.Tests/SystemSettingsServiceTests.cs:163

  • There’s a lot of repeated Arrange/Act/Assert structure across the new GetTweaksAsync tests (true/false or left/center variants). Converting these to [Theory] tests with InlineData (and possibly a small helper to assert a single expected tweak) would reduce duplication and make it easier to add new catalog settings/options later.
        [Fact]
        public async Task GetTweaksAsync_Should_Return_TaskbarAlignment_Tweaks()
        {
            var settingsLeft = new Dictionary<string, object> { { "taskbar_alignment", "left" } };
            var tweaksLeft = await _service.GetTweaksAsync(settingsLeft);
            var listLeft = new List<RegistryTweak>(tweaksLeft);
            Assert.Single(listLeft);
            Assert.Equal("TaskbarAl", listLeft[0].Name);
            Assert.Equal(0, listLeft[0].Value);

            var settingsCenter = new Dictionary<string, object> { { "taskbar_alignment", "center" } };
            var tweaksCenter = await _service.GetTweaksAsync(settingsCenter);
            var listCenter = new List<RegistryTweak>(tweaksCenter);
            Assert.Single(listCenter);
            Assert.Equal("TaskbarAl", listCenter[0].Name);
            Assert.Equal(1, listCenter[0].Value);
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +118
[Fact]
public async Task GetTweaksAsync_Should_Return_DarkMode_Tweaks()
{
var settingsTrue = new Dictionary<string, object> { { "dark_mode", "true" } };
var tweaksTrue = await _service.GetTweaksAsync(settingsTrue);
var tweaksListTrue = new List<RegistryTweak>(tweaksTrue);

Assert.Equal(2, tweaksListTrue.Count);
Assert.Contains(tweaksListTrue, t => t.Name == "AppsUseLightTheme" && t.Value.Equals(0));
Assert.Contains(tweaksListTrue, t => t.Name == "SystemUsesLightTheme" && t.Value.Equals(0));

var settingsFalse = new Dictionary<string, object> { { "dark_mode", "false" } };
var tweaksFalse = await _service.GetTweaksAsync(settingsFalse);
var tweaksListFalse = new List<RegistryTweak>(tweaksFalse);

Assert.Equal(2, tweaksListFalse.Count);
Assert.Contains(tweaksListFalse, t => t.Name == "AppsUseLightTheme" && t.Value.Equals(1));
Assert.Contains(tweaksListFalse, t => t.Name == "SystemUsesLightTheme" && t.Value.Equals(1));
}
Comment on lines +124 to +141
.Setup(r => r.Read(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme"))
.Returns(0);
_mockRegistryService
.Setup(r => r.Read(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme"))
.Returns(0);

var capturedTrue = await _service.GetCapturedSettingsAsync();
Assert.True(capturedTrue.ContainsKey("dark_mode"));
Assert.True((bool)capturedTrue["dark_mode"]);

_mockRegistryService.Invocations.Clear();
_mockRegistryService
.Setup(r => r.Read(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme"))
.Returns(1);
_mockRegistryService
.Setup(r => r.Read(@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme"))
.Returns(1);

@DotDev262

DotDev262 commented May 21, 2026

Copy link
Copy Markdown
Owner

@omnipotentchaos resolve the github copilot suggestions, I also need the screenshot of the working code

@DotDev262 DotDev262 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Solid work on expanding test coverage. The tests are clean and follow existing patterns well. A few improvements requested:

Should fix (non-blocking but good practice):

  • Multiple assertions per [Fact] — several tests bundle true/false cases in one method (e.g., GetTweaksAsync_Should_Return_DarkMode_Tweaks, GetCapturedSettingsAsync_Should_Capture_DarkMode, and all the similar true/false patterns). Please refactor these into [Theory] [InlineData] tests so each case runs independently and failure of one doesn't hide the other.
  • Code duplication — the same Arrange/Act/Assert pattern is repeated ~16 times across settings (dark_mode, taskbar_alignment, taskbar_widgets, show_file_extensions, show_hidden_files, seconds_in_clock, bing_search_enabled, explorer_launch_to). Converting to [Theory] with [InlineData] and a helper method would reduce this by ~60%.
  • null! null-forgiving operator in GetTweaksAsync_Should_Return_Empty_On_Null_Settings — if GetTweaksAsync should accept null, consider making the parameter explicitly nullable (Dictionary<string, object>?) rather than suppressing the warning with !.

Note:

  • The 3 failed tests (symlink, uv, bun) are environment-specific and expected on non-Windows — no action needed.
  • PR #63 recently added a privacy security preset — consider adding tests for it in a follow-up.

Overall these are incremental improvements, not blockers. The tests are functional and comprehensive.

@DotDev262 DotDev262 added GSSOC GirlScript Summer of Code 2026 level:beginner Beginner level task type:testing Testing labels May 21, 2026
@omnipotentchaos

Copy link
Copy Markdown
Contributor Author

Hi @DotDev262, thank you for the helpful feedback! I have successfully addressed all suggestions in the latest commits:

  • Converted all duplicate Arranges, Acts, and Asserts for the 13 catalog settings and captured settings into clean [Theory] + [InlineData] parameterizations.

  • Added corresponding tests for boolean "false" cases to ensure complete option coverage.

  • Removed the mid-test mock Invocations.Clear() calls by using isolated parameterized Theory test runs.

  • Updated the GetTweaksAsync and ApplyNonRegistrySettingsAsync dictionary parameters in the interface and service class to be explicitly nullable (Dictionary<string, object>?), cleanly resolving warning CS8625.

  • Integrated the new "privacy" security preset and wrote detailed unit tests to verify its exact tweaks.

All 160+ cross-platform unit tests compile perfectly and pass successfully!
image
image
image
image

@DotDev262

Copy link
Copy Markdown
Owner

Review

Thanks for the contribution. A few things to fix before this can be merged:

Must fix

  1. PR_DESCRIPTION.md committed to the repo — This is a PR description artifact and should not be in the repository. Please delete it from your branch:

    git rm PR_DESCRIPTION.md
    git commit -m "chore: remove PR_DESCRIPTION.md artifact"
  2. Merge conflict — Your branch has conflicts with main. Please rebase:

    git fetch origin
    git rebase origin/main
    # resolve conflicts, then
    git push --force-with-lease

Note

The test coverage improvements are otherwise solid — the [Theory]/[InlineData] refactoring and edge case coverage are genuinely good work.

@omnipotentchaos
omnipotentchaos force-pushed the expand-systemsettingscoverage branch from b94686e to c044753 Compare May 21, 2026 10:31
@omnipotentchaos

Copy link
Copy Markdown
Contributor Author

@DotDev262 I have completed all the requested fixes.

@DotDev262 DotDev262 added the gssoc:approved Approved for GSSOC points (Required) label May 21, 2026
@DotDev262
DotDev262 merged commit 20761a3 into DotDev262:main May 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSOC points (Required) GSSOC GirlScript Summer of Code 2026 level:beginner Beginner level task type:testing Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Expand SystemSettingsService Test Coverage

3 participants