Ejemplo n.º 1
0
        public void GivenTextBoxWithBinding_WhenFocusLost_ThenValueSetToBinding()
        {
            // Given
            var textBoxDataContext = new TestBindingSource();

            var textBox = new TextBox();

            textBox.DataContext = textBoxDataContext;
            textBox.SetBinding(TextBox.TextProperty, nameof(TestBindingSource.TestProperty));

            TextBoxModificationBinding.Create(textBox);

            var otherTextBox = new TextBox();

            new Window
            {
                Content = new StackPanel
                {
                    Children =
                    {
                        textBox,
                        otherTextBox
                    }
                }
            }.Show();

            // When
            textBox.Focus();
            otherTextBox.Focus();

            // Then
            Assert.That(textBoxDataContext.SetCount, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        private void TestNew_Click(object sender, EventArgs e)
        {
            var editForm = new EditTestForm();

            editForm.ShowDialog();
            if (editForm.DialogResult == DialogResult.OK)
            {
                guide.Tests.Add(new Test(editForm.test));
                TestBindingSource.ResetBindings(false);
                guide.changed = true;
            }
        }
Ejemplo n.º 3
0
        private void TestEdit_Click(object sender, EventArgs e)
        {
            if (!(TestList.SelectedItem is Test item))
            {
                return;
            }
            int index    = guide.Tests.IndexOf(item);
            var editForm = new EditTestForm(item);

            editForm.ShowDialog();
            if (editForm.DialogResult == DialogResult.OK)
            {
                guide.Tests[index] = new Test(editForm.test);
                TestBindingSource.ResetBindings(false);
                guide.changed = true;
            }
        }
Ejemplo n.º 4
0
        private void TestDelete_Click(object sender, EventArgs e)
        {
            if (!(TestList.SelectedItem is Test item))
            {
                return;
            }
            var mess = MessageBox.Show($"Действительно удалить тест {item.Name} ? ",
                                       "Удаление", MessageBoxButtons.YesNo);

            if (DialogResult.Yes == mess)
            {
                if (TestBindingSource.DataSource != guide)
                {
                    ((List <Test>)TestBindingSource.DataSource).Remove(item);
                }
                guide.Tests.Remove(item);
                TestBindingSource.ResetBindings(false);
                guide.changed = true;
            }
        }
Ejemplo n.º 5
0
        private void TSearch_Click(object sender, EventArgs e)
        {
            var search = new TestSearchForm <Test>(guide.Tests);

            search.ShowDialog();
            if (search.DialogResult == DialogResult.Yes)
            {
                TestBindingSource.DataSource = search.Searched;
                if (search.Searched.Count == 0)
                {
                    MessageBox.Show("К сожалению, ничего не найденo...", "Ошибка");
                }
            }
            else if (search.DialogResult == DialogResult.No)
            {
                TestBindingSource.DataSource = guide.Tests;
            }

            TestBindingSource.ResetBindings(false);
        }
Ejemplo n.º 6
0
        public void GivenTextBoxWithBinding_WhenReturnKeyPressed_ThenValueSetToBinding()
        {
            // Given
            var textBoxDataContext = new TestBindingSource();

            var textBox = new TextBox();

            textBox.DataContext = textBoxDataContext;
            textBox.SetBinding(TextBox.TextProperty, nameof(TestBindingSource.TestProperty));

            TextBoxModificationBinding.Create(textBox);

            // When
            textBox.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice,
                                                Substitute.For <PresentationSource>(),
                                                0, Key.Return)
            {
                RoutedEvent = Keyboard.KeyDownEvent
            });

            // Then
            Assert.That(textBoxDataContext.SetCount, Is.EqualTo(1));
        }