public void PresenterTest_Filtering() { // 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(); // Choose a few types to filter with List <Vessel.TargetType> wantedTypes = new List <Vessel.TargetType>() { Vessel.TargetType.FishingBoat, Vessel.TargetType.SpeedBoat }; // Before filtering, those types are present along with other types. Assert.IsTrue(vesselPresenter.DisplayedVessels.Exists(v => wantedTypes.Contains(v.Type)), "Initial list does not contain wanted types."); Assert.IsTrue(vesselPresenter.DisplayedVessels.Exists(v => !wantedTypes.Contains(v.Type)), "Initial list does not contain other types."); // Now filter, and those types should be the only ones present. vesselPresenter.FilterVessels(wantedTypes); Assert.IsTrue(vesselPresenter.DisplayedVessels.Exists(v => wantedTypes.Contains(v.Type)), "Final list does not contain wanted types."); Assert.IsTrue(!vesselPresenter.DisplayedVessels.Exists(v => !wantedTypes.Contains(v.Type)), "Final list contain other types."); }
private void OnCheckboxClick(object sender, RoutedEventArgs e) { // Cast back to checkbox CheckBox checkboxClicked = sender as CheckBox; if (checkboxClicked == vesselToggleAllCheckbox) { // Allow user to skip the inderterminate state when toggling the all box. if (checkboxClicked.IsChecked == null) { checkboxClicked.IsChecked = false; } // Propagate state to individual checkboxes. foreach (var checkbox in vesselFilterCheckboxes) { checkbox.IsChecked = checkboxClicked.IsChecked; } } else { // See if it's everything on or everything off to update the check all box. bool isAllChecked = true; bool isAllUnchecked = true; foreach (var checkbox in vesselFilterCheckboxes) { isAllChecked = isAllChecked ? checkbox.IsChecked.Value : isAllChecked; isAllUnchecked = isAllUnchecked ? !checkbox.IsChecked.Value : isAllUnchecked; } vesselToggleAllCheckbox.IsChecked = isAllChecked == isAllUnchecked ? (bool?)null : isAllChecked; } // See which checkboxes are checked finally to perform filtering. List <Vessel.TargetType> wantedTypes = new List <Vessel.TargetType>(); foreach (var checkbox in vesselFilterCheckboxes) { if (checkbox.IsChecked == true) { wantedTypes.Add((Vessel.TargetType)Enum.Parse(typeof(Vessel.TargetType), checkbox.Name)); } } vesselPresenter.FilterVessels(wantedTypes); // Update vessels now that filtering changed. UpdateVessels(); }