public void Revert_value_on_incorrect_input()
        {
            var waybill = new Waybill(new Address("тест"), new Supplier());
            var line    = new WaybillLine(waybill);

            line.RetailCost = 150;
            waybill.AddLine(line);
            WpfTestHelper.WithWindow2(async w => {
                var grid                 = new DataGrid2();
                grid.IsReadOnly          = false;
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new DataGridTextColumnEx {
                    Binding = new Binding("Product")
                });
                grid.Columns.Add(new DataGridTextColumnEx {
                    Binding = new Binding("RetailCost")
                });
                w.Content        = grid;
                grid.ItemsSource = waybill.Lines;
                await w.WaitIdle();
                var cell = grid.Descendants <DataGridCell>()
                           .First(x => x.Column == grid.Columns[1] && x.DataContext == line);
                Assert.IsTrue(cell.Focus());
                cell.SendKey(Key.F2);
                Assert.IsTrue(cell.IsEditing);
                var input = cell.Descendants <TextBox>().First();
                input.SendText("asd");
                grid.SendKey(Key.Down);
                Assert.IsFalse(cell.IsEditing);
                Assert.AreEqual(150, line.RetailCost);
            });
        }
        public void Scroll_on_wheel()
        {
            var items = Enumerable.Range(1, 100).Select(i => Tuple.Create(i.ToString())).ToList();

            WpfTestHelper.WithWindow2(async w => {
                var grid = new DataGrid2();
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new DataGridTextColumn {
                    Binding = new Binding("Item1")
                });
                w.Content = grid;

                grid.RaiseEvent(new MouseWheelEventArgs(System.Windows.Input.Mouse.PrimaryDevice,
                                                        0,
                                                        -System.Windows.Input.Mouse.MouseWheelDeltaForOneLine)
                {
                    RoutedEvent = UIElement.PreviewMouseWheelEvent,
                    Source      = grid,
                });
                grid.ItemsSource = items;
                await grid.WaitIdle();
                grid.CurrentItem   = items[0];
                grid.CurrentColumn = grid.Columns[0];
                grid.RaiseEvent(new MouseWheelEventArgs(System.Windows.Input.Mouse.PrimaryDevice,
                                                        0,
                                                        -System.Windows.Input.Mouse.MouseWheelDeltaForOneLine)
                {
                    RoutedEvent = UIElement.PreviewMouseWheelEvent,
                    Source      = grid,
                });
                Assert.AreEqual("2", ((Tuple <string>)grid.CurrentItem).Item1);

                await w.WaitIdle();
            });
        }
        public void Do_not_duplicate_result_subscriptions()
        {
            var shell = new Conductor <IScreen>();
            var model = new TestScreen();

            Init(model);

            WpfTestHelper.WithWindow2(async w => {
                var view = (FrameworkElement)ViewLocator.LocateForModel(shell, null, null);
                ViewModelBinder.Bind(shell, view, null);

                w.Content        = view;
                shell.ActiveItem = model;
                await view.WaitLoaded();

                shell.DeactivateItem(model, false);
                await w.WaitIdle();

                shell.ActivateItem(model);
                await w.WaitIdle();

                model.Raise();
                await w.WaitIdle();
            });

            Assert.AreEqual(1, model.ProcessedCount);
        }
Exemple #4
0
        public void Move_focus()
        {
            WpfTestHelper.WithWindow2(async w => {
                var model = new CatalogViewModel();
                var view  = Bind(model);
                w.Content = view;

                await view.WaitLoaded();
                scheduler.Start();
                await view.WaitIdle();
                var names = view.Descendants <DataGrid2>().First(x => x.Name == "CatalogNames");
                var forms = view.Descendants <DataGrid2>().First(x => x.Name == "Catalogs");
                names.Focus();
                Assert.IsTrue(names.IsKeyboardFocusWithin);
                Assert.IsFalse(forms.IsKeyboardFocusWithin);
                var id = session.Query <CatalogName>()
                         .First(c => c.HaveOffers && session.Query <Catalog>().Count(x => x.HaveOffers && x.Name == c) > 1)
                         .Id;
                names.SelectedItem = names.Items.OfType <CatalogName>().First(x => x.Id == id);
                scheduler.Start();
                names.RaiseEvent(WpfTestHelper.KeyArgs(names, Key.Enter));
                await view.WaitIdle();
                Assert.IsFalse(names.IsKeyboardFocusWithin);
                Assert.IsTrue(forms.IsKeyboardFocusWithin);
            });
        }
