mirror of https://github.com/AMT-Cheif/Stylet.git
Start writing unit tests for the MessageBox stuff
This commit is contained in:
parent
99a57578c4
commit
2093d9c3cb
|
@ -90,7 +90,7 @@
|
|||
<Compile Include="StyletIoC\StyletIoCBuilder.cs" />
|
||||
<Compile Include="StyletIoC\StyletIoCContainer.cs" />
|
||||
<Compile Include="StyletIoC\UnboundGeneric.cs" />
|
||||
<Compile Include="Xaml\IconConverter.cs" />
|
||||
<Compile Include="Xaml\IconToBitmapSourceConverter.cs" />
|
||||
<Compile Include="Xaml\View.cs" />
|
||||
<Compile Include="ViewManager.cs" />
|
||||
<Compile Include="WindowManager.cs" />
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace Stylet.Xaml
|
|||
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (values == null || values.Length == 0)
|
||||
return null;
|
||||
var first = values.FirstOrDefault();
|
||||
var result = values.Skip(1).All(x => first.Equals(x));
|
||||
return this.Invert ? !result : result;
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
using NUnit.Framework;
|
||||
using Stylet.Xaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StyletUnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class EqualityConverterTests
|
||||
{
|
||||
private EqualityConverter converter;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
this.converter = new EqualityConverter();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstanceReturnsASingletonInstance()
|
||||
{
|
||||
Assert.NotNull(EqualityConverter.Instance);
|
||||
Assert.AreEqual(EqualityConverter.Instance, EqualityConverter.Instance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsNullIfNullPassed()
|
||||
{
|
||||
Assert.Null(this.converter.Convert(null, null, null, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsNullIfEmptyArrayPassed()
|
||||
{
|
||||
Assert.Null(this.converter.Convert(new object[0], null, null, null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsTrueIfASingleItemGiven()
|
||||
{
|
||||
var value = this.converter.Convert(new object[] { 5 }, null, null, null);
|
||||
Assert.IsInstanceOf<bool>(value);
|
||||
Assert.True((bool)value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsTrueIfAllItemsAreEqual()
|
||||
{
|
||||
var obj = new object();
|
||||
var value = this.converter.Convert(new[] { obj, obj, obj }, null, null, null);
|
||||
Assert.IsInstanceOf<bool>(value);
|
||||
Assert.True((bool)value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsFalseIfAllItemsAreEqualAndInvertIsTrue()
|
||||
{
|
||||
var obj = new object();
|
||||
this.converter.Invert = true;
|
||||
var value = this.converter.Convert(new[] { obj, obj, obj }, null, null, null);
|
||||
Assert.IsInstanceOf<bool>(value);
|
||||
Assert.False((bool)value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsFalseIfOneItemsDiffers()
|
||||
{
|
||||
var obj = new object();
|
||||
var value = this.converter.Convert(new[] { obj, new object(), obj }, null, null, null);
|
||||
Assert.IsInstanceOf<bool>(value);
|
||||
Assert.False((bool)value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReturnsTrueIfOneItemsDiffersAndInvertIsTrue()
|
||||
{
|
||||
var obj = new object();
|
||||
var value = this.converter.Convert(new[] { obj, new object(), obj }, null, null, null);
|
||||
Assert.IsInstanceOf<bool>(value);
|
||||
Assert.False((bool)value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertBackThrows()
|
||||
{
|
||||
Assert.Throws<NotImplementedException>(() => this.converter.ConvertBack(null, null, null, null));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Stylet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StyletUnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MessageBoxTests
|
||||
{
|
||||
[Test]
|
||||
public void ShowMessageBoxShowsMessageBox()
|
||||
{
|
||||
var vm = new Mock<IMessageBoxViewModel>();
|
||||
IoC.GetInstance = (o, k) =>
|
||||
{
|
||||
Assert.AreEqual(typeof(IMessageBoxViewModel), o);
|
||||
Assert.AreEqual(null, k);
|
||||
return vm.Object;
|
||||
};
|
||||
|
||||
var windowManager = new Mock<IWindowManager>();
|
||||
|
||||
vm.SetupGet(x => x.ClickedButton).Returns(MessageBoxButtons.OK);
|
||||
var result = MessageBoxWindowManagerExtensions.ShowMessageBox(windowManager.Object, "this is the text", "this is the title", MessageBoxButtons.OKCancel, System.Windows.MessageBoxImage.Exclamation, MessageBoxButtons.OK, MessageBoxButtons.Cancel);
|
||||
|
||||
vm.Verify(x => x.Setup("this is the text", "this is the title", MessageBoxButtons.OKCancel, System.Windows.MessageBoxImage.Exclamation, MessageBoxButtons.OK, MessageBoxButtons.Cancel));
|
||||
windowManager.Verify(x => x.ShowDialog(vm.Object));
|
||||
|
||||
Assert.AreEqual(MessageBoxButtons.OK, result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,6 +63,7 @@
|
|||
<Compile Include="ConductorOneActiveTests.cs" />
|
||||
<Compile Include="ConductorTests.cs" />
|
||||
<Compile Include="DebugConverterTests.cs" />
|
||||
<Compile Include="EqualityConverterTests.cs" />
|
||||
<Compile Include="EventActionTests.cs" />
|
||||
<Compile Include="EventAggregatorTests.cs" />
|
||||
<Compile Include="ExecuteTests.cs" />
|
||||
|
@ -70,6 +71,7 @@
|
|||
<Compile Include="IoCTests.cs" />
|
||||
<Compile Include="LabelledValueTests.cs" />
|
||||
<Compile Include="LambdaComparerTests.cs" />
|
||||
<Compile Include="MessageBoxTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PropertyChangedBaseTests.cs" />
|
||||
<Compile Include="PropertyChangedExtensionsTests.cs" />
|
||||
|
|
Loading…
Reference in New Issue