Add (passing) test for #5290
authorStephane Delcroix <stephane@delcroix.org>
Tue, 19 Feb 2019 10:17:02 +0000 (11:17 +0100)
committerStephane Delcroix <stephane@delcroix.org>
Tue, 19 Feb 2019 10:17:02 +0000 (11:17 +0100)
Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml.cs [new file with mode: 0644]

diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml
new file mode 100644 (file)
index 0000000..7332951
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage
+               xmlns="http://xamarin.com/schemas/2014/forms"
+               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+               x:Class="Xamarin.Forms.Xaml.UnitTests.Gh5290"
+               NullableTime="{Binding Time, Mode=TwoWay}">     
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh5290.xaml.cs
new file mode 100644 (file)
index 0000000..3c498e3
--- /dev/null
@@ -0,0 +1,46 @@
+using System;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+       public class Gh5290VM
+       {
+               public TimeSpan? Time { get; set; }
+       }
+
+       public partial class Gh5290 : ContentPage
+       {
+               public static readonly BindableProperty NullableTimeProperty =
+                       BindableProperty.Create("NullableTime", typeof(TimeSpan?), typeof(Gh5290), default(TimeSpan?));
+
+               public TimeSpan? NullableTime {
+                       get => (TimeSpan?)GetValue(NullableTimeProperty);
+                       set => SetValue(NullableTimeProperty, value);
+               }
+
+               public Gh5290() => InitializeComponent();
+               public Gh5290(bool useCompiledXaml)
+               {
+                       //this stub will be replaced at compile time
+               }
+
+               [TestFixture]
+               class Tests
+               {
+                       [SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices();
+                       [TearDown] public void TearDown() => Device.PlatformServices = null;
+
+                       [Test]
+                       public void TwoWayBindingToNullable([Values(false, true)]bool useCompiledXaml)
+                       {
+                               var vm = new Gh5290VM { Time = TimeSpan.FromMinutes(42) };
+                               var layout = new Gh5290(useCompiledXaml) { BindingContext = vm };
+                               Assert.That(layout.NullableTime, Is.EqualTo(TimeSpan.FromMinutes(42)));
+
+                               layout.SetValueFromRenderer(NullableTimeProperty, null);
+                               Assert.That(vm.Time, Is.Null);
+                       }
+               }
+       }
+}
\ No newline at end of file