Skip to content

Commit 693317c

Browse files
committed
Refactor tests to use async store updates
- Updated various test methods to use async store update methods (UpdateAsync) instead of synchronous updates (Update) for better handling of asynchronous operations. - Changed test component inheritance from StoreComponent to StoreComponentWithUtilities to leverage additional utility methods. - Ensured that all relevant assertions and actions in tests are compatible with async execution. - Adjusted middleware and dependency injection tests to accommodate async patterns.
1 parent 347917d commit 693317c

33 files changed

Lines changed: 705 additions & 664 deletions

samples/EasyAppDev.Blazor.Store.Sample/EasyAppDev.Blazor.Store.Sample.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
<ProjectReference Include="..\..\src\EasyAppDev.Blazor.Store\EasyAppDev.Blazor.Store.csproj" />
1616
</ItemGroup>
1717

18+
<!-- Exclude diagnostics page in Release builds (diagnostics is DEBUG-only) -->
19+
<ItemGroup Condition="'$(Configuration)' != 'Debug'">
20+
<Content Remove="Pages/Diagnostics.razor" />
21+
<Compile Remove="Pages/Diagnostics.razor" />
22+
</ItemGroup>
23+
1824
</Project>

samples/EasyAppDev.Blazor.Store.Sample/Pages/ComprehensiveDemo.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@page "/comprehensive-demo"
2-
@inherits StoreComponent<ComprehensiveDemoState>
32
@using System.Collections.Immutable
43
@using EasyAppDev.Blazor.Store.AsyncActions
4+
@using EasyAppDev.Blazor.Store.Blazor
5+
@inherits StoreComponentWithUtilities<ComprehensiveDemoState>
56

67
<PageTitle>Comprehensive Demo - All Async Features</PageTitle>
78

samples/EasyAppDev.Blazor.Store.Sample/Pages/DebounceDemo.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/debounce-demo"
22
@using EasyAppDev.Blazor.Store.Sample.State
3-
@inherits StoreComponent<DebounceState>
3+
@using EasyAppDev.Blazor.Store.Blazor
4+
@inherits StoreComponentWithUtilities<DebounceState>
45

56
<PageTitle>Debounce & Throttle Demo</PageTitle>
67

samples/EasyAppDev.Blazor.Store.Sample/Pages/Diagnostics.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/diagnostics"
2+
@using EasyAppDev.Blazor.Store.Diagnostics.Components
23

34
<PageTitle>Store Diagnostics</PageTitle>
45

samples/EasyAppDev.Blazor.Store.Sample/Pages/ExecuteAsyncDemo.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@page "/execute-async-demo"
2-
@inherits StoreComponent<UserManagementState>
32
@using EasyAppDev.Blazor.Store.Sample.State
43
@using EasyAppDev.Blazor.Store.AsyncActions
4+
@using EasyAppDev.Blazor.Store.Blazor
5+
@inherits StoreComponentWithUtilities<UserManagementState>
56

67
<PageTitle>ExecuteAsync Demo</PageTitle>
78

samples/EasyAppDev.Blazor.Store.Sample/Pages/FormValidation.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/form-validation"
2-
@inherits StoreComponent<FormValidationState>
32
@using EasyAppDev.Blazor.Store.Sample.State
3+
@using EasyAppDev.Blazor.Store.Blazor
4+
@inherits StoreComponentWithUtilities<FormValidationState>
45

56
<PageTitle>Form Validation Demo</PageTitle>
67

samples/EasyAppDev.Blazor.Store.Sample/Pages/LazyLoadDemo.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/lazy-load-demo"
2-
@inherits StoreComponent<ProductCatalogState>
32
@using EasyAppDev.Blazor.Store.Sample.State
3+
@using EasyAppDev.Blazor.Store.Blazor
4+
@inherits StoreComponentWithUtilities<ProductCatalogState>
45

56
<PageTitle>LazyLoad Demo</PageTitle>
67

samples/EasyAppDev.Blazor.Store.Sample/Program.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using EasyAppDev.Blazor.Store.Blazor;
77
using EasyAppDev.Blazor.Store.Persistence;
88
using Microsoft.JSInterop;
9+
#if DEBUG
910
using EasyAppDev.Blazor.Store.Diagnostics;
11+
#endif
1012
using EasyAppDev.Blazor.Store.AsyncActions;
1113
using EasyAppDev.Blazor.Store.Utilities;
1214

