Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Feb 5, 2018
1 parent 8cd37f6 commit a2ad109
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 474 deletions.
73 changes: 0 additions & 73 deletions MvvmHelpers.Tests/MvvmHelpers.Tests.csproj

This file was deleted.

5 changes: 0 additions & 5 deletions MvvmHelpers.Tests/packages.config

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel;

namespace MvvmHelpers.Tests
{
[TestFixture()]
[TestClass]
public class BaseViewModelTests
{

[Test()]
public void TitleTest()
[TestMethod]
public void TitleTestMethod()
{
PropertyChangedEventArgs updated = null;
var vm = new PersonViewModel();
Expand All @@ -23,7 +23,7 @@ public void TitleTest()
Assert.AreEqual(updated.PropertyName, nameof(vm.Title), "Correct Property name didn't get raised");
}

[Test()]
[TestMethod]
public void SubTitle()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -38,7 +38,7 @@ public void SubTitle()
Assert.IsNotNull(updated, "Property changed didn't raise");
Assert.AreEqual(updated.PropertyName, nameof(vm.Subtitle), "Correct Property name didn't get raised");
}
[Test()]
[TestMethod]
public void CanLoadMore()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -54,7 +54,7 @@ public void CanLoadMore()
Assert.AreEqual(updated.PropertyName, nameof(vm.CanLoadMore), "Correct Property name didn't get raised");
}

[Test()]
[TestMethod]
public void Icon()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -70,7 +70,7 @@ public void Icon()
Assert.AreEqual(updated.PropertyName, nameof(vm.Icon), "Correct Property name didn't get raised");
}

[Test()]
[TestMethod]
public void IsBusy()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -89,7 +89,7 @@ public void IsBusy()
Assert.IsFalse(vm.IsNotBusy, "Is Not Busy didn't change.");
}

