{"record":{"id":"a19d12e0c737f063","repo":"ppy/osu","slug":"using-the-nameof-osutestscene-dummy-api-is-not","errorCode":null,"errorMessage":"Using the {nameof(OsuTestScene)} dummy API is not supported when {nameof(UseOnlineAPI)} is true","messagePattern":"Using the (.+?) dummy API is not supported when (.+?) is true","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"osu.Game/Tests/Visual/OsuTestScene.cs","lineNumber":61,"sourceCode":"        [Cached]\r\n        protected Bindable<WorkingBeatmap> Beatmap { get; } = new Bindable<WorkingBeatmap>();\r\n\r\n        [Cached]\r\n        protected Bindable<RulesetInfo> Ruleset { get; } = new Bindable<RulesetInfo>();\r\n\r\n        [Cached]\r\n        protected Bindable<IReadOnlyList<Mod>> SelectedMods { get; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());\r\n\r\n        protected new DependencyContainer Dependencies { get; private set; }\r\n\r\n        protected IResourceStore<byte[]> Resources;\r\n\r\n        protected IAPIProvider API\r\n        {\r\n            get\r\n            {\r\n                if (UseOnlineAPI)\r\n                    throw new InvalidOperationException($\"Using the {nameof(OsuTestScene)} dummy API is not supported when {nameof(UseOnlineAPI)} is true\");\r\n\r\n                return dummyAPI;\r\n            }\r\n        }\r\n\r\n        private DummyAPIAccess dummyAPI;\r\n\r\n        /// <summary>\r\n        /// Whether this test scene requires real-world API access.\r\n        /// If true, this will bypass the local <see cref=\"DummyAPIAccess\"/> and use the <see cref=\"OsuGameBase\"/> provided one.\r\n        /// </summary>\r\n        protected virtual bool UseOnlineAPI => false;\r\n\r\n        /// <summary>\r\n        /// A database context factory to be used by test runs. Can be isolated and reset by setting <see cref=\"UseFreshStoragePerRun\"/> to <c>true</c>.\r\n        /// </summary>\r\n        /// <remarks>\r\n        /// In interactive runs (ie. VisualTests) this will use the user's database if <see cref=\"UseFreshStoragePerRun\"/> is not set to <c>true</c>.\r","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Tests/Visual/OsuTestScene.cs#L43-L79","documentation":"OsuTestScene.API is a convenience accessor for the in-process DummyAPIAccess. When a test scene overrides UseOnlineAPI => true, no DummyAPIAccess is created (the real OsuGameBase IAPIProvider is used instead), so reading the dummy-backed API property is invalid and throws.","triggerScenarios":"A test scene sets UseOnlineAPI => true and then reads the inherited `API` property (or otherwise relies on the dummy API).","commonSituations":"Opting a test into real online-API access while legacy code paths still read OsuTestScene.API; copying a dummy-API-based test and flipping UseOnlineAPI.","solutions":["Do not read OsuTestScene.API when UseOnlineAPI is true; resolve IAPIProvider from dependencies via [Resolved].","Keep UseOnlineAPI => false if the test genuinely needs the DummyAPIAccess.","Gate any dummy-specific access behind `if (!UseOnlineAPI)`."],"exampleFix":"// before\nprotected override bool UseOnlineAPI => true;\nvar api = API; // throws\n\n// after\nprotected override bool UseOnlineAPI => true;\n[Resolved]\nprivate IAPIProvider api { get; set; }","handlingStrategy":"validation","validationCode":"IAPIProvider api = UseOnlineAPI\n    ? Dependencies.Get<IAPIProvider>()   // real OsuGameBase API\n    : API;                                // DummyAPIAccess\n// use `api`, never read OsuTestScene.API when UseOnlineAPI is true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When flipping UseOnlineAPI => true, audit every read of the inherited API property.","Prefer [Resolved] IAPIProvider over OsuTestScene.API in test scenes.","Gate dummy-API-specific helpers behind if (!UseOnlineAPI)."],"tags":["test-infra","api","online-api","di-resolver"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}