-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding NotifyPropertyChangedModule implementation and tests. Updating…
… readme with help to pull dependencies and build.
- Loading branch information
Showing
4 changed files
with
94 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Archetype | ||
============ | ||
To build, open PowerShell console in source directory. Run chewie.ps1. Then open the solution. |
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,65 @@ | ||
using System.ComponentModel; | ||
using NUnit.Framework; | ||
|
||
namespace Archetype.Tests | ||
{ | ||
public class NotifyPropertyChangedModule : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public virtual void OnPropertyChanged(string propertyName) | ||
{ | ||
PropertyChangedEventHandler handler = PropertyChanged; | ||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
|
||
public class SampleModel : DelegatingPrototype | ||
{ | ||
private string _Name; | ||
|
||
public SampleModel() | ||
: base(new NotifyPropertyChangedModule()) | ||
{ | ||
// Or you can add it to the prototypes list after the fact | ||
//Prototypes.Add(new NotifyPropertyChangedModule()); | ||
} | ||
|
||
public string Name | ||
{ | ||
get { return _Name; } | ||
set | ||
{ | ||
if (_Name == value) return; | ||
_Name = value; | ||
This.OnPropertyChanged("Name"); | ||
} | ||
} | ||
|
||
protected dynamic This { get { return this; } } | ||
} | ||
|
||
[TestFixture] | ||
public class NotifyPropertyChangesModuleTests | ||
{ | ||
[Test] | ||
public void OnPropertyChangedCanBeCalledFromTheImportingClass() | ||
{ | ||
dynamic instance = new SampleModel(); | ||
INotifyPropertyChanged module = instance; // fancy casting of our object will return the module | ||
bool called = false; | ||
string propertyName = null; | ||
module.PropertyChanged += (sender, args) => | ||
{ | ||
called = true; | ||
propertyName = args.PropertyName; | ||
}; | ||
instance.Name = null; | ||
Assert.IsFalse(called); | ||
instance.Name = "Ian"; | ||
Assert.IsTrue(called); | ||
Assert.AreEqual("Ian", instance.Name); | ||
Assert.AreEqual("Name", propertyName); | ||
} | ||
} | ||
} |