Exemple #5
0
        public void Auto_edit()
        {
            var waybill = Fixture <LocalWaybill>().Waybill;

            WpfTestHelper.WithWindow2(async w => {
                var model = new WaybillDetails(waybill.Id);
                var view  = (WaybillDetailsView)Bind(model);
                w.Content = view;

                var grid = view.Descendants <DataGrid>().First(g => g.Name == "Lines");
                await grid.WaitLoaded();
                Assert.IsNotNull(grid.CellStyle);

                grid.SelectedItem = waybill.Lines[0];
                grid.RaiseEvent(WpfTestHelper.TextArgs("1"));
                var column = grid.Columns.First(c => c.Header is TextBlock && ((TextBlock)c.Header).Text.Equals("Розничная наценка"));
                var cell   = DataGridHelper.GetCell(
                    (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.CurrentCell.Item),
                    column,
                    grid.Columns);
                Assert.IsTrue(cell.IsEditing);
                Assert.AreEqual("1", ((TextBox)cell.Content).Text);
            });

            WpfTestHelper.CleanSafeError();
        }
        public void Quick_search()
        {
            var term = session.Query <Catalog>().First(c => c.HaveOffers).FullName.Substring(0, 1);

            WpfTestHelper.WithWindow2(async w => {
                var model = new CatalogViewModel();
                var view  = Bind(model);
                w.Content = view;

                await view.WaitLoaded();

                var searchCheck       = view.Descendants <CheckBox>().First(c => c.Name == "CatalogSearch");
                searchCheck.IsChecked = true;
                await view.WaitIdle();
                scheduler.Start();

                var grid = view.Descendants <DataGrid>().First(g => g.Name == "Items");
                grid.SendText(term);
                var search = view.Descendants <TextBox>().First(b => b.Name == "SearchText");
                Assert.IsTrue(search.IsVisible);
                Assert.AreEqual(term, search.Text);
                search.Text = "";

                var enable       = view.Descendants <CheckBox>().First(c => c.Name == "IsQuickSearchEnabled");
                enable.IsChecked = true;

                grid.SendText(term);
                Assert.AreEqual("", search.Text);
                var quicksearch = view.Descendants <ContentControl>().First(c => c.Name == "QuickSearch")
                                  .Descendants <TextBox>().First(c => c.Name == "SearchText");
                Assert.AreEqual(term, quicksearch.Text, quicksearch.GetHashCode().ToString());
            });
        }
        public void Style_fixture()
        {
            var offers = new List <Offer>();

            offers.Add(new Offer(new Price("тест"), 100)
            {
                IsGrouped        = true,
                BuyingMatrixType = BuyingMatrixStatus.Denied,
            });

            WpfTestHelper.WithWindow2(async w => {
                var resources = new ResourceDictionary();
                StyleHelper.Reset();
                StyleHelper.BuildStyles(resources);
                var grid = new DataGrid2();
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new DataGridTextColumn {
                    Binding = new Binding("ProductSynonym")
                });
                grid.Columns.Add(new DataGridTextColumn {
                    Binding = new Binding("OrderCount")
                });
                w.Content = grid;
                StyleHelper.ApplyStyles(typeof(Offer), grid, resources);
                grid.ItemsSource = offers;
                await w.WaitIdle();
                var cells = grid.Descendants <DataGridCell>().ToArray();
                Assert.That(cells.Length, Is.GreaterThan(0));
                foreach (var cell in cells)
                {
                    Assert.AreEqual("#FFFF0000", cell.Background.ToString(), ((TextBlock)cell.Content).Text);
                }
            });
        }
