public static void ClassInit(TestContext context)
        {
            serviceProvider = TestStartup.ConfigureServices();

            voteConstructor = serviceProvider.GetRequiredService <VoteConstructor>();
            voteCounter     = serviceProvider.GetRequiredService <IVoteCounter>();
        }
示例#2
0
 /// <summary>
 /// Provide a vote counter to use when compiling the output.
 /// </summary>
 /// <param name="voteCounter">The vote counter to use.</param>
 public void UsingVoteCounter(IVoteCounter voteCounter)
 {
     if (voteCounter != null)
     {
         this.voteCounter = voteCounter;
     }
 }
示例#3
0
        public ViewModel(Tally tally, IVoteCounter voteCounter,
                         ICache <string> cache, CheckForNewRelease newRelease, IAgnostic agnostic,
                         IGlobalOptions globalOptions, ILogger <ViewModel> logger)
        {
            // Save our dependencies in readonly fields.
            this.tally              = tally;
            this.voteCounter        = voteCounter;
            this.PageCache          = cache;
            this.globalOptions      = globalOptions;
            this.checkForNewRelease = newRelease;
            this.agnostic           = agnostic;
            this.logger             = logger;

            tally.PropertyChanged       += Tally_PropertyChanged;
            voteCounter.PropertyChanged += VoteCounter_PropertyChanged;

            // Set up binding commands.
            AddQuestCommand    = new RelayCommand(this, nameof(AddQuestCommand), DoAddQuest, CanAddQuest);
            RemoveQuestCommand = new RelayCommand(this, nameof(RemoveQuestCommand), DoRemoveQuest, CanRemoveQuest);

            RunTallyCommand        = new AsyncRelayCommand(this, nameof(RunTallyCommand), DoRunTallyAsync, CanRunTally);
            CancelTallyCommand     = new RelayCommand(this, nameof(CancelTallyCommand), DoCancelTally, CanCancelTally);
            ClearTallyCacheCommand = new RelayCommand(this, nameof(ClearTallyCacheCommand), DoClearTallyCache, CanClearTallyCache);

            AddLinkedQuestCommand    = new RelayCommand(this, nameof(AddLinkedQuestCommand), AddLinkedQuest, CanAddLinkedQuest);
            RemoveLinkedQuestCommand = new RelayCommand(this, nameof(RemoveLinkedQuestCommand), RemoveLinkedQuest, CanRemoveLinkedQuest);

            SetupWatches();
        }
        public DHondtElectionResultsCalculator(Election election, IVoteCounter voteCounter)
        {
            Check.NotNull(voteCounter, nameof(voteCounter));
            Check.NotNull(election, nameof(election));

            VoteCounter = voteCounter;
            Election    = election;
        }
示例#5
0
        public Tally(IPageProvider pageProvider, IVoteCounter voteCounter)
        {
            VoteCounter = voteCounter ?? throw new ArgumentNullException(nameof(voteCounter));

            // Hook up to event notifications
            pageProvider.StatusChanged += PageProvider_StatusChanged;
            AdvancedOptions.Instance.PropertyChanged += Options_PropertyChanged;
        }
示例#6
0
        public static void ClassInit(TestContext context)
        {
            Agnostic.HashStringsUsing(UnicodeHashFunction.HashFunction);

            sampleQuest = new Quest();

            ViewModelService.Instance.Build();
            voteCounter = ViewModelService.MainViewModel.VoteCounter;
        }
示例#7
0
        public Tally(IServiceProvider serviceProvider, VoteConstructor constructor,
                     IVoteCounter counter, IGeneralOutputOptions options, ILogger <Tally> logger)
        {
            this.serviceProvider = serviceProvider;
            voteConstructor      = constructor;
            voteCounter          = counter;
            outputOptions        = options;
            this.logger          = logger;

            // Hook up to event notifications
            outputOptions.PropertyChanged += Options_PropertyChanged;
        }
        public static void ClassInit(TestContext context)
        {
            serviceProvider = TestStartup.ConfigureServices();

            voteCounter     = serviceProvider.GetRequiredService <IVoteCounter>();
            tally           = serviceProvider.GetRequiredService <Tally>();
            voteConstructor = serviceProvider.GetRequiredService <VoteConstructor>();
            agnostic        = serviceProvider.GetRequiredService <IAgnostic>();

            IQuest quest = new Quest();

            agnostic.ComparisonPropertyChanged(quest, new System.ComponentModel.PropertyChangedEventArgs(nameof(quest.CaseIsSignificant)));
        }
