File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
UnitTest/DataStructuresTests Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -184,11 +184,11 @@ public int GetPreviousPrime(int number)
184184 }
185185
186186 /// <summary>
187- /// Returns the list of primes
187+ /// Returns the read-only IList of primes
188188 /// </summary>
189- public List < int > GetAll
189+ public IList < int > GetAll
190190 {
191- get { return _primes ; }
191+ get { return _primes . AsReadOnly ( ) ; }
192192 }
193193
194194 /// <summary>
Original file line number Diff line number Diff line change 1- using DataStructures . Common ;
1+ using System ;
2+ using DataStructures . Common ;
23using Xunit ;
34
45namespace UnitTest . DataStructuresTests
@@ -11,5 +12,13 @@ public void DoTest()
1112 var instance = PrimesList . Instance ;
1213 Assert . Equal ( 10000 , instance . Count ) ;
1314 }
15+
16+ [ Fact ]
17+ public void PrimesListIsReadOnly ( )
18+ {
19+ var instance = PrimesList . Instance ;
20+ NotSupportedException ex = Assert . Throws < NotSupportedException > ( ( ) => instance . GetAll [ 0 ] = - 1 ) ;
21+ Assert . Equal ( "Collection is read-only." , ex . Message ) ;
22+ }
1423 }
1524}
You can’t perform that action at this time.
0 commit comments