Merge pull request #18206 from frenzibyte/fix-first-run-hot-reload

Workaround interface mocks in `TestSceneFirstRunSetupOverlay` breaking with hot reload
This commit is contained in:
Dean Herbert 2022-05-10 18:12:50 +09:00 committed by GitHub
commit 09613c9e18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Framework.Testing;
@ -25,9 +27,9 @@ namespace osu.Game.Tests.Visual.UserInterface
{
private FirstRunSetupOverlay overlay;
private readonly Mock<IPerformFromScreenRunner> performer = new Mock<IPerformFromScreenRunner>();
private readonly Mock<TestPerformerFromScreenRunner> performer = new Mock<TestPerformerFromScreenRunner>();
private readonly Mock<INotificationOverlay> notificationOverlay = new Mock<INotificationOverlay>();
private readonly Mock<TestNotificationOverlay> notificationOverlay = new Mock<TestNotificationOverlay>();
private Notification lastNotification;
@ -37,8 +39,8 @@ namespace osu.Game.Tests.Visual.UserInterface
private void load()
{
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
Dependencies.CacheAs(performer.Object);
Dependencies.CacheAs(notificationOverlay.Object);
Dependencies.CacheAs<IPerformFromScreenRunner>(performer.Object);
Dependencies.CacheAs<INotificationOverlay>(notificationOverlay.Object);
}
[SetUpSteps]
@ -196,5 +198,31 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("overlay shown", () => overlay.State.Value == Visibility.Visible);
AddAssert("is resumed", () => overlay.CurrentScreen is ScreenBeatmaps);
}
// interface mocks break hot reload, mocking this stub implementation instead works around it.
// see: https://github.com/moq/moq4/issues/1252
[UsedImplicitly]
public class TestNotificationOverlay : INotificationOverlay
{
public virtual void Post(Notification notification)
{
}
public virtual void Hide()
{
}
public virtual IBindable<int> UnreadCount => null;
}
// interface mocks break hot reload, mocking this stub implementation instead works around it.
// see: https://github.com/moq/moq4/issues/1252
[UsedImplicitly]
public class TestPerformerFromScreenRunner : IPerformFromScreenRunner
{
public virtual void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null)
{
}
}
}
}