PageRenderTime 20ms CodeModel.GetById 7ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/PrismLibrary/Silverlight/Prism.Interactivity.Tests/UpdateTextBindingOnPropertyChangedFixture.cs

#
C# | 70 lines | 47 code | 7 blank | 16 comment | 0 complexity | edf5771b40f857f8124c58fc5970c93d MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Diagnostics;
19using System.Net;
20using System.Windows;
21using System.Windows.Controls;
22using System.Windows.Data;
23using System.Windows.Documents;
24using System.Windows.Ink;
25using System.Windows.Input;
26using System.Windows.Media;
27using System.Windows.Media.Animation;
28using System.Windows.Shapes;
29using Microsoft.Practices.Prism.Interactivity;
30using Microsoft.Silverlight.Testing;
31using Microsoft.VisualStudio.TestTools.UnitTesting;
32
33#pragma warning disable 0618
34namespace Prism.Interactivity.Tests
35{
36    [TestClass]
37    public class UpdateTextBindingOnPropertyChangedFixture : SilverlightTest
38    {
39        [TestMethod]
40        [Asynchronous]
41        [Timeout(5000)]
42        public void TestMethod1()
43        {
44            var behavior = new UpdateTextBindingOnPropertyChanged();
45
46            var bindingSource = new BindingSource() { Value = "InitialValue" };
47            var binding = new Binding("Value") { Source = bindingSource, Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.Explicit };
48
49            var textBox = new TextBox();
50            base.TestPanel.Children.Add(textBox);
51
52            EnqueueCallback(() =>
53                                {
54                                    textBox.SetBinding(TextBox.TextProperty, binding);
55                                    System.Windows.Interactivity.Interaction.GetBehaviors(textBox).Add(behavior);
56
57                                    textBox.Text = "NewValue";
58                                });
59
60            EnqueueCallback(() => Assert.AreEqual("NewValue", bindingSource.Value));
61            EnqueueTestComplete();
62        }
63    }
64
65    public class BindingSource
66    {
67        public string Value { get; set; }
68    }
69}
70#pragma warning restore 0618