Exemplo n.º 1
0
        public void PresenterTest_Sorting()
        {
            // First start the simulation through presenter.
            bool isStarted = vesselPresenter.Start("test_oneofeach.vsf");

            Assert.IsTrue(isStarted, "Could not start simulation.");

            // Stop it immediately because we don't need the timer updates.
            Cker.Simulator.Stop();

            // Copy the list to perform the expected value later.
            List <Vessel> vesselCopy = vesselPresenter.DisplayedVessels.ToList();

            // Sort twice to see the order switch.
            string attributeName = "ID";

            vesselPresenter.SortVessels(attributeName);

            // Sort the copy and compare
            vesselCopy = vesselPresenter.CurrentSortDirection == VesselPresenter.SortDirection.Ascending ? vesselCopy.OrderBy(v => v.ID).ToList() : vesselCopy.OrderByDescending(v => v.ID).ToList();
            Assert.IsTrue(Enumerable.SequenceEqual(vesselCopy, vesselPresenter.DisplayedVessels), "List not sorted correctly.");

            // Again.
            vesselPresenter.SortVessels(attributeName);
            vesselCopy = vesselPresenter.CurrentSortDirection == VesselPresenter.SortDirection.Ascending ? vesselCopy.OrderBy(v => v.ID).ToList() : vesselCopy.OrderByDescending(v => v.ID).ToList();
            Assert.IsTrue(Enumerable.SequenceEqual(vesselCopy, vesselPresenter.DisplayedVessels), "List not sorted correctly.");
        }
Exemplo n.º 2
0
        private void OnColumnHeaderClick(object sender, RoutedEventArgs e)
        {
            GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;

            // Ignore clicks on the grid padding (extra spaces at the far right)
            if (headerClicked == null || headerClicked.Role == GridViewColumnHeaderRole.Padding)
            {
                return;
            }

            // Retrieve name of the attritube associated to the column header just clicked.
            // This corresponds to the binding; however, this is not the case when there are multibinds; we just take the header name instead.
            var dataBinding          = (Binding)headerClicked.Column.DisplayMemberBinding;
            var currentSortAttribute = dataBinding != null ? dataBinding.Path.Path : headerClicked.Content as string;

            // Apply the sorting and update.
            vesselPresenter.SortVessels(currentSortAttribute);
            UpdateVessels();

            // Change the look of the current column header to reflect sorting
            // but first reset the look of the previous header
            if (currentSortHeader != null)
            {
                currentSortHeader.Column.HeaderTemplate = null;
            }
            var columnHeaderTemplate = vesselPresenter.CurrentSortDirection == VesselPresenter.SortDirection.Ascending ? sortAscendingArrowDisplay : sortDescendingArrowDisplay;

            headerClicked.Column.HeaderTemplate = columnHeaderTemplate;

            // Save the current sort by attribute for next time.
            currentSortHeader = headerClicked;
        }