@@ -16,8 +18,10 @@
1618

1719
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
1820

19-
// Register diagnostics service - only active in DEBUG builds
21+
// Register diagnostics service - only available in DEBUG builds
22+
#if DEBUG
2023
builder.Services.AddStoreDiagnostics();
24+
#endif
2125

2226
// Register utility services required by StoreComponent
2327
// Note: AddStoreUtilities() registers IDebounceManager, IThrottleManager, and ILazyCache
@@ -34,50 +38,44 @@
3438
// ============================================================================
3539
builder.Services.AddStore(
3640
new CounterState(0),
37-
(store, sp) => store.WithDefaults(sp, "Counter Store")
38-
.WithDiagnosticsIfAvailable(sp));
41+
(store, sp) => store.WithDefaults(sp, "Counter Store"));
3942

4043
// ============================================================================
4144
// Debounce Store - Demonstrates debounce and throttle functionality
4245
// ============================================================================
4346
builder.Services.AddStore(
4447
new DebounceState(),
45-
(store, sp) => store.WithDefaults(sp, "Debounce Store")
46-
.WithDiagnosticsIfAvailable(sp));
48+
(store, sp) => store.WithDefaults(sp, "Debounce Store"));
4749

4850
// ============================================================================
4951
// Todo Store - Demonstrates immutable collections (ImmutableList)
5052
// ============================================================================
5153
builder.Services.AddStore(
5254
TodoState.Empty,
53-
(store, sp) => store.WithDefaults(sp, "Todo Store")
54-
.WithDiagnosticsIfAvailable(sp));
55+
(store, sp) => store.WithDefaults(sp, "Todo Store"));
5556

5657
// ============================================================================
5758
// User Profile Store - Demonstrates async actions and loading states
5859
// ============================================================================
5960
builder.Services.AddStore(
6061
UserProfileState.Empty,
61-
(store, sp) => store.WithDefaults(sp, "User Profile Store")
62-
.WithDiagnosticsIfAvailable(sp));
62+
(store, sp) => store.WithDefaults(sp, "User Profile Store"));
6363

6464
// ============================================================================
6565
// AsyncData Demo Store - Demonstrates AsyncData<T> wrapper pattern
6666
// Simplifies async state from 20+ lines to 1 property!
6767
// ============================================================================
6868
builder.Services.AddStore(
6969
AsyncDataDemoState.Initial,
70-
(store, sp) => store.WithDefaults(sp, "AsyncData Demo Store")
71-
.WithDiagnosticsIfAvailable(sp));
70+
(store, sp) => store.WithDefaults(sp, "AsyncData Demo Store"));
7271

7372
// ============================================================================
7473
// User Management Store - Demonstrates ExecuteAsync helper
7574
// Automatic error handling - reduces try-catch from 12+ lines to 5 lines!
7675
// ============================================================================
7776
builder.Services.AddStore(
7877
UserManagementState.Initial,
79-
(store, sp) => store.WithDefaults(sp, "User Management Store")
80-
.WithDiagnosticsIfAvailable(sp));
78+
(store, sp) => store.WithDefaults(sp, "User Management Store"));
8179

8280
// ============================================================================
8381
// Shopping Cart Store - Demonstrates persistence with LocalStorage
@@ -87,8 +85,7 @@
8785
builder.Services.AddStore(
8886
ShoppingCartState.Empty,
8987
(store, sp) => store.WithDefaults(sp, "Shopping Cart Store")
90-
.WithPersistence(sp, "shopping-cart-state")
91-
.WithDiagnosticsIfAvailable(sp));
88+
.WithPersistence(sp, "shopping-cart-state"));
9289

9390
// ============================================================================
9491
// Theme Store - Demonstrates selector optimization with SelectorStoreComponent
@@ -98,17 +95,15 @@
9895
builder.Services.AddStore(
9996
ThemeState.Default,
10097
(store, sp) => store.WithDefaults(sp, "Theme Store")
101-
.WithPersistence(sp, "theme-state")
102-
.WithDiagnosticsIfAvailable(sp));
98+
.WithPersistence(sp, "theme-state"));
10399

