-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Tests, Add Subkey to ORC, update WithTimeout to TimeSpan
- Loading branch information
1 parent
efaf9fe
commit 8288dcb
Showing
15 changed files
with
472 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Changelog | ||
|
||
### [1.2.0] | ||
* WithTimeout now takes in an optional TimeSpan | ||
* ObservableRangeCollection now has optional SubKey | ||
* Ability to change IsNotBusy |
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,121 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MvvmHelpers.Tests | ||
{ | ||
[TestFixture()] | ||
public class BaseViewModelTests | ||
{ | ||
|
||
[Test()] | ||
public void TitleTest() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
vm.Title = "Hello"; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.Title), "Correct Property name didn't get raised"); | ||
} | ||
|
||
[Test()] | ||
public void SubTitle() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
vm.Subtitle = "Hello"; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.Subtitle), "Correct Property name didn't get raised"); | ||
} | ||
[Test()] | ||
public void CanLoadMore() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
vm.CanLoadMore = false; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.CanLoadMore), "Correct Property name didn't get raised"); | ||
} | ||
|
||
[Test()] | ||
public void Icon() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
vm.Icon = "Hello"; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.Icon), "Correct Property name didn't get raised"); | ||
} | ||
|
||
[Test()] | ||
public void IsBusy() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
if (args.PropertyName == "IsBusy") | ||
updated = args; | ||
}; | ||
|
||
vm.IsBusy = true; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.IsBusy), "Correct Property name didn't get raised"); | ||
|
||
Assert.IsFalse(vm.IsNotBusy, "Is Not Busy didn't change."); | ||
} | ||
|
||
[Test()] | ||
public void IsNotBusy() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
var vm = new PersonViewModel(); | ||
|
||
vm.PropertyChanged += (sender, args) => | ||
{ | ||
if(args.PropertyName == "IsNotBusy") | ||
updated = args; | ||
}; | ||
|
||
vm.IsNotBusy = false; | ||
Task.Delay(100); | ||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(vm.IsNotBusy), "Correct Property name didn't get raised"); | ||
|
||
Assert.IsTrue(vm.IsBusy, "Is Busy didn't change."); | ||
} | ||
} | ||
} | ||
|
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,66 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MvvmHelpers.Tests | ||
{ | ||
[TestFixture()] | ||
public class GroupingTests | ||
{ | ||
[Test()] | ||
public void Grouping() | ||
{ | ||
|
||
var grouped = new ObservableRangeCollection<Grouping<string, Person>>(); | ||
var people = new[] | ||
{ | ||
new Person { FirstName = "Joseph", LastName = "Hill" }, | ||
new Person { FirstName = "James", LastName = "Montemagno" }, | ||
new Person { FirstName = "Pierce", LastName = "Boggan" }, | ||
}; | ||
|
||
var sorted = from person in people | ||
orderby person.FirstName | ||
group person by person.SortName into personGroup | ||
select new Grouping<string, Person>(personGroup.Key, personGroup); | ||
|
||
grouped.AddRange(sorted); | ||
|
||
Assert.AreEqual(2, grouped.Count, "There should be 2 groups"); | ||
Assert.AreEqual("J", grouped[0].Key, "Key for group 0 should be J"); | ||
Assert.AreEqual(2, grouped[0].Count, "There should be 2 items in group 0"); | ||
Assert.AreEqual(1, grouped[1].Count, "There should be 1 items in group 1"); | ||
|
||
} | ||
|
||
[Test()] | ||
public void GroupingSubKey() | ||
{ | ||
|
||
var grouped = new ObservableRangeCollection<Grouping<string, string, Person>>(); | ||
var people = new[] | ||
{ | ||
new Person { FirstName = "Joseph", LastName = "Hill" }, | ||
new Person { FirstName = "James", LastName = "Montemagno" }, | ||
new Person { FirstName = "Pierce", LastName = "Boggan" }, | ||
}; | ||
|
||
var sorted = from person in people | ||
orderby person.FirstName | ||
group person by person.SortName into personGroup | ||
select new Grouping<string, string, Person>(personGroup.Key, personGroup.Key, personGroup); | ||
|
||
grouped.AddRange(sorted); | ||
|
||
Assert.AreEqual(2, grouped.Count, "There should be 2 groups"); | ||
Assert.AreEqual("J", grouped[0].SubKey, "Key for group 0 should be J"); | ||
Assert.AreEqual("J", grouped[0].Key, "Key for group 0 should be J"); | ||
Assert.AreEqual(2, grouped[0].Count, "There should be 2 items in group 0"); | ||
Assert.AreEqual(1, grouped[1].Count, "There should be 1 items in group 1"); | ||
|
||
} | ||
} | ||
} |
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,72 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MvvmHelpers.Tests | ||
{ | ||
[TestFixture()] | ||
public class ObservableObjectTests | ||
{ | ||
Person person; | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
person = new Person(); | ||
person.FirstName = "James"; | ||
person.LastName = "Montemagno"; | ||
} | ||
|
||
[Test()] | ||
public void OnPropertyChanged() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
person.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
person.FirstName = "Motz"; | ||
|
||
Task.Delay(100); | ||
|
||
Assert.IsNotNull(updated, "Property changed didn't raise"); | ||
Assert.AreEqual(updated.PropertyName, nameof(person.FirstName), "Correct Property name didn't get raised"); | ||
} | ||
|
||
[Test()] | ||
public void OnDidntChange() | ||
{ | ||
PropertyChangedEventArgs updated = null; | ||
person.PropertyChanged += (sender, args) => | ||
{ | ||
updated = args; | ||
}; | ||
|
||
person.FirstName = "James"; | ||
|
||
Task.Delay(100); | ||
|
||
Assert.IsNull(updated, "Property changed was raised, but shouldn't have been"); | ||
} | ||
|
||
[Test()] | ||
public void OnChangedEvent() | ||
{ | ||
|
||
var triggered = false; | ||
person.Changed = () => | ||
{ | ||
triggered = true; | ||
}; | ||
|
||
person.FirstName = "Motz"; | ||
|
||
Task.Delay(100); | ||
|
||
Assert.IsTrue(triggered, "OnChanged didn't raise"); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.