示例#9
0
        public ElectionGobernor(
            Election election,
            IVoteCounter voteCounter,
            IElectoralRoll electoralRoll,
            IElectionResultsCalculator electionResultsCalculator)
        {
            Check.NotNull(election, nameof(election));
            Check.NotNull(voteCounter, nameof(voteCounter));
            Check.NotNull(electoralRoll, nameof(electoralRoll));
            Check.NotNull(electionResultsCalculator, nameof(electionResultsCalculator));

            Election                  = election;
            VoteCounter               = voteCounter;
            ElectoralRoll             = electoralRoll;
            ElectionResultsCalculator = electionResultsCalculator;
        }
示例#10
0
        public MainViewModel(
            HttpClientHandler httpClientHandler, IPageProvider pageProvider,
            IVoteCounter voteCounter, ITextResultsProvider textResults,
            Func <string, CompareInfo, CompareOptions, int> hashFunction)
        {
            PropertyChanged += Agnostic.HashStringsUsing(hashFunction);

            SetupNetwork(pageProvider, httpClientHandler);
            SetupTextResults(textResults);

            AllVotesCollection  = new ObservableCollectionExt <string>();
            AllVotersCollection = new ObservableCollectionExt <string>();

            BuildCheckForNewRelease();
            SetupVoteCounter(voteCounter);

            BuildTally();

            SetupCommands();
        }
示例#11
0
        public TallyOutput(
            IVoteCounter counter,
            RankVoteCounterFactory rankVoteCounterFactory,
            ForumAdapterFactory forumAdapterFactory,
            IGeneralOutputOptions options)
        {
            voteCounter   = counter;
            outputOptions = options;

            rankVoteCounter = rankVoteCounterFactory.CreateRankVoteCounter(options.RankVoteCounterMethod);

            if (voteCounter.Quest != null)
            {
                quest        = voteCounter.Quest;
                forumAdapter = forumAdapterFactory.CreateForumAdapter(quest.ForumType, quest.ThreadUri);
            }
            else
            {
                quest        = new Quest();
                forumAdapter = forumAdapterFactory.CreateForumAdapter(ForumType.Unknown, Quest.InvalidThreadUri);
            }
        }
示例#12
0
 /// <summary>
 /// <see cref="VoteConstructor"/> class has a dependency on <see cref="IVoteCounter"/>.
 /// </summary>
 /// <param name="voteCounter">The vote counter to store locally and use within this class.</param>
 public VoteConstructor(IVoteCounter voteCounter)
 {
     this.voteCounter = voteCounter;
 }
示例#13
0
        public bool Undo(IVoteCounter voteCounter)
        {
            if (undone)
            {
                return(false);
            }

            var currentVotes = voteCounter.VoteStorage;

            // Remove pass - Remove all current votes or supporters that are not
            // in the archived version of the vote repository.

            HashSet <VoteLineBlock> voteRemovals = new HashSet <VoteLineBlock>();

            foreach (var(currentVote, currentSupporters) in currentVotes)
            {
                if (!storage.TryGetValue(currentVote, out var storageSupporters))
                {
                    voteRemovals.Add(currentVote);
                }
                else
                {
                    HashSet <Origin> voterRemovals = new HashSet <Origin>();

                    foreach (var(currentSupporter, _) in currentSupporters)
                    {
                        if (!storageSupporters.ContainsKey(currentSupporter))
                        {
                            voterRemovals.Add(currentSupporter);
                        }
                    }

                    foreach (var removal in voterRemovals)
                    {
                        currentSupporters.Remove(removal);
                    }
                }
            }

            foreach (var removal in voteRemovals)
            {
                currentVotes.Remove(removal);
            }


            // Replace pass - Add all archived votes or supporters that are not
            // in the current version of the vote repository.

            foreach (var(storageVote, storageSupporters) in storage)
            {
                if (!currentVotes.TryGetValue(storageVote, out var currentSupporters))
                {
                    currentVotes.Add(storageVote, storageSupporters);
                }
                else
                {
                    foreach (var(storageSupporter, storageSupporterVote) in storageSupporters)
                    {
                        if (!currentSupporters.ContainsKey(storageSupporter))
                        {
                            currentSupporters.Add(storageSupporter, storageSupporterVote);
                        }
                    }
                }
            }

            return(undone = true);
        }
示例#14
0
 /// <summary>
 /// Attach to the VoteCounter's property changed event.
 /// </summary>
 private void SetupVoteCounter(IVoteCounter voteCounter)
 {
     VoteCounter = voteCounter ?? new VoteCounter();
     VoteCounter.PropertyChanged += VoteCounter_PropertyChanged;
 }
示例#15
0
 public ViewModelService VoteCounter(IVoteCounter voteCounter)
 {
     this.voteCounter = voteCounter;
     return(this);
 }
示例#16
0
 public VoteConstructor(IVoteCounter voteCounter)
 {
     VoteCounter = voteCounter ?? throw new ArgumentNullException(nameof(voteCounter));
 }