Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Prefix your items with `(Template)` if the change is about the template and not
- Updated the Segoe MDL2 Assets font to fix an issue with the Flip View icons on Windows.
- Optimized the .NET workloads install process.
- Fixed the iOS application icon size.
- Added VM Disposal in Functional Tests.

## 3.8.X
- Updated from .NET 8 to .NET 9.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Threading;
using Chinook.StackNavigation;

namespace Chinook.SectionsNavigation;
Expand Down Expand Up @@ -51,4 +53,43 @@ public static IObservable<string> ObserveActiveSectionName(this ISectionsNavigat
var state = args.EventArgs.CurrentState;
return state.ActiveSection.Name;
});

/// <summary>
/// Clears the sections and sets the active section to <paramref name="activeSectionName"/> if not null or empty.
/// </summary>
/// <param name="sectionsNavigator"><see cref="ISectionsNavigator"/>.</param>
/// <param name="ct">The cancellation token.</param>
/// <param name="activeSectionName">The active section name to set after clearing them all.</param>
/// <remarks>
/// There are good chances that the page requesting this operation gets disposed, so you should use <see cref="CancellationToken.None"/>.
/// <br/>
/// If you don't want any section set as active don't provide <paramref name="activeSectionName"/>.
/// </remarks>
public static async Task ClearSections(this ISectionsNavigator sectionsNavigator, CancellationToken ct, string activeSectionName = default)
{
// Clearing those pages prevents bindings from updating in background.
// For better performance, it's better to re-create the pages when we'll need them.
foreach (var section in sectionsNavigator.State.Sections.Values)
{
await section.Clear(ct);
}

if (!string.IsNullOrEmpty(activeSectionName))
{
await sectionsNavigator.SetActiveSection(ct, activeSectionName);
}
}

/// <summary>
/// Closes all modals.
/// </summary>
/// <param name="sectionsNavigator"><see cref="ISectionsNavigator"/>.</param>
/// <param name="ct">The cancellation token.</param>
public static async Task CloseModals(this ISectionsNavigator sectionsNavigator, CancellationToken ct)
{
foreach (var modal in sectionsNavigator.State.Modals)
{
await sectionsNavigator.CloseModal(ct, SectionsNavigatorRequest.GetCloseModalRequest(modalName: modal.Name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using ApplicationTemplate.DataAccess;
using ApplicationTemplate.Tests;

namespace ApplicationTemplate.Tests;
namespace ForceUpdate;

/// <summary>
/// Tests for the forced update flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,16 @@ async Task IAsyncLifetime.InitializeAsync()
ViewModelBase.DefaultServiceProvider.Should().BeSameAs(_coreStartup.ServiceProvider, because: "We want the ViewModels of this test to use the services that we just initialized.");
}

Task IAsyncLifetime.DisposeAsync()
async Task IAsyncLifetime.DisposeAsync()
{
// To prevent scheduled tasks in view models from running after the test is completed.
// Once the test is finished, the view models should no longer be active.
// Therefore, we clear the stack navigator, which disposes of all view models.
await GetService<ISectionsNavigator>().CloseModals(CancellationToken.None);
await GetService<ISectionsNavigator>().ClearSections(CancellationToken.None);

_coreStartup.Dispose();
_backButtonSource.Dispose();
return Task.CompletedTask;
}

private sealed class FunctionalTestBackButtonSource : IBackButtonSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationTemplate.Tests;
using Xunit.Abstractions;

namespace ApplicationTemplate.Tests;
namespace Posts;

public sealed class EditPostPageViewModelShould : FunctionalTestBase
{
Expand Down