-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for reading value in OnChange callback
- Loading branch information
1 parent
800c6fd
commit 026ad02
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace MutableOptions.Tests.TestOptions | ||
{ | ||
using Microsoft.Extensions.Options.Mutable; | ||
using System.ComponentModel; | ||
|
||
internal sealed class SimpleSettingsService : INotifyPropertyChanged, IDisposable | ||
{ | ||
private readonly IMutableOptionsMonitor<SimpleOptions> _mutableOptionsMonitor; | ||
private readonly IDisposable _changeSubscription; | ||
|
||
public SimpleSettingsService(IMutableOptionsMonitor<SimpleOptions> mutableOptionsMonitor) | ||
{ | ||
_mutableOptionsMonitor = mutableOptionsMonitor; | ||
_changeSubscription = _mutableOptionsMonitor.OnChange(HandleSimpleOptionsChanged); | ||
} | ||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
public string StringValue | ||
{ | ||
get => _mutableOptionsMonitor.CurrentValue.StringValue; | ||
set => _mutableOptionsMonitor.Mutate(options => options with { StringValue = value }); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_changeSubscription.Dispose(); | ||
} | ||
|
||
private void HandleSimpleOptionsChanged(SimpleOptions simpleOptions, string name) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters