File tree Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ namespace Observer
4
4
{
5
5
public class SpecialsSubject : ISubject
6
6
{
7
- public delegate void Callback ( string s ) ;
8
- public string SubjectState { get ; set ; }
7
+ public delegate void Callback ( string s ) ;
8
+ public required string SubjectState { get ; set ; }
9
9
10
- private List < IObserver > _observers = new List < IObserver > ( ) ;
10
+ private readonly List < IObserver > _observers = [ ] ;
11
11
12
12
public void Attach ( IObserver observer )
13
13
{
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public bool Delete(int id)
14
14
{
15
15
return _products . Remove ( id ) ;
16
16
}
17
- public IProductInfo Get ( int id )
17
+ public IProductInfo ? Get ( int id )
18
18
{
19
19
if ( ! _products . ContainsKey ( id ) )
20
20
{
Original file line number Diff line number Diff line change @@ -4,6 +4,6 @@ namespace Proxy
4
4
public interface IEntries
5
5
{
6
6
bool Delete ( int id ) ;
7
- IProductInfo Get ( int id ) ;
7
+ IProductInfo ? Get ( int id ) ;
8
8
}
9
9
}
Original file line number Diff line number Diff line change @@ -11,11 +11,13 @@ public class ObserverShould
11
11
public void UpdateObserverOnce_WhenSubjectHasSpecials ( )
12
12
{
13
13
// Arrange
14
- var subject = new SpecialsSubject ( ) ;
14
+ var subject = new SpecialsSubject
15
+ {
16
+ SubjectState = "Footwear Sale"
17
+ } ;
15
18
var mockObserver = new Mock < IObserver > ( ) ;
16
19
// Act
17
20
subject . Attach ( mockObserver . Object ) ;
18
- subject . SubjectState = "Footwear Sale" ;
19
21
subject . Notify ( ) ;
20
22
// Assert
21
23
mockObserver . Verify ( observer => observer . Update ( subject ) , Times . Once ( ) ) ;
@@ -25,7 +27,10 @@ public void UpdateObserverOnce_WhenSubjectHasSpecials()
25
27
public void NotCallUpdate_WhenObserverNotAttachedToSubject ( )
26
28
{
27
29
// Arrange
28
- var subject = new SpecialsSubject ( ) ;
30
+ var subject = new SpecialsSubject
31
+ {
32
+ SubjectState = "Footwear Sale"
33
+ } ;
29
34
var mockObserver = new Mock < IObserver > ( ) ;
30
35
// Act
31
36
subject . SubjectState = "Footwear Sale" ;
You can’t perform that action at this time.
0 commit comments