public void GetElectionMapForYesNoElectionTest()
        {
            var electionMap = _electionMapper.GetElectionMap(_yesNoElection);

            Assert.AreEqual(6, electionMap.NumberOfSelections);
            Assert.AreEqual(_yesNoElection.Contests.Length, electionMap.ContestMaps.Count);
            Assert.AreEqual(1, electionMap.BallotStyleMaps.Count);
        }
        public ActionResult <CreateElectionResult> CreateElection(ElectionRequest request)
        {
            try
            {
                var electionMap = _electionMapper.GetElectionMap(request.Election);
                request.Config.NumberOfSelections = electionMap.NumberOfSelections;

                var election = ElectionGuardApi.CreateElection(request.Config);
                return(CreatedAtAction(nameof(CreateElection), new ElectionResponse {
                    ElectionGuardConfig = election.ElectionGuardConfig,
                    TrusteeKeys = election.TrusteeKeys,
                    ElectionMap = electionMap,
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError("CreateElection: ", ex);
                return(StatusCode(500));
            }
        }
        public ElectionGuardController(ILogger <ElectionGuardController> logger, IElectionMapper <Election, Ballot, VoteTally> electionMapper, IConfigFileService configService)
        {
            _config         = configService;
            _logger         = logger;
            _electionMapper = electionMapper;

            _exportPath = Path.Combine(_config.GetDataDirectory(), "election_results");
            logger.LogInformation($"DATA: resolved at: {_config.GetDataDirectory()}");

            // try to load the election config files from the file system
            var election = _config.GetElection();

            if (election != null)
            {
                logger.LogInformation("ElectionController: Found Election");
                _election    = election;
                _electionMap = _electionMapper.GetElectionMap(_election);
            }
            else
            {
                logger.LogInformation("ElectionController: Could not find election.json");
            }

            var electionguardConfig = _config.getElectionGuardConfig();

            if (electionguardConfig != null)
            {
                logger.LogInformation("ElectionController: Found ElectionGuard Config");
                _electionGuardConfig = electionguardConfig;
            }
            else
            {
                logger.LogInformation("ElectionController: Could not find election.config.json");
            }

            var now = DateTime.Now;

            _encryptedBallotsExportFileName        = $"encrypted-ballots_{now.Year}_{now.Month}_{now.Day}";
            _registeredBallotsExportFileNamePrefix = $"registered-ballots";
            _tallyExportFileNamePrefix             = "tally-results";
        }