in class/WPF.Toolkit/:
[moon.git] / test / 2.0 / moon-unit / System.Windows.Threading / CrossThreadAccessTest.cs
blobcf405cb8d83472ef3318f2171d65e549e92a040e
1 using System;
2 using System.ComponentModel;
3 using System.Windows;
4 using System.Windows.Controls;
5 using System.Windows.Threading;
7 using Microsoft.Silverlight.Testing;
8 using Microsoft.VisualStudio.TestTools.UnitTesting;
10 namespace MoonTest.System.Windows.Threading {
12 [TestClass]
13 public class CrossThreadAccessTest : SilverlightTest {
15 private BackgroundWorker bw = new BackgroundWorker ();
16 private bool complete;
17 // async tests are nice but we need to make sure the async code gets executed
18 private bool executed;
20 public CrossThreadAccessTest ()
22 bw.DoWork += delegate (object sender, DoWorkEventArgs e) {
23 Action action = (e.Argument as Action);
24 Assert.Throws<UnauthorizedAccessException> (delegate {
25 executed = true; // been there, done that :)
26 action ();
27 });
29 bw.RunWorkerCompleted += delegate {
30 complete = true;
34 private void CrossThreadTest (Action action)
36 executed = complete = false;
37 Enqueue (() => { bw.RunWorkerAsync (action); });
38 EnqueueConditional (() => { return executed && complete; });
39 EnqueueTestComplete ();
42 [TestMethod]
43 [Asynchronous]
44 public void ApplicationTest ()
46 CrossThreadTest (() => {
47 new Application ();
48 });
51 [TestMethod]
52 [Asynchronous]
53 public void LoadComponentTest ()
55 CrossThreadTest (() => {
56 Application.LoadComponent (this, new Uri ("/threads3;component/App.xaml", UriKind.Relative));
57 });
60 [TestMethod]
61 [Asynchronous]
62 public void GetRootVisualTest ()
64 CrossThreadTest (() => {
65 Assert.IsNotNull (Application.Current.RootVisual);
66 });
69 [TestMethod]
70 [Asynchronous]
71 public void SetRootVisualTest ()
73 TextBlock b = new TextBlock ();
74 CrossThreadTest (() => {
75 Application.Current.RootVisual = b;
76 });
79 [TestMethod]
80 [Asynchronous]
81 public void EventTest ()
83 TextBlock e1 = new TextBlock ();
84 CrossThreadTest (() => {
85 e1.GotFocus += delegate (object sender, RoutedEventArgs ev) {
87 });
90 [TestMethod]
91 [Asynchronous]
92 public void CreateDependencyObjectTest ()
94 CrossThreadTest (() => {
95 new TextBlock ();
96 });
99 [TestMethod]
100 [Asynchronous]
101 public void DependencyObjectFindNameTest ()
103 TextBlock b = new TextBlock ();
104 CrossThreadTest (() => {
105 b.FindName ("t");
109 [TestMethod]
110 [Asynchronous]
111 public void CreateDependencyPropertyTest ()
113 TextBlock e1 = new TextBlock ();
114 CrossThreadTest (() => {
115 e1.Text = "";
119 [TestMethod]
120 [Asynchronous]
121 public void DispatcherTimerTest ()
123 CrossThreadTest (() => {
124 new DispatcherTimer ();