[Test()]
[TestMethod]
public void IsNotBusy()
{
PropertyChangedEventArgs updated = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,10 +7,10 @@

namespace MvvmHelpers.Tests
{
[TestFixture()]
[TestClass]
public class GroupingTests
{
[Test()]
[TestMethod]
public void Grouping()
{

Expand Down Expand Up @@ -42,7 +42,7 @@ group person by person.SortName into personGroup

}

[Test()]
[TestMethod]
public void GroupingSubKey()
{

Expand Down
19 changes: 19 additions & 0 deletions MvvmHelpers.UnitTests/MvvmHelpers.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MvvmHelpers\MvvmHelpers.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace MvvmHelpers.Tests
{
[TestFixture()]
[TestClass]
public class ObservableObjectTests
{
Person person;
[SetUp]
[TestInitialize]
public void Setup()
{
person = new Person();
person.FirstName = "James";
person.LastName = "Montemagno";
}

[Test()]
[TestMethod]
public void OnPropertyChanged()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -34,7 +34,7 @@ public void OnPropertyChanged()
Assert.AreEqual(updated.PropertyName, nameof(person.FirstName), "Correct Property name didn't get raised");
}

[Test()]
[TestMethod]
public void OnDidntChange()
{
PropertyChangedEventArgs updated = null;
Expand All @@ -49,7 +49,7 @@ public void OnDidntChange()
Assert.IsNull(updated, "Property changed was raised, but shouldn't have been");
}

[Test()]
[TestMethod]
public void OnChangedEvent()
{

Expand All @@ -64,7 +64,7 @@ public void OnChangedEvent()
Assert.IsTrue(triggered, "OnChanged didn't raise");
}

[Test()]
[TestMethod]
public void ValidateEvent()
{
var contol = "Motz";
Expand All @@ -82,7 +82,7 @@ public void ValidateEvent()

}

[Test()]
[TestMethod]
public void NotValidateEvent()
{
var contol = person.FirstName;
Expand All @@ -100,7 +100,7 @@ public void NotValidateEvent()

}

[Test()]
[TestMethod]
public void ValidateEventException()
{
person.Validate = (oldValue, newValue) =>
Expand All @@ -109,7 +109,7 @@ public void ValidateEventException()
return false;
};

Assert.Throws<ArgumentOutOfRangeException>(() => person.FirstName = "Motz", "Should throw ArgumentOutOfRangeException");
Assert.ThrowsException<ArgumentOutOfRangeException>(() => person.FirstName = "Motz", "Should throw ArgumentOutOfRangeException");

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;

namespace MvvmHelpers.Tests
{
[TestFixture()]
[TestClass]
public class ObservableRangeTests
{
[Test()]
[TestMethod]
public void AddRange()
{
ObservableRangeCollection<int> collection = new ObservableRangeCollection<int>();
Expand All @@ -36,7 +36,7 @@ public void AddRange()
collection.AddRange(toAdd);
}

[Test()]
[TestMethod]
public void ReplaceRange()
{
ObservableRangeCollection<int> collection = new ObservableRangeCollection<int>();
Expand Down Expand Up @@ -64,8 +64,8 @@ public void ReplaceRange()
}


[Test()]
public void RemoveRangeRemoveTest()
[TestMethod]
public void RemoveRangeRemoveTestMethod()
{
ObservableRangeCollection<int> collection = new ObservableRangeCollection<int>();
int[] toAdd = new[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3 };
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 10 additions & 11 deletions MvvmHelpers.sln
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{93B692A1-FE26-4A59-B906-0CBADB102B8F}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
bootstrapper.ps1 = bootstrapper.ps1
build.cake = build.cake
CHANGELOG.md = CHANGELOG.md
MvvmHelpers.nuspec = MvvmHelpers.nuspec
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmHelpers.Tests", "MvvmHelpers.Tests\MvvmHelpers.Tests.csproj", "{FB9CBAC4-6CAE-451B-AB21-09E5B003F7D8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmHelpers", "MvvmHelpers\MvvmHelpers.csproj", "{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmHelpers", "MvvmHelpers\MvvmHelpers.csproj", "{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmHelpers.UnitTests", "MvvmHelpers.UnitTests\MvvmHelpers.UnitTests.csproj", "{620ED767-21A2-4CFB-9B9F-6F42E9F6ECDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FB9CBAC4-6CAE-451B-AB21-09E5B003F7D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB9CBAC4-6CAE-451B-AB21-09E5B003F7D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB9CBAC4-6CAE-451B-AB21-09E5B003F7D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB9CBAC4-6CAE-451B-AB21-09E5B003F7D8}.Release|Any CPU.Build.0 = Release|Any CPU
{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D6855F0-C8DE-4222-B7B6-DFB7650700E1}.Release|Any CPU.Build.0 = Release|Any CPU
{620ED767-21A2-4CFB-9B9F-6F42E9F6ECDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{620ED767-21A2-4CFB-9B9F-6F42E9F6ECDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{620ED767-21A2-4CFB-9B9F-6F42E9F6ECDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{620ED767-21A2-4CFB-9B9F-6F42E9F6ECDA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4C19D861-682A-4971-BE87-6D0443235729}
EndGlobalSection
EndGlobal
8 changes: 6 additions & 2 deletions MvvmHelpers/ObservableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ protected virtual bool SetProperty<T>(
Action onChanged = null,
Func<T, T, bool> validateValue = null)
{
if ((validateValue == null && EqualityComparer<T>.Default.Equals(backingStore, value)) ||
(validateValue != null && !validateValue(backingStore, value)))
//if value didn't change
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;

//if value changed but didn't validate
if (validateValue != null && !validateValue(backingStore, value))
return false;

backingStore = value;
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

Collection of MVVM helper classes for any application.

Grab the NuGet: https://www.nuget.org/packages/Refractored.MvvmHelpers
**Build Status**: ![](https://jamesmontemagno.visualstudio.com/_apis/public/build/definitions/5c11b5bc-b611-475d-a50c-4043a0cbb441/11/badge)

Build Status: [![Build status](https://ci.appveyor.com/api/projects/status/nsj9rae1g93hy62o/branch/master?svg=true)](https://ci.appveyor.com/project/JamesMontemagno/mvvm-helpers/branch/master)
**NuGets**

Built with C# 7 features, you must be running Visual Studio 2017 or Visual Studio for Mac to compile. **NuGets of course work everywhere!**
|Name|Info|
| ------------------- | :------------------: |
|MvvmHelpers|[![NuGet](https://img.shields.io/nuget/v/Refractored.MvvmHelpers.svg?label=NuGet)](https://www.nuget.org/packages/Refractored.MvvmHelpers/)|
|Development Feed|[MyGet](http://myget.org/F/mvvm-helpers)|

## What's included?

Expand Down
Loading

0 comments on commit a2ad109

Please sign in to comment.