diff options
6 files changed, 283 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/PointViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PointViewModelTests.cs new file mode 100644 index 0000000..d9811b5 --- /dev/null +++ b/Xamarin.PropertyEditing.Tests/PointViewModelTests.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.PropertyEditing.Drawing; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Tests +{ + [TestFixture] + internal class PointViewModelTests + : PropertyViewModelTests<CommonPoint, PointPropertyViewModel> + { + [Test] + public void X () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.Value, Is.EqualTo (new CommonPoint (0, 0))); + + bool xChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(PointPropertyViewModel.X)) + xChanged = true; + if (args.PropertyName == nameof(PointPropertyViewModel.Value)) + valueChanged = true; + }; + + vm.X = 5; + Assert.That (vm.Value.X, Is.EqualTo (5)); + Assert.That (xChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + [Test] + public void Y () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.Value, Is.EqualTo (new CommonPoint (0, 0))); + + bool yChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(PointPropertyViewModel.Y)) + yChanged = true; + if (args.PropertyName == nameof(PointPropertyViewModel.Value)) + valueChanged = true; + }; + + vm.Y = 5; + Assert.That (vm.Value.Y, Is.EqualTo (5)); + Assert.That (yChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + [Test] + public void ValueChangesXY () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.X, Is.EqualTo (0)); + Assume.That (vm.Y, Is.EqualTo (0)); + + bool xChanged = false, yChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(PointPropertyViewModel.X)) + xChanged = true; + if (args.PropertyName == nameof(PointPropertyViewModel.Y)) + yChanged = true; + if (args.PropertyName == nameof(PointPropertyViewModel.Value)) + valueChanged = true; + }; + + vm.Value = new CommonPoint (5, 10); + + Assert.That (vm.X, Is.EqualTo (5)); + Assert.That (vm.Y, Is.EqualTo (10)); + Assert.That (yChanged, Is.True); + Assert.That (xChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + protected override CommonPoint GetRandomTestValue (Random rand) + { + return new CommonPoint (rand.Next (), rand.Next ()); + } + + protected override PointPropertyViewModel GetViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors) + { + return new PointPropertyViewModel (property, editors); + } + } +} diff --git a/Xamarin.PropertyEditing.Tests/SizeViewModelTests.cs b/Xamarin.PropertyEditing.Tests/SizeViewModelTests.cs new file mode 100644 index 0000000..2e6f198 --- /dev/null +++ b/Xamarin.PropertyEditing.Tests/SizeViewModelTests.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.PropertyEditing.Drawing; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Tests +{ + internal class SizeViewModelTests + : PropertyViewModelTests<CommonSize, SizePropertyViewModel> + { + [Test] + public void Width () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.Value, Is.EqualTo (new CommonSize (0, 0))); + + bool xChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(SizePropertyViewModel.Width)) + xChanged = true; + if (args.PropertyName == nameof(SizePropertyViewModel.Value)) + valueChanged = true; + }; + + vm.Width = 5; + Assert.That (vm.Value.Width, Is.EqualTo (5)); + Assert.That (xChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + [Test] + public void Height () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.Value, Is.EqualTo (new CommonSize (0, 0))); + + bool yChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(SizePropertyViewModel.Height)) + yChanged = true; + if (args.PropertyName == nameof(SizePropertyViewModel.Value)) + valueChanged = true; + }; + + vm.Height = 5; + Assert.That (vm.Value.Height, Is.EqualTo (5)); + Assert.That (yChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + [Test] + public void ValueChangesWidthHeight () + { + var property = GetPropertyMock (); + var editor = GetBasicEditor (property.Object); + var vm = GetViewModel (property.Object, new[] { editor }); + Assume.That (vm.Width, Is.EqualTo (0)); + Assume.That (vm.Height, Is.EqualTo (0)); + + bool xChanged = false, yChanged = false, valueChanged = false; + vm.PropertyChanged += (sender, args) => { + if (args.PropertyName == nameof(SizePropertyViewModel.Width)) + xChanged = true; + if (args.PropertyName == nameof(SizePropertyViewModel.Height)) + yChanged = true; + if (args.PropertyName == nameof(SizePropertyViewModel.Value)) + valueChanged = true; + }; + + vm.Value = new CommonSize (5, 10); + + Assert.That (vm.Width, Is.EqualTo (5)); + Assert.That (vm.Height, Is.EqualTo (10)); + Assert.That (yChanged, Is.True); + Assert.That (xChanged, Is.True); + Assert.That (valueChanged, Is.True); + } + + protected override CommonSize GetRandomTestValue (Random rand) + { + return new CommonSize (rand.Next (), rand.Next ()); + } + + protected override SizePropertyViewModel GetViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors) + { + return new SizePropertyViewModel (property, editors); + } + } +} diff --git a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj index a2748b2..17311cc 100644 --- a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj +++ b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj @@ -70,9 +70,11 @@ <Compile Include="MockPropertyInfo\MockPropertyInfo.cs" /> <Compile Include="MockPropertyInfo\MockEnumPropertyInfo.cs" /> <Compile Include="MockPropertyProviderTests.cs" /> + <Compile Include="PointViewModelTests.cs" /> <Compile Include="RadialGradientBrushPropertyViewModelTests.cs" /> <Compile Include="LinearGradientBrushPropertyViewModelTests.cs" /> <Compile Include="ImageBrushPropertyViewModelTests.cs" /> + <Compile Include="SizeViewModelTests.cs" /> <Compile Include="SolidBrushPropertyViewModelTests.cs" /> <Compile Include="ConstrainedPropertyViewModelTests.cs" /> <Compile Include="EnumPropertyViewModelTests.cs" /> diff --git a/Xamarin.PropertyEditing/ViewModels/PointPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PointPropertyViewModel.cs new file mode 100644 index 0000000..f898332 --- /dev/null +++ b/Xamarin.PropertyEditing/ViewModels/PointPropertyViewModel.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Xamarin.PropertyEditing.Drawing; + +namespace Xamarin.PropertyEditing.ViewModels +{ + internal class PointPropertyViewModel + : PropertyViewModel<CommonPoint> + { + public PointPropertyViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors) + : base (property, editors) + { + } + + public double X + { + get { return Value.X; } + set + { + if (Value.X == value) + return; + + Value = new CommonPoint (value, Value.X); + } + } + + public double Y + { + get { return Value.Y; } + set + { + if (Value.Y == value) + return; + + Value = new CommonPoint (Value.Y, value); + } + } + + protected override void OnValueChanged () + { + base.OnValueChanged (); + OnPropertyChanged (nameof(X)); + OnPropertyChanged (nameof(Y)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing/ViewModels/SizePropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/SizePropertyViewModel.cs new file mode 100644 index 0000000..c568ca2 --- /dev/null +++ b/Xamarin.PropertyEditing/ViewModels/SizePropertyViewModel.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Xamarin.PropertyEditing.Drawing; + +namespace Xamarin.PropertyEditing.ViewModels +{ + internal class SizePropertyViewModel + : PropertyViewModel<CommonSize> + { + public SizePropertyViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors) + : base (property, editors) + { + } + + public double Width + { + get { return Value.Width; } + set + { + if (Value.Width == value) + return; + + Value = new CommonSize (value, Value.Height); + } + } + + public double Height + { + get { return Value.Height; } + set + { + if (Value.Height == value) + return; + + Value = new CommonSize (Value.Width, value); + } + } + + protected override void OnValueChanged () + { + base.OnValueChanged (); + OnPropertyChanged (nameof(Width)); + OnPropertyChanged (nameof(Height)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj index 5261231..cf5eb55 100644 --- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj +++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj @@ -101,10 +101,12 @@ <Compile Include="ViewModels\NumericPropertyViewModel.cs" /> <Compile Include="ViewModels\ObjectViewModel.cs" /> <Compile Include="ViewModels\PanelViewModel.cs" /> + <Compile Include="ViewModels\PointPropertyViewModel.cs" /> <Compile Include="ViewModels\PredefinedValuesViewModel.cs" /> <Compile Include="ViewModels\PropertiesViewModel.cs" /> <Compile Include="ViewModels\PropertyViewModel.cs" /> <Compile Include="ViewModels\RelayCommand.cs" /> + <Compile Include="ViewModels\SizePropertyViewModel.cs" /> <Compile Include="ViewModels\SolidBrushPropertyViewModel.cs" /> <Compile Include="ViewModels\StringPropertyViewModel.cs" /> <Compile Include="PropertyArrangeMode.cs" /> |