コード例 #1
0
        public void SportFiltersCheckPreMatch()
        {
            IoCContainer.Kernel.Unbind <IMediator>();
            var MessageMediator = new MyMessageMediator();

            IoCContainer.Kernel.Bind <IMediator>().ToConstant <IMediator>(MessageMediator).InSingletonScope();
            ChangeTracker.Setup(x => x.SelectedDescriptorsPreMatch).Returns(new List <string>());

            Repository.Setup(x => x.FindMatches(It.IsAny <SortableObservableCollection <IMatchVw> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <LineSr.DelegateFilterMatches>(), It.IsAny <Comparison <IMatchVw> >())).Returns(new SortableObservableCollection <IMatchVw>());

            var prematch = new MatchesViewModel();

            prematch.OnNavigationCompleted();

            MessageMediator.SendMessage(true, MsgTag.ClearSelectedSports);

            //at start should be only "All sports" available and checked
            Assert.AreEqual(1, prematch.SportsBarItemsPreMatch.Count);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.ALL_SPORTS, prematch.SelectedDescriptors[0]);

            //if something else is checked, there should be no "All sports" in selected descriptors
            SportBarItem hokkey = new SportBarItem("Ice Hokkey", SportSr.SPORT_DESCRIPTOR_ICE_HOCKEY);
            SportBarItem soccer = new SportBarItem("Soccer", SportSr.SPORT_DESCRIPTOR_SOCCER);
            SportBarItem volley = new SportBarItem("Volleyball", SportSr.SPORT_DESCRIPTOR_VOLLEYBALL);

            prematch.OnCheckedExecute(hokkey);

            Assert.AreEqual(1, prematch.SportsBarItemsPreMatch.Count);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.SPORT_DESCRIPTOR_ICE_HOCKEY, prematch.SelectedDescriptors[0]);

            //select all sport once again, other selection should be dropped
            SportBarItem allsports = new SportBarItem("All Sports", SportSr.ALL_SPORTS);

            prematch.OnCheckedExecute(allsports);

            Assert.AreEqual(1, prematch.SportsBarItemsPreMatch.Count);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.ALL_SPORTS, prematch.SelectedDescriptors[0]);

            //all sports cannot be unchecked if pressed twice
            prematch.OnCheckedExecute(allsports);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.ALL_SPORTS, prematch.SelectedDescriptors[0]);

            //same item pressed twice should be unchecked and if no other item selected all sports should be checked
            prematch.OnCheckedExecute(soccer);
            prematch.OnCheckedExecute(hokkey);
            Assert.AreEqual(2, prematch.SelectedDescriptors.Count);
            prematch.OnCheckedExecute(hokkey);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.SPORT_DESCRIPTOR_SOCCER, prematch.SelectedDescriptors[0]);
            prematch.OnCheckedExecute(soccer);
            Assert.AreEqual(1, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.ALL_SPORTS, prematch.SelectedDescriptors[0]);

            //two items can be selected in same time
            prematch.OnCheckedExecute(hokkey);
            prematch.OnCheckedExecute(soccer);
            prematch.OnCheckedExecute(volley);
            Assert.AreEqual(3, prematch.SelectedDescriptors.Count);
            Assert.AreEqual(SportSr.SPORT_DESCRIPTOR_ICE_HOCKEY, prematch.SelectedDescriptors[0]);
            Assert.AreEqual(SportSr.SPORT_DESCRIPTOR_SOCCER, prematch.SelectedDescriptors[1]);
            Assert.AreEqual(SportSr.SPORT_DESCRIPTOR_VOLLEYBALL, prematch.SelectedDescriptors[2]);
        }