-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52db865
commit f065290
Showing
4 changed files
with
67 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.ComponentModel; | ||
|
||
namespace BrentEdwards.MVVM.Test | ||
{ | ||
[TestClass] | ||
public sealed class ViewModelBaseTests | ||
{ | ||
private class MockViewModel : ViewModelBase | ||
{ | ||
public void TriggerPropertyChanged(string propertyName) | ||
{ | ||
NotifyPropertyChanged(propertyName); | ||
} | ||
} | ||
|
||
private List<string> _propertiesChanged; | ||
private void PropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
_propertiesChanged.Add(e.PropertyName); | ||
} | ||
|
||
[TestMethod] | ||
public void NotifyPropertyChanged() | ||
{ | ||
_propertiesChanged = new List<string>(); | ||
|
||
var viewModel = new MockViewModel(); | ||
var propertyName = Guid.NewGuid().ToString(); | ||
|
||
viewModel.PropertyChanged += PropertyChanged; | ||
viewModel.TriggerPropertyChanged(propertyName); | ||
viewModel.PropertyChanged -= PropertyChanged; | ||
|
||
Assert.AreEqual(1, _propertiesChanged.Count); | ||
Assert.IsTrue(_propertiesChanged.Contains(propertyName)); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.ComponentModel; | ||
|
||
namespace BrentEdwards.MVVM | ||
{ | ||
public abstract class ViewModelBase : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
protected void NotifyPropertyChanged(String propertyName) | ||
{ | ||
if (PropertyChanged != null) | ||
{ | ||
var args = new PropertyChangedEventArgs(propertyName); | ||
PropertyChanged(this, args); | ||
} | ||
} | ||
} | ||
} |