logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityHudHostComponentTests

    PlayMode tests for the two pieces the game uses that the preview never touches: the widget-context constructor of HudRenderResources, and UnityHudHostComponent driving a HUD through a service locator.

    Inheritance
    object
    UnityHudHostComponentTests
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.UnityGameUi.Tests.Infrastructure
    Assembly: Tests.dll
    Syntax
    public class UnityHudHostComponentTests
    Remarks

    Neither needs Serenity booted, which is what made them look untestable at first glance. SerenityUiContext takes an IServiceLocator — an interface — and the host resolves its locator from a private field before falling back to the static bridge, so both can be handed fakes.

    Constructors

    UnityHudHostComponentTests()

    Declaration
    public UnityHudHostComponentTests()

    Methods

    Clear_RemovesEverythingItBuilt()

    Declaration
    public IEnumerator Clear_RemovesEverythingItBuilt()
    Returns
    Type Description
    IEnumerator

    Clear_ResetsHiddenElementState()

    Declaration
    public IEnumerator Clear_ResetsHiddenElementState()
    Returns
    Type Description
    IEnumerator

    Dispatch_HideHudElementSignal_HidesOnlyThatElement()

    Declaration
    public IEnumerator Dispatch_HideHudElementSignal_HidesOnlyThatElement()
    Returns
    Type Description
    IEnumerator

    Dispatch_HideHudElementSignal_WithMismatchedHudId_IsIgnored()

    Declaration
    public IEnumerator Dispatch_HideHudElementSignal_WithMismatchedHudId_IsIgnored()
    Returns
    Type Description
    IEnumerator

    Dispatch_HideHudElementSignal_WithNoHudShown_IsIgnored()

    Declaration
    public IEnumerator Dispatch_HideHudElementSignal_WithNoHudShown_IsIgnored()
    Returns
    Type Description
    IEnumerator

    Dispatch_ShowHudElementSignal_AfterHide_ReShowsOnlyThatElement()

    Declaration
    public IEnumerator Dispatch_ShowHudElementSignal_AfterHide_ReShowsOnlyThatElement()
    Returns
    Type Description
    IEnumerator

    HiddenElement_DoesNotLeakToADifferentHudSharingTheSameElementId()

    Regression test for the cross-HUD leak the fresh review caught: hidden state used to be a flat element-id set with no HUD component, so hiding "ammo" on one HUD silently started a DIFFERENT HUD's own "ammo" element hidden too, the first time it was built.

    Declaration
    public IEnumerator HiddenElement_DoesNotLeakToADifferentHudSharingTheSameElementId()
    Returns
    Type Description
    IEnumerator

    HiddenElement_StaysHiddenAcrossHideThenShowSameHud()

    Declaration
    public IEnumerator HiddenElement_StaysHiddenAcrossHideThenShowSameHud()
    Returns
    Type Description
    IEnumerator

    HiddenElement_StaysHiddenAcrossSwitchingHudsAndBack()

    Declaration
    public IEnumerator HiddenElement_StaysHiddenAcrossSwitchingHudsAndBack()
    Returns
    Type Description
    IEnumerator

    HideHud_ThenShowAgain_RebuildsWithoutDuplicating()

    Teardown goes through Object.Destroy, which in play mode is deferred to the end of the frame. Asserting on the object graph in the same frame reads the objects as still there — a test written that way fails against correct code, or worse, passes by comparing two equally stale counts.

    Declaration
    public IEnumerator HideHud_ThenShowAgain_RebuildsWithoutDuplicating()
    Returns
    Type Description
    IEnumerator

    HudRenderResources_FromANullContext_DegradesInsteadOfThrowing()

    Declaration
    public void HudRenderResources_FromANullContext_DegradesInsteadOfThrowing()

    HudRenderResources_FromAWidgetContext_ResolvesTheThemeTextStyle()

    The constructor the game uses, as opposed to the theme-only one the preview uses. Both resolve the theme's lettering, but only this one goes through the widget context — so following the theme could have worked in the preview and silently not in the game.

    Declaration
    public void HudRenderResources_FromAWidgetContext_ResolvesTheThemeTextStyle()

    HudRenderResources_FromAnEmptyContext_DegradesInsteadOfThrowing()

    Declaration
    public void HudRenderResources_FromAnEmptyContext_DegradesInsteadOfThrowing()

    RegisterHud_WithNull_DoesNotThrow()

    Declaration
    public void RegisterHud_WithNull_DoesNotThrow()

    SetUp()

    Declaration
    public void SetUp()

    ShowHud_AuthoredHudTakesPrecedenceOverProvider_ProviderIsNeverAsked()

    Declaration
    public void ShowHud_AuthoredHudTakesPrecedenceOverProvider_ProviderIsNeverAsked()

    ShowHud_BuildsTheElementsAndBindsThemToLiveServices()

    Declaration
    public void ShowHud_BuildsTheElementsAndBindsThemToLiveServices()

    ShowHud_NoProviderRegistered_DoesNotThrowAndStillWarns()

    Declaration
    public void ShowHud_NoProviderRegistered_DoesNotThrowAndStillWarns()

    ShowHud_ProviderOnlyId_BuildsTheHud()

    The regression test: with nothing scene-authored at all, a HUD known only to the provider must still build — this is the fully no-code flow (HUD Builder → generated ShowTrigger → play) that silently showed nothing before UnityHudHostComponent ever consulted a provider.

    Declaration
    public void ShowHud_ProviderOnlyId_BuildsTheHud()

    ShowHud_ProviderResolvedByGuid_IsAskedOnlyOnceAcrossRepeatedShowsByGuid()

    Regression test: the cached-authored lookup used to match only Id, so a HUD resolved and shown by Guid re-queried the provider on every repeat show even though it was already cached.

    Declaration
    public void ShowHud_ProviderResolvedByGuid_IsAskedOnlyOnceAcrossRepeatedShowsByGuid()

    ShowHud_ProviderResolvedId_IsAskedOnlyOnceAcrossRepeatedShows()

    Declaration
    public void ShowHud_ProviderResolvedId_IsAskedOnlyOnceAcrossRepeatedShows()

    ShowHud_TwoDifferentUnresolvableIds_WarnsTwice()

    Declaration
    public void ShowHud_TwoDifferentUnresolvableIds_WarnsTwice()

    ShowHud_UnresolvableId_WarnsExactlyOnceAcrossRepeatedCalls()

    Declaration
    public void ShowHud_UnresolvableId_WarnsExactlyOnceAcrossRepeatedCalls()

    ShowHud_WithAnUnknownId_DoesNotThrow()

    Declaration
    public void ShowHud_WithAnUnknownId_DoesNotThrow()

    ShowHud_WithNoLocatorAtAll_DoesNotThrow()

    Declaration
    public void ShowHud_WithNoLocatorAtAll_DoesNotThrow()

    TearDown()

    Declaration
    public void TearDown()

    ValueTrigger_OneWatchedElement_FansOutToMultipleOwners()

    Declaration
    public IEnumerator ValueTrigger_OneWatchedElement_FansOutToMultipleOwners()
    Returns
    Type Description
    IEnumerator

    ValueTrigger_RebuildingTheHud_DoesNotLeakOldSubscriptionsOrDoubleFire()

    Regression guard for a rebuild leaking stale watcher registrations: if TearDownElements ever stopped clearing _animationValueWatchers, a second build would ADD a second (owner, entry) pair for the new "healthFlash" view on top of the first (torn-down) one, and a single Points change would fire twice instead of once.

    Declaration
    public IEnumerator ValueTrigger_RebuildingTheHud_DoesNotLeakOldSubscriptionsOrDoubleFire()
    Returns
    Type Description
    IEnumerator

    ValueTrigger_WatchingAnotherElement_FiresOnThatElementsChange_NotItsOwn()

    Declaration
    public IEnumerator ValueTrigger_WatchingAnotherElement_FiresOnThatElementsChange_NotItsOwn()
    Returns
    Type Description
    IEnumerator

    ValueTrigger_WithUnresolvableWatchedId_BuildsWithoutThrowing()

    Declaration
    public void ValueTrigger_WithUnresolvableWatchedId_BuildsWithoutThrowing()

    ValueTrigger_WithUnresolvableWatchedId_WarnsOnlyOnceAcrossRebuilds()

    Declaration
    public void ValueTrigger_WithUnresolvableWatchedId_WarnsOnlyOnceAcrossRebuilds()
    In this article
    © 2026 Serenity. All Rights Reserved