Skip to content

Commit

Permalink
Workaround interface mocks in TestSceneFirstRunSetupOverlay breakin…
Browse files Browse the repository at this point in the history
…g with hot reload
  • Loading branch information
frenzibyte committed May 10, 2022
1 parent a6674d8 commit 14a21e9
Showing 1 changed file with 32 additions and 4 deletions.
Expand Up @@ -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;
Expand All @@ -25,9 +27,9 @@ public class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
{
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;

Expand All @@ -37,8 +39,8 @@ public class TestSceneFirstRunSetupOverlay : OsuManualInputManagerTestScene
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]
Expand Down Expand Up @@ -196,5 +198,31 @@ public void TestResumeViaNotification()
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)
{
}
}
}
}

0 comments on commit 14a21e9

Please sign in to comment.