Exemple #1
0
        public void WhenCreatingANewFilterableCollectionThenItIsInitializedAsExpected()
        {
            List <string> collection = new List <string>()
            {
                "Marcelo", "Willian", "Casemiro", "Messi"
            };
            FilterableCollection <string> filterableCollection = new FilterableCollection <string>(collection);

            CollectionAssert.AreEqual(collection, filterableCollection.OriginalCollection.ToList(), "OriginalCollection is not as expected");
            CollectionAssert.AreEqual(collection, filterableCollection.FilteredCollection.ToList(), "FilteredCollection is not as expected");
        }
Exemple #2
0
 public UserVM(Game parent, string name) : base(parent)
 {
     Name    = name;
     Planets = new FilterableCollection <PlanetVM>(new ObservableCollection <PlanetVM>(),
                                                   (vm, s) => vm.Model.Name.Trim().Replace(" ", "").StartsWith(s.Trim().Replace(" ", ""),
                                                                                                               StringComparison.CurrentCultureIgnoreCase), new PlanetVMComparer());
     Planets.AllItems.CollectionChanged += (sender, args) =>
     {
         PropChanged(nameof(PlanetsCount), nameof(ResourceString), nameof(InfluenceString));
     };
     Planets.PropertyChanged += (sender, args) =>
     {
         PropChanged(nameof(ResourceString), nameof(InfluenceString));
     };
 }
Exemple #3
0
        public void WhenFilteringAFilterableCollectionThenItIsBeingFiltered()
        {
            List <string> collection = new List <string>()
            {
                "Marcelo", "Willian", "Casemiro", "Messi"
            };
            FilterableCollection <string> filterableCollection = new FilterableCollection <string>(collection);

            filterableCollection.Filter = str => !str.Contains('e');

            CollectionAssert.AreEqual(collection, filterableCollection.OriginalCollection.ToList(), "OriginalCollection is not as expected");
            CollectionAssert.AreEqual(new List <string>()
            {
                "Willian"
            }, filterableCollection.FilteredCollection.ToList(), "FilteredCollection is not as expected");
        }
Exemple #4
0
 public ObjectiveSelectorVM(Game.Game g, List <ObjectiveVM> existingObjectives, List <ObjectiveVM> publicObjectives) : base(g)
 {
     Objectives = new FilterableCollection <ObjectiveVM>(
         new ObservableCollection <ObjectiveVM>(g.AllObjectiveCards
                                                .Where(e => (e.Stage == 0 || publicObjectives.Exists(p => p.Model.Name == e.Name)) && !existingObjectives.Exists(ex => ex.Model.Name.Equals(e.Name)))
                                                .Select(e =>
     {
         var ret              = new ObjectiveVM(g, e);
         ret.PropertyChanged += (sender, args) =>
         {
             if (args.PropertyName == nameof(PlanetVM.IsSelected))
             {
                 PropChanged(nameof(SelectedObjectives));
             }
         };
         return(ret);
     }).OrderBy(e => e.Model.Stage != 0).ThenBy(e => e.Model.Stage).ThenBy(e => e.Model.Name)),
         (vm, s) => vm.Model.Name.Trim().Replace(" ", "").StartsWith(s.Trim().Replace(" ", ""),
                                                                     StringComparison.CurrentCultureIgnoreCase), new ObjectiveVMComparer());
 }
Exemple #5
0
        public void TestFilterFunction()
        {
            FilterableCollection <int> test = new FilterableCollection <int>();

            for (int i = 0; i < 100; i++)
            {
                test.Add(i);
            }
            test.Filter(x => x < 50);
            foreach (int i in test)
            {
                if (i >= 50)
                {
                    Assert.Fail();
                }
            }
            Assert.AreEqual(test.Count, 50);
            test.Restore();
            Assert.AreEqual(test.Count, 100);
            test.Restore();
            Assert.AreEqual(test.Count, 100);
        }
 public PlanetSelectorVM(Game.Game g, bool onlyBelongingToUsers, bool checkByDefault) : base(g)
 {
     Planets = new FilterableCollection <PlanetVM>(
         new ObservableCollection <PlanetVM>(g.AllPlanetCards
                                             .Where(e => !onlyBelongingToUsers || g.Users.Any(us =>
                                                                                              us.Planets.AllItems.ToList().Exists(pl =>
                                                                                                                                  pl.Model.Name.Equals(e.Name, StringComparison.CurrentCultureIgnoreCase))))
                                             .Select(e =>
     {
         var ret              = new PlanetVM(null, e);
         ret.PropertyChanged += (sender, args) =>
         {
             if (args.PropertyName == nameof(PlanetVM.IsSelected))
             {
                 PropChanged(nameof(SelectedPlanets));
             }
         };
         ret.IsSelected = checkByDefault;
         return(ret);
     })),
         (vm, s) => vm.Model.Name.Trim().Replace(" ", "").StartsWith(s.Trim().Replace(" ", ""),
                                                                     StringComparison.CurrentCultureIgnoreCase), new PlanetVMComparer());
 }