File tree Expand file tree Collapse file tree 5 files changed +68
-3
lines changed Expand file tree Collapse file tree 5 files changed +68
-3
lines changed Original file line number Diff line number Diff line change @@ -40,5 +40,20 @@ public void getTableDataTest()
4040 Assert . AreEqual ( width , tableData . Width ) ;
4141 Assert . AreEqual ( height , tableData . Height ) ;
4242 }
43+
44+ [ Test ]
45+ public async Task LogDiagnosticDataAsyncTest ( )
46+ {
47+ var mockDataAPI = new MockDataAPI ( ) ;
48+ string testData = "{\" Event\" :\" Test\" }" ;
49+
50+ await mockDataAPI . LogDiagnosticDataAsync ( testData ) ;
51+
52+ List < string > loggedData = mockDataAPI . GetLoggedData ( ) ;
53+
54+ Assert . IsNotNull ( loggedData ) ;
55+ Assert . AreEqual ( 1 , loggedData . Count ) ;
56+ Assert . AreEqual ( testData , loggedData . First ( ) ) ;
57+ }
4358 }
4459}
Original file line number Diff line number Diff line change 1+ using Data ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
5+ using System . Text ;
6+ using System . Threading . Tasks ;
7+
8+ namespace DataTest
9+ {
10+ public class MockDataAPI : DataAPI
11+ {
12+ private readonly List < string > _loggedData = new List < string > ( ) ;
13+ private readonly SemaphoreSlim _fileSemaphore = new SemaphoreSlim ( 1 , 1 ) ;
14+
15+ public override async Task LogDiagnosticDataAsync ( string data )
16+ {
17+ await _fileSemaphore . WaitAsync ( ) ;
18+ try
19+ {
20+ _loggedData . Add ( data ) ;
21+ }
22+ finally
23+ {
24+ _fileSemaphore . Release ( ) ;
25+ }
26+ }
27+
28+ public List < string > GetLoggedData ( ) => _loggedData ;
29+ }
30+ }
Original file line number Diff line number Diff line change @@ -16,11 +16,13 @@ public class LogicAPI : LogicAbstractAPI
1616 public override Table table { get ; }
1717 public override ObservableCollection < BallLogic > balls { get ; } = new ObservableCollection < BallLogic > ( ) ;
1818
19- public LogicAPI ( )
19+ public LogicAPI ( ) : this ( DataAPI . createDataAPI ( ) ) { }
20+
21+ public LogicAPI ( DataAPI dataAPI )
2022 {
21- _dataAPI = DataAPI . createDataAPI ( ) ;
23+ _dataAPI = dataAPI ;
2224 table = _dataAPI . getTableData ( 500 , 500 ) ;
23- BallLogic . SetTable ( table ) ;
25+ BallLogic . SetTable ( table ) ;
2426 }
2527
2628 public override void RunSimulation ( )
Original file line number Diff line number Diff line change 22using Data ;
33using System . Collections . ObjectModel ;
44using System . Numerics ;
5+ using DataTest ;
56
67namespace LogicTest
78{
@@ -86,5 +87,21 @@ public void createDeleteBallsTest()
8687 _logicAPI . deleteBalls ( ) ;
8788 Assert . AreEqual ( 0 , _logicAPI . balls . Count ) ;
8889 }
90+
91+ [ Test ]
92+ public async Task RunSimulation_LogDataTest ( )
93+ {
94+ var mockDataAPI = new MockDataAPI ( ) ;
95+ var logicAPI = new LogicAPI ( mockDataAPI ) ;
96+ logicAPI . createBalls ( 2 , 10 ) ;
97+
98+ logicAPI . RunSimulation ( ) ;
99+ await Task . Delay ( 100 ) ;
100+ logicAPI . StopSimulation ( ) ;
101+
102+ List < string > loggedData = mockDataAPI . GetLoggedData ( ) ;
103+
104+ Assert . IsNotNull ( loggedData ) ;
105+ }
89106 }
90107}
Original file line number Diff line number Diff line change 1818 </ItemGroup >
1919
2020 <ItemGroup >
21+ <ProjectReference Include =" ..\DataTest\DataTest.csproj" />
2122 <ProjectReference Include =" ..\Data\Data.csproj" />
2223 <ProjectReference Include =" ..\Logic\Logic.csproj" />
2324 </ItemGroup >
You can’t perform that action at this time.
0 commit comments