summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs116
1 files changed, 116 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs
new file mode 100644
index 00000000..7bab5676
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs
@@ -0,0 +1,116 @@
+´╗┐using System;
+using System.Collections.Generic;
+
+using Xamarin.Forms;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public class BaseForEvents : ContentView
+ {
+ protected int baseClicked;
+ protected void HandleClickedOnBase (object sender, EventArgs e)
+ {
+ baseClicked++;
+ }
+ }
+
+ public class ElementWithEvent : ContentView
+ {
+ public event EventHandler Clicked;
+
+ public void SendClicked ()
+ {
+ var eh = Clicked;
+ if (eh != null)
+ eh (this, EventArgs.Empty);
+ }
+ }
+
+ public class ElementWithGenericEvent : ContentView
+ {
+ public event EventHandler<ItemTappedEventArgs> Clicked;
+
+ public void SendClicked ()
+ {
+ var eh = Clicked;
+ if (eh != null)
+ eh (this, new ItemTappedEventArgs ("foo", "bar"));
+ }
+ }
+
+ public partial class EventsConnection : BaseForEvents
+ {
+ public EventsConnection ()
+ {
+ InitializeComponent ();
+ }
+
+ public EventsConnection (bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ int clicked;
+ public void HandleClicked (object sender, EventArgs e)
+ {
+ clicked++;
+ }
+
+ int genericClicked;
+ public void HandleGenericClicked (object sender, ItemTappedEventArgs e)
+ {
+ genericClicked++;
+ }
+
+ int asyncPrivateClicked;
+ async void HandleClickedPrivateAsync (object sender, EventArgs e)
+ {
+ asyncPrivateClicked++;
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestClicked (bool useCompiledXaml)
+ {
+ var layout = new EventsConnection (useCompiledXaml);
+ Assert.AreEqual (0, layout.clicked);
+ layout.elementWithEvent.SendClicked ();
+ Assert.AreEqual (1, layout.clicked);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestGenericClicked (bool useCompiledXaml)
+ {
+ var layout = new EventsConnection (useCompiledXaml);
+ Assert.AreEqual (0, layout.genericClicked);
+ layout.elementWithGenericEvent.SendClicked ();
+ Assert.AreEqual (1, layout.genericClicked);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestHandlerOnBase (bool useCompiledXaml)
+ {
+ var layout = new EventsConnection (useCompiledXaml);
+ Assert.AreEqual (0, layout.baseClicked);
+ layout.eventHandlerOnBase.SendClicked ();
+ Assert.AreEqual (1, layout.baseClicked);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestAsyncPrivateHandler (bool useCompiledXaml)
+ {
+ var layout = new EventsConnection (useCompiledXaml);
+ Assert.AreEqual (0, layout.asyncPrivateClicked);
+ layout.elementwithAsyncprivateHandler.SendClicked ();
+ Assert.AreEqual (1, layout.asyncPrivateClicked);
+ }
+ }
+ }
+} \ No newline at end of file