1+ using Logic ;
2+ using Model ;
3+ using System . Collections . ObjectModel ;
4+ using ViewModel ;
5+
6+ namespace ViewModelTest
7+ {
8+ public class MainWindowViewModelTests
9+ {
10+ private class ModelMockClass : ModelAbstractAPI
11+ {
12+ public int StartSimulationCallCount { get ; set ; }
13+ public int StopSimulationCallCount { get ; set ; }
14+ public int CreateBallsCallCount { get ; set ; }
15+ public override int Width => 500 ;
16+ public override int Height => 500 ;
17+
18+ public override ObservableCollection < BallLogic > createBalls ( int amount , int radius )
19+ {
20+ CreateBallsCallCount ++ ;
21+ return new ObservableCollection < BallLogic > ( ) ;
22+ }
23+
24+ public override void StartSimulation ( )
25+ {
26+ StartSimulationCallCount ++ ;
27+ }
28+
29+ public override void StopSimulation ( )
30+ {
31+ StopSimulationCallCount ++ ;
32+ }
33+ }
34+
35+ [ Test ]
36+ public void CreateHandler_StartsSimulationTest ( )
37+ {
38+ var mockModel = new ModelMockClass ( ) ;
39+ var viewModel = new MainWindowViewModel ( mockModel ) ;
40+ viewModel . ballsAmount = 5 ;
41+
42+ viewModel . CreateHandler ( ) ;
43+
44+ Assert . AreEqual ( 1 , mockModel . CreateBallsCallCount ) ;
45+ Assert . AreEqual ( 1 , mockModel . StartSimulationCallCount ) ;
46+ }
47+
48+ [ Test ]
49+ public void StopHandler_StopsSimulationTest ( )
50+ {
51+ var mockModel = new ModelMockClass ( ) ;
52+ var viewModel = new MainWindowViewModel ( mockModel ) ;
53+
54+ viewModel . StopHandler ( ) ;
55+
56+ Assert . AreEqual ( 1 , mockModel . StopSimulationCallCount ) ;
57+ }
58+
59+ [ Test ]
60+ public void BallsGroup_Setter_RaisesPropertyChangedEventTest ( )
61+ {
62+ var mockModel = new ModelMockClass ( ) ;
63+ var viewModel = new MainWindowViewModel ( mockModel ) ;
64+
65+ bool eventRaised = false ;
66+ viewModel . PropertyChanged += ( sender , args ) =>
67+ {
68+ if ( args . PropertyName == "ballsGroup" )
69+ eventRaised = true ;
70+ } ;
71+
72+ viewModel . ballsGroup = new ObservableCollection < BallLogic > ( ) ;
73+ Assert . IsTrue ( eventRaised ) ;
74+ }
75+
76+ [ Test ]
77+ public void BallsAmount_Setter_RaisesPropertyChangedEventTest ( )
78+ {
79+ var mockModel = new ModelMockClass ( ) ;
80+ var viewModel = new MainWindowViewModel ( mockModel ) ;
81+
82+ bool eventRaised = false ;
83+ viewModel . PropertyChanged += ( sender , args ) =>
84+ {
85+ if ( args . PropertyName == "ballsAmount" )
86+ eventRaised = true ;
87+ } ;
88+
89+ viewModel . ballsAmount = 10 ;
90+ Assert . IsTrue ( eventRaised ) ;
91+ }
92+ }
93+ }
0 commit comments