@@ -10,101 +10,87 @@ namespace eShopOnContainers.UnitTests
1010{
1111 public class CatalogViewModelTests
1212 {
13+ public CatalogViewModelTests ( )
14+ {
15+ ViewModelLocator . RegisterDependencies ( true ) ;
16+ }
17+
1318 [ Fact ]
1419 public void AddCatalogItemCommandIsNotNullTest ( )
1520 {
1621 var catalogService = new CatalogMockService ( ) ;
17- ViewModelLocator . RegisterDependencies ( true ) ;
1822 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
19-
2023 Assert . NotNull ( catalogViewModel . AddCatalogItemCommand ) ;
2124 }
2225
2326 [ Fact ]
2427 public void FilterCommandIsNotNullTest ( )
2528 {
2629 var catalogService = new CatalogMockService ( ) ;
27- ViewModelLocator . RegisterDependencies ( true ) ;
2830 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
29-
3031 Assert . NotNull ( catalogViewModel . FilterCommand ) ;
3132 }
3233
3334 [ Fact ]
3435 public void ClearFilterCommandIsNotNullTest ( )
3536 {
3637 var catalogService = new CatalogMockService ( ) ;
37- ViewModelLocator . RegisterDependencies ( true ) ;
3838 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
39-
4039 Assert . NotNull ( catalogViewModel . ClearFilterCommand ) ;
4140 }
4241
4342 [ Fact ]
4443 public void ProductsPropertyIsNullWhenViewModelInstantiatedTest ( )
4544 {
4645 var catalogService = new CatalogMockService ( ) ;
47- ViewModelLocator . RegisterDependencies ( true ) ;
4846 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
49-
5047 Assert . Null ( catalogViewModel . Products ) ;
5148 }
5249
5350 [ Fact ]
5451 public void BrandsPropertyuIsNullWhenViewModelInstantiatedTest ( )
5552 {
5653 var catalogService = new CatalogMockService ( ) ;
57- ViewModelLocator . RegisterDependencies ( true ) ;
5854 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
59-
6055 Assert . Null ( catalogViewModel . Brands ) ;
6156 }
6257
6358 [ Fact ]
6459 public void BrandPropertyIsNullWhenViewModelInstantiatedTest ( )
6560 {
6661 var catalogService = new CatalogMockService ( ) ;
67- ViewModelLocator . RegisterDependencies ( true ) ;
6862 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
69-
7063 Assert . Null ( catalogViewModel . Brand ) ;
7164 }
7265
7366 [ Fact ]
7467 public void TypesPropertyIsNullWhenViewModelInstantiatedTest ( )
7568 {
7669 var catalogService = new CatalogMockService ( ) ;
77- ViewModelLocator . RegisterDependencies ( true ) ;
7870 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
79-
8071 Assert . Null ( catalogViewModel . Types ) ;
8172 }
8273
8374 [ Fact ]
8475 public void TypePropertyIsNullWhenViewModelInstantiatedTest ( )
8576 {
8677 var catalogService = new CatalogMockService ( ) ;
87- ViewModelLocator . RegisterDependencies ( true ) ;
8878 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
89-
9079 Assert . Null ( catalogViewModel . Type ) ;
9180 }
9281
9382 [ Fact ]
9483 public void IsFilterPropertyIsFalseWhenViewModelInstantiatedTest ( )
9584 {
9685 var catalogService = new CatalogMockService ( ) ;
97- ViewModelLocator . RegisterDependencies ( true ) ;
9886 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
99-
10087 Assert . False ( catalogViewModel . IsFilter ) ;
10188 }
10289
10390 [ Fact ]
10491 public async Task ProductsPropertyIsNotNullAfterViewModelInitializationTest ( )
10592 {
10693 var catalogService = new CatalogMockService ( ) ;
107- ViewModelLocator . RegisterDependencies ( true ) ;
10894 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
10995
11096 await catalogViewModel . InitializeAsync ( null ) ;
@@ -116,7 +102,6 @@ public async Task ProductsPropertyIsNotNullAfterViewModelInitializationTest()
116102 public async Task BrandsPropertyIsNotNullAfterViewModelInitializationTest ( )
117103 {
118104 var catalogService = new CatalogMockService ( ) ;
119- ViewModelLocator . RegisterDependencies ( true ) ;
120105 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
121106
122107 await catalogViewModel . InitializeAsync ( null ) ;
@@ -128,7 +113,6 @@ public async Task BrandsPropertyIsNotNullAfterViewModelInitializationTest()
128113 public async Task TypesPropertyIsNotNullAfterViewModelInitializationTest ( )
129114 {
130115 var catalogService = new CatalogMockService ( ) ;
131- ViewModelLocator . RegisterDependencies ( true ) ;
132116 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
133117
134118 await catalogViewModel . InitializeAsync ( null ) ;
@@ -140,9 +124,7 @@ public async Task TypesPropertyIsNotNullAfterViewModelInitializationTest()
140124 public async Task SettingProductsPropertyShouldRaisePropertyChanged ( )
141125 {
142126 bool invoked = false ;
143-
144127 var catalogService = new CatalogMockService ( ) ;
145- ViewModelLocator . RegisterDependencies ( true ) ;
146128 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
147129
148130 catalogViewModel . PropertyChanged += ( sender , e ) =>
@@ -159,9 +141,7 @@ public async Task SettingProductsPropertyShouldRaisePropertyChanged()
159141 public async Task SettingBrandsPropertyShouldRaisePropertyChanged ( )
160142 {
161143 bool invoked = false ;
162-
163144 var catalogService = new CatalogMockService ( ) ;
164- ViewModelLocator . RegisterDependencies ( true ) ;
165145 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
166146
167147 catalogViewModel . PropertyChanged += ( sender , e ) =>
@@ -178,9 +158,7 @@ public async Task SettingBrandsPropertyShouldRaisePropertyChanged()
178158 public async Task SettingTypesPropertyShouldRaisePropertyChanged ( )
179159 {
180160 bool invoked = false ;
181-
182161 var catalogService = new CatalogMockService ( ) ;
183- ViewModelLocator . RegisterDependencies ( true ) ;
184162 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
185163
186164 catalogViewModel . PropertyChanged += ( sender , e ) =>
@@ -198,7 +176,6 @@ public void AddCatalogItemCommandSendsAddProductMessageTest()
198176 {
199177 bool messageReceived = false ;
200178 var catalogService = new CatalogMockService ( ) ;
201- ViewModelLocator . RegisterDependencies ( true ) ;
202179 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
203180
204181 Xamarin . Forms . MessagingCenter . Subscribe < CatalogViewModel , CatalogItem > ( this , MessageKeys . AddProduct , ( sender , arg ) =>
@@ -215,7 +192,6 @@ public async Task FilterCommandSendsFilterMessageTest()
215192 {
216193 bool messageReceived = false ;
217194 var catalogService = new CatalogMockService ( ) ;
218- ViewModelLocator . RegisterDependencies ( true ) ;
219195 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
220196 await catalogViewModel . InitializeAsync ( null ) ;
221197 catalogViewModel . Brand = catalogViewModel . Brands . FirstOrDefault ( ) ;
@@ -234,7 +210,6 @@ public async Task FilterCommandSendsFilterMessageTest()
234210 public async Task ClearFilterCommandResetsPropertiesTest ( )
235211 {
236212 var catalogService = new CatalogMockService ( ) ;
237- ViewModelLocator . RegisterDependencies ( true ) ;
238213 var catalogViewModel = new CatalogViewModel ( catalogService ) ;
239214
240215 await catalogViewModel . InitializeAsync ( null ) ;
0 commit comments