diff options
author | Eric Maupin <me@ermau.com> | 2018-04-02 21:02:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 21:02:48 +0300 |
commit | 26a4f7008de475e1a6e0b70f8dffeadf12a4c52f (patch) | |
tree | 0f0f7dd24491010e8d67d1ad3eedc14e986044d0 /Xamarin.PropertyEditing.Tests | |
parent | adc2724fb684cf2459f8f3f5441fc643f9dab811 (diff) | |
parent | dae1a904017b90b00d859610565d06364af10a1c (diff) |
Merge pull request #208 from xamarin/lewing-multi-nullable
Add test cases for empty editor lists and null ValueInfo<T> values
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/BytePropertyViewModelTests.cs | 2 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs | 50 |
2 files changed, 50 insertions, 2 deletions
diff --git a/Xamarin.PropertyEditing.Tests/BytePropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/BytePropertyViewModelTests.cs index cd61a7a..3a83cc6 100644 --- a/Xamarin.PropertyEditing.Tests/BytePropertyViewModelTests.cs +++ b/Xamarin.PropertyEditing.Tests/BytePropertyViewModelTests.cs @@ -36,7 +36,7 @@ namespace Xamarin.PropertyEditing.Tests protected override byte GetConstrainedRandomValueBelowBounds (Random rand, out byte max, out byte min) { var value = (byte)rand.Next (2, byte.MaxValue - 2); - max = (byte)rand.Next (value + 1, byte.MaxValue); + max = (byte)rand.Next (value + 2, byte.MaxValue); min = (byte)rand.Next (value + 1, (byte)(max - 1)); return value; diff --git a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs index 2e9a093..18b8e30 100644 --- a/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs +++ b/Xamarin.PropertyEditing.Tests/PropertyViewModelTests.cs @@ -141,6 +141,55 @@ namespace Xamarin.PropertyEditing.Tests } [Test] + public void MultipleValuesNull () + { + var basicEditor = GetBasicEditor (); + var prop = basicEditor.Properties.First (); + var editor = new Mock<IObjectEditor> (); + editor.SetupGet (o => o.Target).Returns (new TestClass ()); + editor.SetupGet (oe => oe.Properties).Returns (new [] { prop }); + editor.Setup (oe => oe.GetValueAsync<TValue> (prop, null)).ReturnsAsync ((ValueInfo<TValue>)null); + var e2 = new Mock<IObjectEditor> (); + e2.SetupGet (o => o.Target).Returns (new TestClass ()); + e2.SetupGet (oe => oe.Properties).Returns (new [] { prop }); + e2.Setup (oe => oe.GetValueAsync<TValue> (prop, null)).ReturnsAsync ((ValueInfo<TValue>)null); + var vm = GetViewModel (basicEditor.Properties.First (), new [] { e2.Object, editor.Object }); + + Assert.That (vm.Value, Is.EqualTo (default (TValue))); + Assert.That (vm.MultipleValues, Is.False); + } + + [Test] + public void MultipleValuesOneNull () + { + TValue value = GetNonDefaultRandomTestValue (); + + var basicEditor = GetBasicEditor (value); + var prop = basicEditor.Properties.First (); + var editor = new Mock<IObjectEditor> (); + editor.SetupGet (o => o.Target).Returns (new TestClass ()); + editor.SetupGet (oe => oe.Properties).Returns (new [] { prop }); + editor.Setup (oe => oe.GetValueAsync<TValue> (prop, null)).ReturnsAsync ((ValueInfo<TValue>)null); + var vm = GetViewModel (basicEditor.Properties.First (), new [] { basicEditor, editor.Object }); + + Assert.That (vm.Value, Is.EqualTo (default (TValue))); + Assert.That (vm.MultipleValues, Is.True); + } + + [Test] + public void EmptyEditorList () + { + TValue value = GetNonDefaultRandomTestValue (); + + var vm = GetBasicTestModel (value); + Assume.That (vm.Value, Is.EqualTo (value)); + vm.Editors.Remove (vm.Editors.First ()); + + Assert.That (vm.Value, Is.EqualTo (default (TValue))); + Assert.That (vm.MultipleValues, Is.False); + } + + [Test] public void MultipleValuesDontMatchButSourcesDo () { TValue value = GetNonDefaultRandomTestValue (); @@ -1054,7 +1103,6 @@ namespace Xamarin.PropertyEditing.Tests mock.SetupGet (pi => pi.Type).Returns (typeof(TValueReal)); mock.SetupGet (pi => pi.Name).Returns (name); mock.SetupGet (pi => pi.Category).Returns (category); - AugmentPropertyMock (mock); return mock; |