Skip to content

Commit

Permalink
Update Tests, Add Subkey to ORC, update WithTimeout to TimeSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Jan 5, 2017
1 parent efaf9fe commit 8288dcb
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 38 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
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
121 changes: 121 additions & 0 deletions MvvmHelpers.Tests/BaseVewModelTests.cs
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.");
}
}
}

66 changes: 66 additions & 0 deletions MvvmHelpers.Tests/GroupingTests.cs
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");

}
}
}
21 changes: 21 additions & 0 deletions MvvmHelpers.Tests/MvvmHelpers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,34 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GroupingTests.cs" />
<Compile Include="ObservableObjectTests.cs" />
<Compile Include="BaseVewModelTests.cs" />
<Compile Include="ObservableRangeTests.cs" />
<Compile Include="Person.cs" />
<Compile Include="UtilTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
72 changes: 72 additions & 0 deletions MvvmHelpers.Tests/ObservableObjectTests.cs
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");
}
}
}

Loading

0 comments on commit 8288dcb

Please sign in to comment.