Improve test coverage slightly

This commit is contained in:
Antony Male 2014-05-06 13:11:51 +01:00
parent 30472cffca
commit 3ecb0c38c8
8 changed files with 154 additions and 4 deletions

View File

@ -12,6 +12,7 @@ REPORT_GENERATOR = Dir['packages/ReportGenerator*/ReportGenerator.exe'].first
UNIT_TESTS_DLL = "StyletUnitTests/bin/#{CONFIG}/StyletUnitTests.dll"
COVERAGE_DIR = 'Coverage'
COVERAGE_FILE = File.join(COVERAGE_DIR, 'coverage.xml')
desc "Build Stylet.sln using the current CONFIG (or Debug)"
build :build do |b|
@ -20,13 +21,17 @@ build :build do |b|
b.prop 'Configuration', CONFIG
end
desc "Run unit tests using the current CONFIG (or Debug)"
test_runner :test => [:build] do |t|
test_runner :nunit_test_runner => [:build] do |t|
t.exe = NUNIT_CONSOLE
t.files = [UNIT_TESTS_DLL]
t.add_parameter '/nologo'
end
desc "Run unit tests using the current CONFIG (or Debug)"
task :test => [:nunit_test_runner] do |t|
rm 'TestResult.xml'
end
desc "Launch the NUnit gui pointing at the correct DLL for CONFIG (or Debug)"
task :nunit do |t|
sh NUNIT_EXE, UNIT_TESTS_DLL
@ -34,7 +39,7 @@ end
desc "Generate code coverage reports for CONFIG (or Debug)"
task :cover => [:build] do |t|
sh OPENCOVER_CONSOLE, %Q{-register:user -target:"#{NUNIT_CONSOLE}" -filter:+[*]* -targetargs:"#{UNIT_TESTS_DLL} /noshadow" -output:"#{File.join(COVERAGE_DIR, 'coverage.xml')}"}
sh REPORT_GENERATOR, %Q{-reports:"coverage.xml" -targetdir:"#{COVERAGE_DIR}"}
sh OPENCOVER_CONSOLE, %Q{-register:user -target:"#{NUNIT_CONSOLE}" -filter:+[Stylet]* -targetargs:"#{UNIT_TESTS_DLL} /noshadow" -output:"#{COVERAGE_FILE}"}
sh REPORT_GENERATOR, %Q{-reports:"#{COVERAGE_FILE}" -targetdir:"#{COVERAGE_DIR}"}
end

View File

@ -0,0 +1,29 @@
using NUnit.Framework;
using Stylet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace StyletUnitTests
{
[TestFixture]
public class AssemblySourceTests
{
[TestFixtureSetUp]
public void SetUpFixture()
{
Execute.TestExecuteSynchronously = true;
}
[Test]
public void TestAssemblies()
{
var assembly = Assembly.GetExecutingAssembly();
AssemblySource.Assemblies.Add(assembly);
CollectionAssert.AreEqual(AssemblySource.Assemblies, new[] { assembly });
}
}
}

View File

@ -132,5 +132,33 @@ namespace StyletUnitTests
var changedEvent = changedEvents[0];
Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action);
}
[Test]
public void UsesPropertyChangedDipatcher()
{
var collection = new BindableCollection<Element>();
var changedProperties = new List<string>();
((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => changedProperties.Add(e.PropertyName);
var changedEvents = new List<NotifyCollectionChangedEventArgs>();
collection.CollectionChanged += (o, e) => changedEvents.Add(e);
List<Action> dispatchedActions = new List<Action>();
collection.PropertyChangedDispatcher = a => dispatchedActions.Add(a);
collection.Add(new Element());
Assert.IsEmpty(changedProperties);
Assert.IsNotEmpty(dispatchedActions);
foreach (var action in dispatchedActions)
action();
Assert.That(changedProperties, Is.EquivalentTo(new[] { "Count", "Item[]" }));
Assert.AreEqual(1, changedEvents.Count);
var changedEvent = changedEvents[0];
Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvent.Action);
}
}
}

View File

