---
phase: 07-user-access-audit
plan: 10
subsystem: testing
tags: [xunit, moq, debounce, search, viewmodel]

# Dependency graph
requires:
  - phase: 07-user-access-audit
    provides: UserAccessAuditViewModel with debounced SearchQuery → DebounceSearchAsync → SearchUsersAsync path (plan 08)
provides:
  - Unit test verifying SearchQuery debounce triggers IGraphUserSearchService.SearchUsersAsync after 300ms

affects:
  - future plans referencing UserAccessAuditViewModelTests

# Tech tracking
tech-stack:
  added: []
  patterns: ["CreateViewModel returns 3-tuple (vm, auditMock, graphMock) — callers use _ discards for unused elements"]

key-files:
  created: []
  modified:
    - SharepointToolbox.Tests/ViewModels/UserAccessAuditViewModelTests.cs

key-decisions:
  - "Extended CreateViewModel to 3-tuple (vm, auditMock, graphMock) so debounce test can set up expectations and verify calls on IGraphUserSearchService"
  - "600ms Task.Delay in test ensures 300ms debounce + async execution completes before assertion"
  - "TenantSwitchedMessage sent before setting SearchQuery to populate _currentProfile, preventing null ClientId from bypassing the real search path"

patterns-established:
  - "Debounce test pattern: set messenger profile, set property, await 2x debounce delay, verify mock"

requirements-completed: [UACC-01]

# Metrics
duration: 5min
completed: 2026-04-07
---

# Phase 7 Plan 10: Debounced Search Unit Test Summary

**Unit test closing gap 3: setting SearchQuery triggers SearchUsersAsync after 300ms debounce, verified with Moq on IGraphUserSearchService**

## Performance

- **Duration:** ~5 min
- **Started:** 2026-04-07T11:05:00Z
- **Completed:** 2026-04-07T11:10:00Z
- **Tasks:** 1
- **Files modified:** 1

## Accomplishments

- Extended `CreateViewModel` helper from 2-tuple to 3-tuple, exposing `Mock<IGraphUserSearchService>` to tests
- Updated all 8 existing tests with `_` discard for the new third slot — zero regressions
- Added Test 9 (`SearchQuery_debounced_calls_SearchUsersAsync`) that proves the fire-and-forget debounce path invokes `SearchUsersAsync` exactly once after the 300ms delay
- Full suite: 177 passed / 22 skipped / 0 failed

## Task Commits

Each task was committed atomically:

1. **Task 1: Add debounced search unit test** - `67a2053` (test)

**Plan metadata:** (docs commit below)

## Files Created/Modified

- `SharepointToolbox.Tests/ViewModels/UserAccessAuditViewModelTests.cs` - Extended CreateViewModel to 3-tuple, updated 8 existing tests, added Test 9

## Decisions Made

- Extended `CreateViewModel` to return `(vm, auditMock, graphMock)` rather than creating a separate overload — keeps one factory, callers use `_` for unused mocks
- Used `TenantSwitchedMessage` to populate `_currentProfile` before the search rather than `SetCurrentProfile` helper — follows the same path the real UI uses, ensuring more realistic coverage

## Deviations from Plan

None - plan executed exactly as written.

## Issues Encountered

None.

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- Verification gap 3 closed: debounced search path has unit test coverage
- All 9 ViewModel tests pass; UserAccessAudit feature test suite complete

---
*Phase: 07-user-access-audit*
*Completed: 2026-04-07*