Exemple #8
0
        public void Check_add_from_catalog_enabling()
        {
            user.IsStockEnabled = true;
            session.Save(user);
            var waybill = new Waybill(address, session.Query <Supplier>().First());

            waybill.IsCreatedByUser = true;
            var line = new WaybillLine(waybill)
            {
                Quantity = 1
            };

            waybill.Lines.Add(line);
            session.Save(waybill);

            WpfTestHelper.WithWindow2(async w => {
                var model = new WaybillDetails(waybill.Id);
                var view  = (WaybillDetailsView)Bind(model);
                w.Content = view;

                await view.WaitLoaded();
                var addButton = view.Descendants <Button>().First(b => b.Name == "AddFromCatalog");
                Assert.IsTrue(addButton.Visibility == Visibility.Visible);
                Assert.IsTrue(addButton.IsEnabled);

                view.Descendants <Button>().First(b => b.Name == "Stock")
                .RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                Assert.IsTrue(addButton.Visibility == Visibility.Visible);
                Assert.IsFalse(addButton.IsEnabled);
            });
            WpfTestHelper.CleanSafeError();
        }
 public void Popup_scroll()
 {
     WpfTestHelper.WithWindow2(async w => {
         var selector = InitSelector(w);
         await selector.WaitLoaded();
         selector.IsOpened = true;
         await w.WaitIdle();
         var scrollViewer = selector.Descendants <ScrollViewer>().First();
         Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedVerticalScrollBarVisibility);
     });
 }
        public void Filter_label()
        {
            WpfTestHelper.WithWindow2(async w => {
                var selector = InitSelector(w);
                await selector.WaitLoaded();

                var stackPanel = selector.Descendants <Grid>().FirstOrDefault(g => g.Name == "MainGrid").Descendants <StackPanel>().First();
                Assert.That(stackPanel.AsText(), Is.Not.StringContaining(", фильтр применен"));
                selector.IsOpened = true;
                ((ISelectable)selector.Items[0]).IsSelected = false;
                Assert.That(stackPanel.AsText(), Does.Contain(", фильтр применен"));
            });
        }
Exemple #11
0
        public void Enter_price()
        {
            WpfTestHelper.WithWindow2(async w => {
                var view  = Bind(new PriceViewModel());
                var grid  = (DataGrid)view.FindName("Prices");
                w.Content = view;

                await w.WaitLoaded();
                var keyEventArgs         = WpfTestHelper.KeyArgs(grid, Key.Enter);
                keyEventArgs.RoutedEvent = DataGrid.KeyDownEvent;
                grid.RaiseEvent(keyEventArgs);
            });
            Assert.IsInstanceOf <PriceOfferViewModel>(shell.ActiveItem);
        }
        public void Set_focus_on_empty_grid()
        {
            WpfTestHelper.WithWindow2(async w => {
                var grid  = new DataGrid2();
                w.Content = grid;
                await grid.WaitLoaded();

                Assert.IsFalse(grid.IsKeyboardFocusWithin);
                var point = grid.PointToScreen(new Point(3, 3));
                Mouse.MoveTo(new System.Drawing.Point((int)point.X, (int)point.Y));
                Mouse.Click(MouseButton.Left);
                await w.WaitIdle();
                Assert.IsTrue(grid.IsKeyboardFocusWithin);
            });
        }
Exemple #13
0
        public void Export()
        {
            var catalog = session.Query <Catalog>().First(c => c.HaveOffers);
            var model   = new CatalogOfferViewModel(catalog);

            WpfTestHelper.WithWindow2(async w => {
                var view  = Bind(model);
                w.Content = view;
                await view.WaitLoaded();

                Assert.IsTrue(model.CanExport.Value);
                result = (OpenResult)model.Export();
                Assert.That(File.Exists(result.Filename), result.Filename);
            });
        }
        public void Focus_on_empty_data_grid()
        {
            WpfTestHelper.WithWindow2(async w => {
                var grid = new DataGrid2();
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new DataGridTextColumn {
                    Binding = new Binding("Items")
                });
                w.Content        = grid;
                grid.ItemsSource = Enumerable.Empty <Tuple <string> >().ToList();

                await w.WaitIdle();
                DataGridHelper.Focus(grid);
                Assert.IsTrue(grid.IsKeyboardFocusWithin);
            });
        }
 public void Do_not_reset_data_grid_focus()
 {
     WpfTestHelper.WithWindow2(async w => {
         var grid = new DataGrid2();
         grid.AutoGenerateColumns = false;
         grid.Columns.Add(new DataGridTextColumn {
             Binding = new Binding("Items")
         });
         w.Content        = grid;
         grid.ItemsSource = Enumerable.Range(1, 100).Select(i => Tuple.Create(i.ToString())).ToList();
         await grid.WaitLoaded();
         DataGridHelper.Focus(grid);
         grid.ItemsSource = Enumerable.Range(500, 100).Select(i => Tuple.Create(i.ToString())).ToList();
         await w.WaitIdle();
         Assert.IsTrue(grid.IsKeyboardFocusWithin);
         Assert.IsInstanceOf <DataGridCell>(Keyboard.FocusedElement);
     });
 }