@ -164,5 +164,22 @@ namespace StyletUnitTests
screen.Verify(x => x.Close());
Assert.AreEqual(0, this.conductor.Items.Count);
}
[Test]
public void ClosingConductorClosesAllItems()
{
var screen1 = new Mock<IScreen>();
screen1.SetupGet(x => x.Parent).Returns(this.conductor);
var screen2 = new Mock<IScreen>();
screen2.SetupGet(x => x.Parent).Returns(this.conductor);
this.conductor.ActivateItem(screen1.Object);
this.conductor.ActivateItem(screen2.Object);
((IClose)this.conductor).Close();
screen1.Verify(x => x.Close());
screen1.VerifySet(x => x.Parent = null);
screen2.Verify(x => x.Close());
screen2.VerifySet(x => x.Parent = null);
}
}
}

View File

@ -128,6 +128,17 @@ namespace StyletUnitTests
this.conductor.ActivateItem(screen.Object);
screen.VerifySet(x => x.Parent = this.conductor);
}
[Test]
public void SettingActiveItemActivatesItem()
{
var screen = new Mock<IScreen>();
((IActivate)this.conductor).Activate();
this.conductor.ActiveItem =screen.Object;
screen.Verify(x => x.Activate());
Assert.AreEqual(this.conductor.ActiveItem, screen.Object);
}
[Test]
public void CloseRemovesItemsParent()
@ -192,5 +203,22 @@ namespace StyletUnitTests
this.conductor.GoBack();
Assert.IsNull(this.conductor.ActiveItem);
}
[Test]
public void CloseClosesAllItems()
{
var screen1 = new Mock<IScreen>();
screen1.SetupGet(x => x.Parent).Returns(this.conductor);
var screen2 = new Mock<IScreen>();
screen2.SetupGet(x => x.Parent).Returns(this.conductor);
this.conductor.ActivateItem(screen1.Object);
this.conductor.ActivateItem(screen2.Object);
((IClose)this.conductor).Close();
screen1.Verify(x => x.Close());
screen1.VerifySet(x => x.Parent = null);
screen2.Verify(x => x.Close());
screen2.VerifySet(x => x.Parent = null);
}
}
}

View File

@ -61,6 +61,16 @@ namespace StyletUnitTests
Assert.AreEqual(new[] { screen1.Object, screen2.Object }, this.conductor.Items);
}
[Test]
public void SettingActiveItemActivatesItem()
{
var screen = new Mock<IScreen>();
((IActivate)this.conductor).Activate();
this.conductor.ActiveItem = screen.Object;
screen.Verify(x => x.Activate());
Assert.AreEqual(this.conductor.ActiveItem, screen.Object);
}
[Test]
public void ClosingActiveItemChoosesPreviousItemIfAvailable()
{
@ -248,5 +258,16 @@ namespace StyletUnitTests
screen.Verify(x => x.Close());
Assert.AreEqual(0, this.conductor.Items.Count);
}
[Test]
public void ClosingConductorClosesActiveItem()
{
var screen1 = new Mock<IScreen>();
screen1.SetupGet(x => x.Parent).Returns(this.conductor);
this.conductor.ActivateItem(screen1.Object);
((IClose)this.conductor).Close();
screen1.Verify(x => x.Close());
screen1.VerifySet(x => x.Parent = null);
}
}
}

View File

@ -110,6 +110,16 @@ namespace StyletUnitTests
screen.Verify(x => x.Close(), Times.Never);
}
[Test]
public void SettingActiveItemActivatesItem()
{
var screen = new Mock<IScreen>();
((IActivate)this.conductor).Activate();
this.conductor.ActiveItem = screen.Object;
screen.Verify(x => x.Activate());
Assert.AreEqual(this.conductor.ActiveItem, screen.Object);
}
[Test]
public void CloseItemDoesNothingIfToldToDeactiveInactiveItem()
{
@ -168,5 +178,16 @@ namespace StyletUnitTests
screen1.Setup(x => x.CanCloseAsync()).Returns(Task.FromResult(false));
Assert.IsFalse(this.conductor.CanCloseAsync().Result);
}
[Test]
public void ClosingConductorClosesActiveItem()
{
var screen1 = new Mock<IScreen>();
screen1.SetupGet(x => x.Parent).Returns(this.conductor);
this.conductor.ActivateItem(screen1.Object);
((IClose)this.conductor).Close();
screen1.Verify(x => x.Close());
screen1.VerifySet(x => x.Parent = null);
}
}
}

View File

@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ActionExtensionTests.cs" />
<Compile Include="AssemblySourceTests.cs" />
<Compile Include="BindableCollectionTests.cs" />
<Compile Include="ConductorAllActiveTests.cs" />
<Compile Include="ConductorNavigatingTests.cs" />