104100
// ============================================================================
105101
// Product Catalog Store - Demonstrates LazyLoad with caching
106102
// Automatic caching with request deduplication - no manual cache management!
107103
// ============================================================================
108104
builder.Services.AddStore(
109105
new ProductCatalogState(),
110-
(store, sp) => store.WithDefaults(sp, "Product Catalog Store")
111-
.WithDiagnosticsIfAvailable(sp));
106+
(store, sp) => store.WithDefaults(sp, "Product Catalog Store"));
112107

113108
// ============================================================================
114109
// Comprehensive Demo Store - Demonstrates ALL async helpers working together
@@ -117,8 +112,7 @@
117112
// ============================================================================
118113
builder.Services.AddStore(
119114
ComprehensiveDemoState.Initial,
120-
(store, sp) => store.WithDefaults(sp, "Comprehensive Demo Store")
121-
.WithDiagnosticsIfAvailable(sp));
115+
(store, sp) => store.WithDefaults(sp, "Comprehensive Demo Store"));
122116

123117
// ============================================================================
124118
// Form Validation Store - Demonstrates form state management and validation
@@ -127,8 +121,7 @@
127121
// ============================================================================
128122
builder.Services.AddStore(
129123
new FormValidationState(),
130-
(store, sp) => store.WithDefaults(sp, "Form Validation Store")
131-
.WithDiagnosticsIfAvailable(sp));
124+
(store, sp) => store.WithDefaults(sp, "Form Validation Store"));
132125

133126
// ============================================================================
134127
// Cross-Store Demo Stores - Demonstrates Phase 1 updates
@@ -137,12 +130,10 @@
137130
// ============================================================================
138131
builder.Services.AddStore(
139132
AuthDemoState.Initial,
140-
(store, sp) => store.WithDefaults(sp, "Auth Demo Store")
141-
.WithDiagnosticsIfAvailable(sp));
133+
(store, sp) => store.WithDefaults(sp, "Auth Demo Store"));
142134

143135
builder.Services.AddStore(
144136
CartDemoState.Empty,
145-
(store, sp) => store.WithDefaults(sp, "Cart Demo Store")
146-
.WithDiagnosticsIfAvailable(sp));
137+
(store, sp) => store.WithDefaults(sp, "Cart Demo Store"));
147138

148139
await builder.Build().RunAsync();

samples/EasyAppDev.Blazor.Store.Sample/_Imports.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@
1212
@using EasyAppDev.Blazor.Store.Core
1313
@using EasyAppDev.Blazor.Store.Blazor
1414
@using EasyAppDev.Blazor.Store.Sample.State
15-
@using EasyAppDev.Blazor.Store.Diagnostics.Components

src/EasyAppDev.Blazor.Store/Blazor/SelectorStoreComponent.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,6 @@ public abstract class SelectorStoreComponent<TState> : ComponentBase, IDisposabl
105105
/// </remarks>
106106
protected abstract object SelectState(TState state);
107107

108-
/// <summary>
109-
/// Updates the state using the provided updater function.
110-
/// </summary>
111-
/// <param name="updater">Function that transforms current state to new state.</param>
112-
/// <param name="action">Optional action name for debugging.</param>
113-
protected void UpdateState(Func<TState, TState> updater, string? action = null)
114-
{
115-
Store.Update(updater, action);
116-
}
117-
118-
/// <summary>
119-
/// Updates the state asynchronously.
120-
/// </summary>
121-
/// <param name="updater">Function that transforms current state to new state.</param>
122-
/// <param name="action">Optional action name for debugging.</param>
123-
protected Task UpdateStateAsync(Func<TState, TState> updater, string? action = null)
124-
{
125-
return Store.UpdateAsync(updater, action);
126-
}
127-
128-
/// <summary>
129-
/// Updates the state asynchronously using an async updater.
130-
/// </summary>
131-
/// <param name="asyncUpdater">Async function that transforms state.</param>
132-
/// <param name="action">Optional action name for debugging.</param>
133-
protected Task UpdateStateAsync(Func<TState, Task<TState>> asyncUpdater, string? action = null)
134-
{
135-
return Store.UpdateAsync(asyncUpdater, action);
136-
}
137-
138108
/// <summary>
139109
/// Updates the state using a transformation function (Zustand-style).
140110
/// </summary>

0 commit comments

Comments
 (0)