-
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.
Merge pull request #13 from BoBoBaSs84/feature/add-unit-tests
feat: add unit tests
- Loading branch information
Showing
15 changed files
with
219 additions
and
26 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
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
4 changes: 2 additions & 2 deletions
4
...ations/Enumerators/CollectionEventType.cs → ...ons/Enumerators/CollectionChangeAction.cs
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
17 changes: 17 additions & 0 deletions
17
tests/BB84.NotificationsTests/BindablePropertyTests.Changed.cs
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,17 @@ | ||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class BindablePropertyTests | ||
{ | ||
[TestMethod] | ||
public void Changed() | ||
{ | ||
int changedValue = default; | ||
TestClass testClass = new(1); | ||
testClass.BindableProperty.Changed += (sender, e) => changedValue = e.Value; | ||
|
||
testClass.BindableProperty.Value = 2; | ||
|
||
Assert.AreEqual(2, changedValue); | ||
Assert.AreEqual(2, testClass.BindableProperty.Value); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/BB84.NotificationsTests/BindablePropertyTests.Changing.cs
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,17 @@ | ||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class BindablePropertyTests | ||
{ | ||
[TestMethod] | ||
public void Changing() | ||
{ | ||
int changingValue = default; | ||
TestClass testClass = new(1); | ||
testClass.BindableProperty.Changing += (sender, e) => changingValue = e.Value; | ||
|
||
testClass.BindableProperty.Value = 2; | ||
|
||
Assert.AreEqual(1, changingValue); | ||
Assert.AreEqual(2, testClass.BindableProperty.Value); | ||
} | ||
} |
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,16 @@ | ||
using BB84.Notifications; | ||
using BB84.Notifications.Interfaces; | ||
|
||
namespace BB84.NotificationsTests; | ||
|
||
[TestClass] | ||
public sealed partial class BindablePropertyTests | ||
{ | ||
private sealed class TestClass | ||
{ | ||
public TestClass(int bindableProperty) | ||
=> BindableProperty = new BindableProperty<int>(bindableProperty); | ||
|
||
public IBindableProperty<int> BindableProperty { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/BB84.NotificationsTests/NotifyCollectionBaseTests.Changed.cs
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,20 @@ | ||
using BB84.Notifications.Enumerators; | ||
|
||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class NotifyCollectionBaseTests | ||
{ | ||
[TestMethod] | ||
public void Changed() | ||
{ | ||
CollectionChangeAction action = default!; | ||
string item = string.Empty; | ||
MyCollection strings = new(); | ||
strings.CollectionChanged += (sender, e) => { item = (string)e.Item!; action = e.Action; }; | ||
|
||
strings.Add("UnitTest"); | ||
|
||
Assert.AreEqual(CollectionChangeAction.Add, action); | ||
Assert.AreEqual("UnitTest", item); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/BB84.NotificationsTests/NotifyCollectionBaseTests.Changing.cs
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,20 @@ | ||
using BB84.Notifications.Enumerators; | ||
|
||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class NotifyCollectionBaseTests | ||
{ | ||
[TestMethod] | ||
public void Changing() | ||
{ | ||
CollectionChangeAction action = default!; | ||
string item = string.Empty; | ||
MyCollection strings = new(); | ||
strings.CollectionChanging += (sender, e) => { item = (string)e.Item!; action = e.Action; }; | ||
|
||
strings.Add("UnitTest"); | ||
|
||
Assert.AreEqual(CollectionChangeAction.Add, action); | ||
Assert.AreEqual("UnitTest", item); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/BB84.NotificationsTests/NotifyCollectionBaseTests.cs
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,47 @@ | ||
using System.Collections; | ||
using System.Collections.ObjectModel; | ||
|
||
using BB84.Notifications; | ||
using BB84.Notifications.Enumerators; | ||
|
||
namespace BB84.NotificationsTests; | ||
|
||
[TestClass] | ||
public sealed partial class NotifyCollectionBaseTests | ||
{ | ||
private class MyCollection : NotifyCollectionBase, ICollection<string> | ||
{ | ||
private readonly Collection<string> _collection; | ||
|
||
public MyCollection() | ||
=> _collection = new Collection<string>(); | ||
|
||
public int Count => _collection.Count; | ||
public bool IsReadOnly => false; | ||
|
||
public void Add(string item) | ||
{ | ||
RaiseCollectionChanging(CollectionChangeAction.Add, item); | ||
_collection.Add(item); | ||
RaiseCollectionChanged(CollectionChangeAction.Add, item); | ||
} | ||
|
||
public void Clear() | ||
=> _collection.Clear(); | ||
|
||
public bool Contains(string item) | ||
=> _collection.Contains(item); | ||
|
||
public void CopyTo(string[] array, int arrayIndex) | ||
=> _collection.CopyTo(array, arrayIndex); | ||
|
||
public IEnumerator<string> GetEnumerator() | ||
=> _collection.GetEnumerator(); | ||
|
||
public bool Remove(string item) | ||
=> _collection.Remove(item); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
=> _collection.GetEnumerator(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/BB84.NotificationsTests/NotifyPropertyBaseTests.Changed.cs
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,19 @@ | ||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class NotifyPropertyBaseTests | ||
{ | ||
[TestMethod] | ||
public void Changed() | ||
{ | ||
string changedProperty = string.Empty; | ||
int changedValue = default; | ||
TestClass testClass = new(); | ||
testClass.PropertyChanged += (sender, e) => { changedValue = (int)e.Value!; changedProperty = e.Name; }; | ||
|
||
testClass.Property = 1; | ||
|
||
Assert.AreEqual(nameof(testClass.Property), changedProperty); | ||
Assert.AreEqual(1, changedValue); | ||
Assert.AreEqual(1, testClass.Property); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/BB84.NotificationsTests/NotifyPropertyBaseTests.Changing.cs
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,19 @@ | ||
namespace BB84.NotificationsTests; | ||
|
||
public sealed partial class NotifyPropertyBaseTests | ||
{ | ||
[TestMethod] | ||
public void Changing() | ||
{ | ||
string changingProperty = string.Empty; | ||
int changingValue = default; | ||
TestClass testClass = new() { Property = 1 }; | ||
testClass.PropertyChanging += (sender, e) => { changingValue = (int)e.Value!; changingProperty = e.Name; }; | ||
|
||
testClass.Property = 2; | ||
|
||
Assert.AreEqual(nameof(testClass.Property), changingProperty); | ||
Assert.AreEqual(1, changingValue); | ||
Assert.AreNotEqual(1, testClass.Property); | ||
} | ||
} |
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,18 @@ | ||
using BB84.Notifications; | ||
|
||
namespace BB84.NotificationsTests; | ||
|
||
[TestClass] | ||
public sealed partial class NotifyPropertyBaseTests | ||
{ | ||
private sealed class TestClass : NotifyPropertyBase | ||
{ | ||
private int _property; | ||
|
||
public int Property | ||
{ | ||
get => _property; | ||
set => SetProperty(ref _property, value); | ||
} | ||
} | ||
} |