File tree Expand file tree Collapse file tree
Client.Integration.Tests/Store Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,6 @@ public partial class RouteState : State<RouteState>
99 {
1010 public string Route { get ; private set ; }
1111
12- protected override void Initialize ( ) { }
12+ public override void Initialize ( ) { }
1313 }
1414}
Original file line number Diff line number Diff line change 66 public interface IState
77 {
88 Guid Guid { get ; }
9+ void Initialize ( ) ;
910 }
1011
1112 public interface IState < TState > : IState
Original file line number Diff line number Diff line change 77
88 public abstract class State < TState > : IState < TState >
99 {
10- public State ( )
11- {
12- Initialize ( ) ;
13- }
1410
1511 [ IgnoreDataMember ]
1612 public Guid Guid { get ; protected set ; } = Guid . NewGuid ( ) ;
@@ -40,7 +36,6 @@ public void ThrowIfNotTestAssembly(Assembly aAssembly)
4036 /// <summary>
4137 /// Override this to Set the initial state
4238 /// </summary>
43- protected abstract void Initialize ( ) ;
44-
39+ public abstract void Initialize ( ) ;
4540 }
4641}
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ public object GetState(Type aType)
7676 Logger . LogDebug ( $ "{ GetType ( ) . Name } : Creating State of type: { typeName } ") ;
7777 state = ( IState ) ServiceProvider . GetService ( aType ) ;
7878 if ( state == null ) throw new NullReferenceException ( "state is null" ) ;
79- // state = (IState)Activator.CreateInstance(aType );
79+ state . Initialize ( ) ;
8080 States . Add ( typeName , state ) ;
8181 }
8282 else
Original file line number Diff line number Diff line change @@ -49,5 +49,14 @@ public void ShouldLoadStatesFromJson()
4949 weatherForecastsState . WeatherForecasts [ 0 ] . Date . Minute . ShouldBe ( 29 ) ;
5050 weatherForecastsState . WeatherForecasts [ 0 ] . Date . Second . ShouldBe ( 54 ) ;
5151 }
52+
53+ /// <summary>
54+ /// WeatherForecatesState will throw an exception if items initialized in the constructor are null.
55+ /// </summary>
56+ public void ShouldInitializeStateAfterConstruction ( )
57+ {
58+ WeatherForecastsState state = Store . GetState < WeatherForecastsState > ( ) ;
59+ state . ShouldNotBeNull ( ) ;
60+ }
5261 }
5362}
Original file line number Diff line number Diff line change @@ -10,6 +10,6 @@ internal partial class ApplicationState : State<ApplicationState>
1010
1111 public ApplicationState ( ) { }
1212
13- protected override void Initialize ( ) => Name = "Blazor State Demo Application" ;
13+ public override void Initialize ( ) => Name = "Blazor State Demo Application" ;
1414 }
1515}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public CloneTestState() { }
1313 /// <summary>
1414 /// Set the Initial State
1515 /// </summary>
16- protected override void Initialize ( ) => Count = 3 ;
16+ public override void Initialize ( ) => Count = 3 ;
1717 public object Clone ( ) => new CloneTestState { Count = 42 } ;
1818 }
1919}
Original file line number Diff line number Diff line change @@ -12,6 +12,6 @@ public CounterState() { }
1212 /// <summary>
1313 /// Set the Initial State
1414 /// </summary>
15- protected override void Initialize ( ) => Count = 3 ;
15+ public override void Initialize ( ) => Count = 3 ;
1616 }
1717}
Original file line number Diff line number Diff line change @@ -13,6 +13,6 @@ public EventStreamState()
1313 _Events = new List < string > ( ) ;
1414 }
1515
16- protected override void Initialize ( ) { }
16+ public override void Initialize ( ) { }
1717 }
1818}
Original file line number Diff line number Diff line change @@ -15,6 +15,18 @@ public WeatherForecastsState()
1515 _WeatherForecasts = new List < WeatherForecastDto > ( ) ;
1616 }
1717
18- protected override void Initialize ( ) { }
18+
19+ /// <summary>
20+ ///
21+ /// </summary>
22+ /// <remarks>used to test that constructor is complete before Initialize is called</remarks>
23+ public override void Initialize ( )
24+ {
25+ if ( _WeatherForecasts is null )
26+ {
27+ throw new System . ArgumentNullException ( nameof ( _WeatherForecasts ) ) ;
28+ }
29+
30+ }
1931 }
2032}
You can’t perform that action at this time.
0 commit comments