Skip to content

Commit

Permalink
Modernise and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
deanagan committed Aug 1, 2024
1 parent b5ffc32 commit 6f5c3bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Patterns/Observer/SpecialsSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace Observer
{
public class SpecialsSubject : ISubject
{
public delegate void Callback (string s);
public string SubjectState {get; set;}
public delegate void Callback(string s);
public required string SubjectState { get; set; }

private List<IObserver> _observers = new List<IObserver>();
private readonly List<IObserver> _observers = [];

public void Attach(IObserver observer)
{
Expand Down
2 changes: 1 addition & 1 deletion Patterns/Proxy/Entries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public bool Delete(int id)
{
return _products.Remove(id);
}
public IProductInfo Get(int id)
public IProductInfo? Get(int id)
{
if (!_products.ContainsKey(id))
{
Expand Down
2 changes: 1 addition & 1 deletion Patterns/Proxy/IEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Proxy
public interface IEntries
{
bool Delete(int id);
IProductInfo Get(int id);
IProductInfo? Get(int id);
}
}
11 changes: 8 additions & 3 deletions Tests/ObserverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class ObserverShould
public void UpdateObserverOnce_WhenSubjectHasSpecials()
{
// Arrange
var subject = new SpecialsSubject();
var subject = new SpecialsSubject
{
SubjectState = "Footwear Sale"
};
var mockObserver = new Mock<IObserver>();
// Act
subject.Attach(mockObserver.Object);
subject.SubjectState = "Footwear Sale";
subject.Notify();
// Assert
mockObserver.Verify(observer => observer.Update(subject), Times.Once());
Expand All @@ -25,7 +27,10 @@ public void UpdateObserverOnce_WhenSubjectHasSpecials()
public void NotCallUpdate_WhenObserverNotAttachedToSubject()
{
// Arrange
var subject = new SpecialsSubject();
var subject = new SpecialsSubject
{
SubjectState = "Footwear Sale"
};
var mockObserver = new Mock<IObserver>();
// Act
subject.SubjectState = "Footwear Sale";
Expand Down

0 comments on commit 6f5c3bd

Please sign in to comment.