Exemple #16
0
        public void Show_print_for_created_waybill()
        {
            var waybill = new Waybill(session.Query <Address>().First(), session.Query <Supplier>().First());

            waybill.IsCreatedByUser = true;
            session.Save(waybill);

            WpfTestHelper.WithWindow2(async w => {
                var model = new WaybillDetails(waybill.Id);
                var view  = (WaybillDetailsView)Bind(model);
                w.Content = view;

                await view.WaitLoaded();
                view.Descendants <Button>().First(b => b.Name == "PrintWaybill")
                .RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
            });
            WpfTestHelper.CleanSafeError();
        }
Exemple #17
0
        public void Spliter_settings()
        {
            var expected = new GridLength();
            int diff;

            WpfTestHelper.WithWindow2(async w => {
                var model = new MinCosts();
                var view  = Bind(model);
                w.Content = view;
                await view.WaitLoaded();
                var grid   = (Grid)view.FindName("MainGrid");
                var row    = grid.RowDefinitions[Grid.GetRow((UIElement)view.FindName("Costs"))];
                row.Height = new GridLength(row.ActualHeight - 5, GridUnitType.Pixel);
                expected   = row.Height;

                diff = model.Diff.Value = model.Diff.Value + 1;
                Close(model);
            });

            var memory       = new MemoryStream();
            var streamWriter = new StreamWriter(memory);

            shell.Serialize(streamWriter);
            streamWriter.Flush();
            shell.PersistentContext.Clear();
            memory.Position = 0;
            shell.Deserialize(new StreamReader(memory));

            WpfTestHelper.WithWindow2(async w => {
                var view  = Bind(new MinCosts());
                w.Content = view;
                var grid  = (Grid)view.FindName("MainGrid");
                await view.WaitLoaded();
                var actual = grid.RowDefinitions[Grid.GetRow((UIElement)view.FindName("Costs"))].Height;
                Assert.AreEqual(expected.GridUnitType, actual.GridUnitType);
                Assert.AreEqual(expected.Value, actual.Value, 0.001);
            });
        }
        public void Show_address()
        {
            restore = true;
            session.Save(new Address("Тестовый адрес доставки"));
            session.DeleteEach <BatchLine>();
            session.Save(new BatchLine(session.Query <Catalog>().First(), address)
            {
                Comment    = "test comment",
                Properties = "Клубничный",
            });

            WpfTestHelper.WithWindow2(async w => {
                var model = new Batch();
                var view  = Bind(model);
                w.Content = view;

                await view.WaitLoaded();

                var searchCheck       = view.Descendants <CheckBox>().First(c => c.Name == "All");
                searchCheck.IsChecked = true;

                var grid = view.Descendants <DataGrid>().First(c => c.Name == "ReportLines");
                scheduler.Start();
                grid.CurrentItem = grid.Items[0];
                await view.WaitIdle();

                var col = DataGridHelper.FindColumn(grid, "Адрес заказа");
                Assert.AreEqual(col.Visibility, Visibility.Visible);
                var comment = view.Descendants <TextBox>().First(c => c.Name == "CurrentReportLine_Value_Comment");
                Assert.AreEqual("test comment", comment.Text);

                col            = DataGridHelper.FindColumn(grid, "Кат.свойства");
                col.Visibility = Visibility.Visible;
                await view.WaitIdle();
                var cell = grid.Descendants <DataGridCell>().First(x => x.Column == col);
                Assert.AreEqual("Клубничный", cell.Descendants <TextBlock>().First().Text);
            });
        }
        public void Searchable_column()
        {
            WpfTestHelper.WithWindow2(async w => {
                var model        = new SearchableModel();
                var grid         = new DataGrid2();
                grid.DataContext = model;
                BindingOperations.SetBinding(grid, DataGrid.ItemsSourceProperty, new Binding("Items.Value"));
                BindingOperations.SetBinding(grid, SearchableDataGridColumn.SearchTermProperty, new Binding("Term.Value"));
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new SearchableDataGridColumn {
                    Binding        = new Binding("Item1"),
                    HighlightStyle = new Style {
                        Setters =
                        {
                            new Setter(TextElement.BackgroundProperty, Brushes.Red)
                        }
                    }
                });
                w.Content = grid;
                await grid.WaitLoaded();
                await w.WaitIdle();

                model.Items.Value = Enumerable.Range(0, 49).Select(i => Tuple.Create(i.ToString())).ToList();
                await w.WaitIdle();

                model.Term.Value  = "5";
                model.Items.Value = Enumerable.Range(50, 100).Select(i => Tuple.Create(i.ToString())).ToList();
                await w.WaitIdle();

                var row  = grid.Descendants <DataGridRow>().First(r => ((Tuple <String>)r.DataContext).Item1 == "50");
                var text = row.Descendants <TextBlock>().First();
                Assert.AreEqual("50", text.Text);
                var inlines = text.Inlines.OfType <Run>().ToArray();
                Assert.AreEqual("5", inlines[0].Text);
                Assert.AreEqual("0", inlines[1].Text);
            });
        }
 public void Get_cell()
 {
     WpfTestHelper.WithWindow2(async w => {
         var grid = new DataGrid {
             Columns =
             {
                 new DataGridTextColumn {
                     DisplayIndex = 1
                 },
                 new DataGridTextColumn {
                     DisplayIndex = 0
                 }
             },
             ItemsSource = new[] { 1, 2 }
         };
         grid.CurrentItem = grid.Items[0];
         grid.CurrentCell = new DataGridCellInfo(grid.CurrentItem, grid.Columns[1]);
         w.Content        = grid;
         await grid.WaitLoaded();
         var cell = DataGridHelper.GetCell(grid, grid.CurrentCell);
         Assert.AreEqual(grid.CurrentItem, cell.DataContext);
         Assert.AreEqual(grid.Columns[1], cell.Column);
     });
 }
        public void Mark_search_results()
        {
            WpfTestHelper.WithWindow2(async w => {
                var model = new CatalogViewModel();
                var view  = Bind(model);
                w.Content = view;

                await view.WaitLoaded();

                var searchCheck       = view.Descendants <CheckBox>().First(c => c.Name == "CatalogSearch");
                searchCheck.IsChecked = true;
                await view.WaitIdle();

                var allCheck       = view.Descendants <CheckBox>().First(c => c.Name == "ShowWithoutOffers");
                allCheck.IsChecked = true;
                await view.WaitIdle();

                var search  = view.Descendants <TextBox>().First(b => b.Name == "SearchText");
                search.Text = "мыло";
                var grid    = view.Descendants <DataGrid>().First(g => g.Name == "Items");
                grid.SendKey(Key.Return);
                await view.WaitIdle();
            });
        }
        public void Do_not_lose_focus_on_delete()
        {
            var items = Enumerable.Range(1, 100).Select(i => Tuple.Create(i.ToString())).ToList();
            var data  = new ObservableCollection <Tuple <String> >(items);

            WpfTestHelper.WithWindow2(async w => {
                var grid = new DataGrid2();
                grid.AutoGenerateColumns = false;
                grid.Columns.Add(new DataGridTextColumn {
                    Binding = new Binding("Items")
                });
                w.Content        = grid;
                grid.ItemsSource = data;

                await w.WaitIdle();
                DataGridHelper.Focus(grid);
                Assert.IsNotNull(grid.CurrentItem);
                data.Remove((Tuple <string>)grid.SelectedItem);

                await w.WaitIdle();
                Assert.IsTrue(grid.IsKeyboardFocusWithin);
                Assert.IsNotNull(grid.CurrentItem);
            });
        }