public void Q554072_3() { var control = new EventToCommandTestView(); Window.Content = control; EnqueueShowWindow(); EnqueueCallback(() => { EventToCommandTestViewModel vm = (EventToCommandTestViewModel)control.DataContext; Assert.AreEqual(2, vm.Q554072CommandCount); }); EnqueueTestComplete(); }
public async Task Q554072_3() { #endif var control = new EventToCommandTestView(); Window.Content = control; #if NETFX_CORE await #endif EnqueueShowWindow(); EnqueueCallback(() => { EventToCommandTestViewModel vm = (EventToCommandTestViewModel)control.DataContext; #if !NETFX_CORE Assert.AreEqual(2, vm.Q554072CommandCount); #else Assert.IsTrue(vm.Q554072CommandCount > 1); #endif }); EnqueueTestComplete(); }
public async Task EventToCommandInWindow() { #endif var userControl = new EventToCommandTestView(); Window.Content = userControl; var viewModel = (EventToCommandTestViewModel)userControl.DataContext; Assert.AreEqual(0, viewModel.LoadedCount); Assert.AreEqual(0, viewModel.SelectionChangedCount); #if NETFX_CORE await #endif EnqueueTestWindowMainCallback(() => { foreach (EventToCommand trigger in Interaction.GetBehaviors(userControl)) { Assert.AreEqual(1, trigger.RaiseSourceChangedCount); } Assert.AreEqual(1, viewModel.LoadedCount); Assert.AreEqual("test", viewModel.LoadedParameter); Assert.AreEqual(0, viewModel.DummyCommand.InvokeCount); Assert.AreEqual(1, viewModel.ButtonLoadedCount); Assert.AreEqual(0, viewModel.SelectionChangedCount); userControl.listBox.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount); Assert.AreEqual("item2", viewModel.SelectionChangedParameter.AddedItems[0].With(x => x as ListBoxItem).Content); Assert.AreEqual(0, viewModel.SelectionChangedCount2); userControl.listBox2.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount2); Assert.AreEqual("foo", viewModel.SelectionChangedParameter2); Assert.AreEqual(0, viewModel.SelectionChangedCount3); userControl.listBox3.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount3); Assert.AreEqual("item2", viewModel.SelectionChangedParameter3.With(x => x as ListBoxItem).Content); Assert.IsFalse(userControl.listBox4.IsEnabled); viewModel.SelectionChangedCommandParameter4 = true; Assert.IsTrue(userControl.listBox4.IsEnabled); viewModel.SelectionChangedCommandParameter4 = false; Assert.IsFalse(userControl.listBox4.IsEnabled); var eventToCommand = (EventToCommand)Interaction.GetBehaviors(userControl.listBox4)[0]; eventToCommand.Command = viewModel.SelectionChangedCommand2; Assert.IsTrue(userControl.listBox4.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = false; eventToCommand.Command = viewModel.SelectionChangedCommand4; Assert.IsTrue(userControl.listBox4.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = true; Assert.IsFalse(userControl.listBox4.IsEnabled); Assert.IsFalse(userControl.listBox5.IsEnabled); viewModel.SelectionChangedCommandParameter5 = true; Assert.IsTrue(userControl.listBox5.IsEnabled); viewModel.SelectionChangedCommandParameter5 = false; Assert.IsFalse(userControl.listBox5.IsEnabled); eventToCommand = (EventToCommand)Interaction.GetBehaviors(userControl).First(x => ((EventToCommand)x).SourceName == "listBox5"); eventToCommand.Command = viewModel.SelectionChangedCommand2; Assert.IsTrue(userControl.listBox5.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = false; eventToCommand.Command = viewModel.SelectionChangedCommand5; Assert.IsTrue(userControl.listBox5.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = true; Assert.IsFalse(userControl.listBox5.IsEnabled); }); EnqueueTestComplete(); }
public async Task EventToCommandInWindow() { #endif var userControl = new EventToCommandTestView(); Window.Content = userControl; var viewModel = (EventToCommandTestViewModel)userControl.DataContext; Assert.AreEqual(0, viewModel.LoadedCount); Assert.AreEqual(0, viewModel.SelectionChangedCount); #if NETFX_CORE await #endif EnqueueTestWindowMainCallback(() => { foreach(EventToCommand trigger in Interaction.GetBehaviors(userControl)) { Assert.AreEqual(1, trigger.RaiseSourceChangedCount); } Assert.AreEqual(1, viewModel.LoadedCount); Assert.AreEqual("test", viewModel.LoadedParameter); Assert.AreEqual(0, viewModel.DummyCommand.InvokeCount); Assert.AreEqual(1, viewModel.ButtonLoadedCount); Assert.AreEqual(0, viewModel.SelectionChangedCount); userControl.listBox.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount); Assert.AreEqual("item2", viewModel.SelectionChangedParameter.AddedItems[0].With(x => x as ListBoxItem).Content); Assert.AreEqual(0, viewModel.SelectionChangedCount2); userControl.listBox2.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount2); Assert.AreEqual("foo", viewModel.SelectionChangedParameter2); Assert.AreEqual(0, viewModel.SelectionChangedCount3); userControl.listBox3.SelectedIndex = 1; Assert.AreEqual(1, viewModel.SelectionChangedCount3); Assert.AreEqual("item2", viewModel.SelectionChangedParameter3.With(x => x as ListBoxItem).Content); Assert.IsFalse(userControl.listBox4.IsEnabled); viewModel.SelectionChangedCommandParameter4 = true; Assert.IsTrue(userControl.listBox4.IsEnabled); viewModel.SelectionChangedCommandParameter4 = false; Assert.IsFalse(userControl.listBox4.IsEnabled); var eventToCommand = (EventToCommand)Interaction.GetBehaviors(userControl.listBox4)[0]; eventToCommand.Command = viewModel.SelectionChangedCommand2; Assert.IsTrue(userControl.listBox4.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = false; eventToCommand.Command = viewModel.SelectionChangedCommand4; Assert.IsTrue(userControl.listBox4.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = true; Assert.IsFalse(userControl.listBox4.IsEnabled); Assert.IsFalse(userControl.listBox5.IsEnabled); viewModel.SelectionChangedCommandParameter5 = true; Assert.IsTrue(userControl.listBox5.IsEnabled); viewModel.SelectionChangedCommandParameter5 = false; Assert.IsFalse(userControl.listBox5.IsEnabled); eventToCommand = (EventToCommand)Interaction.GetBehaviors(userControl).First(x => ((EventToCommand)x).SourceName == "listBox5"); eventToCommand.Command = viewModel.SelectionChangedCommand2; Assert.IsTrue(userControl.listBox5.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = false; eventToCommand.Command = viewModel.SelectionChangedCommand5; Assert.IsTrue(userControl.listBox5.IsEnabled); eventToCommand.AllowChangingEventOwnerIsEnabled = true; Assert.IsFalse(userControl.listBox5.IsEnabled); }); EnqueueTestComplete(); }