using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AutopilotMonitor.Functions.Services.GraphResolution; namespace AutopilotMonitor.Functions.Tests.GraphResolution; /// In-memory fake for resolver tests. internal sealed class FakeGraphFeatureDetector : IGraphFeatureDetector { public Dictionary ContextByTenant { get; } = new(); public List InvalidateCalls { get; } = new(); public Task HasPermissionAsync(string tenantId, string graphAppRole, CancellationToken ct = default) { ContextByTenant.TryGetValue(tenantId, out var ctx); return Task.FromResult(ctx != null && ctx.GrantedRoles.Contains(graphAppRole)); } public Task> GetGrantedRolesAsync(string tenantId, CancellationToken ct = default) { ContextByTenant.TryGetValue(tenantId, out var ctx); return Task.FromResult>( ctx?.GrantedRoles ?? (IReadOnlySet)new HashSet()); } public Task TryGetTokenContextAsync(string tenantId, CancellationToken ct = default) { ContextByTenant.TryGetValue(tenantId, out var ctx); return Task.FromResult(ctx); } /// When set for a tenant, reports it as transient. public HashSet TransientTenants { get; } = new(); public Task GetSnapshotAsync(string tenantId, CancellationToken ct = default) { if (TransientTenants.Contains(tenantId)) { return Task.FromResult(new GraphPermissionSnapshot { IsTransient = true }); } ContextByTenant.TryGetValue(tenantId, out var ctx); return Task.FromResult(new GraphPermissionSnapshot { GrantedRoles = ctx?.GrantedRoles ?? (IReadOnlySet)new HashSet(), IsTransient = false, }); } public void InvalidateTenant(string tenantId) => InvalidateCalls.Add(tenantId); }