@@ -4,17 +4,30 @@ namespace ICTAce.FileHub.Client.Tests;
44
55public abstract class BaseTest : IDisposable
66{
7+ private const string TestBaseUrl = "https://localhost:5001/" ;
78 private bool _disposed ;
89
9- protected BunitContext TestContext { get ; private set ; }
10- protected Alias TestAlias { get ; private set ; }
11- protected Site TestSite { get ; private set ; }
12- protected Page TestPage { get ; private set ; }
10+ protected BunitContext TestContext { get ; private set ; } = null ! ;
11+ protected Alias TestAlias { get ; private set ; } = null ! ;
12+ protected Site TestSite { get ; private set ; } = null ! ;
13+ protected Page TestPage { get ; private set ; } = null ! ;
1314
1415 protected BaseTest ( )
16+ {
17+ InitializeTestContext ( ) ;
18+ RegisterServices ( ) ;
19+ InitializeCommonTestData ( ) ;
20+ }
21+
22+ private void InitializeTestContext ( )
1523 {
1624 TestContext = new ( ) ;
1725 TestContext . JSInterop . Mode = JSRuntimeMode . Loose ;
26+ SetupJsInterop ( ) ;
27+ }
28+
29+ private void SetupJsInterop ( )
30+ {
1831 TestContext . JSInterop . Setup < bool > ( "Oqtane.Interop.formValid" , _ => true ) . SetResult ( true ) ;
1932 TestContext . JSInterop . Setup < bool > ( "formValid" , _ => true ) . SetResult ( true ) ;
2033 TestContext . JSInterop . SetupVoid ( "Oqtane.Interop.setElementAttribute" , _ => true ) ;
@@ -31,7 +44,10 @@ protected BaseTest()
3144 TestContext . JSInterop . SetupVoid ( "Oqtane.Interop.includeMeta" , _ => true ) ;
3245 TestContext . JSInterop . Setup < int > ( "Oqtane.Interop.getScrollPosition" , _ => true ) . SetResult ( 0 ) ;
3346 TestContext . JSInterop . SetupVoid ( "Oqtane.Interop.scrollTo" , _ => true ) ;
47+ }
3448
49+ private void RegisterServices ( )
50+ {
3551 TestContext . Services . AddLocalization ( ) ;
3652 TestContext . Services . AddSingleton < Microsoft . Extensions . Localization . IStringLocalizerFactory , MockStringLocalizerFactory > ( ) ;
3753
@@ -65,17 +81,14 @@ protected BaseTest()
6581 TestContext . Services . AddScoped < IServiceScopeFactory > ( sp => sp . GetRequiredService < IServiceScopeFactory > ( ) ) ;
6682
6783 // Add HttpClient for Blazor components
68- TestContext . Services . AddScoped ( sp => new HttpClient { BaseAddress = new Uri ( "https://localhost:5001/" ) } ) ;
84+ TestContext . Services . AddScoped ( sp => new HttpClient { BaseAddress = new Uri ( TestBaseUrl ) } ) ;
6985
7086 // Add PageState mock for cascading parameter
7187 TestContext . Services . AddScoped ( _ => new Mocks . PageState
7288 {
7389 Action = "Index" ,
7490 QueryString = [ ]
7591 } ) ;
76-
77- // Initialize common test data
78- InitializeCommonTestData ( ) ;
7992 }
8093
8194 private void InitializeCommonTestData ( )
@@ -97,7 +110,9 @@ private void InitializeCommonTestData()
97110 LogoFileId = null ,
98111 FaviconFileId = null ,
99112 DefaultThemeType = "Test.Theme" ,
113+ #pragma warning disable CS0618 // Type or member is obsolete - Required for Oqtane compatibility
100114 DefaultLayoutType = "Test.Layout" ,
115+ #pragma warning restore CS0618
101116 DefaultContainerType = "Test.Container" ,
102117 } ;
103118
@@ -119,11 +134,11 @@ private void InitializeCommonTestData()
119134 } ;
120135 }
121136
122- protected Mocks . PageState CreatePageState ( string action , Dictionary < string , string > ? queryString = null )
137+ protected Mocks . PageState CreatePageState ( string action , IDictionary < string , string > ? queryString = null )
123138 => new Mocks . PageState
124139 {
125140 Action = action ,
126- QueryString = queryString ?? [ ] ,
141+ QueryString = queryString ?? new Dictionary < string , string > ( StringComparer . Ordinal ) ,
127142 Page = TestPage ,
128143 Alias = TestAlias ,
129144 Site = TestSite ,
@@ -159,8 +174,8 @@ protected Module CreateModuleState(int moduleId = 1, int pageId = 1, string titl
159174 PackageName = "ICTAce.FileHub" ,
160175 SiteId = 1
161176 } ,
162- PermissionList = new List < Permission >
163- {
177+ PermissionList =
178+ [
164179 new Permission
165180 {
166181 PermissionName = "View" ,
@@ -181,8 +196,8 @@ protected Module CreateModuleState(int moduleId = 1, int pageId = 1, string titl
181196 UserId = null ,
182197 IsAuthorized = true
183198 }
184- } ,
185- Settings = new ( )
199+ ] ,
200+ Settings = new Dictionary < string , string > ( StringComparer . Ordinal )
186201 } ;
187202
188203 protected virtual void Dispose ( bool disposing )
0 commit comments