public async Task GetMatchingBallotsForPattern_BadRequestWhenNoPattern()
        {
            var request  = TestFactory.CreateHttpRequest();
            var logger   = TestFactory.CreateLogger();
            var svc      = TestFactory.CreateElectionResultsService();
            var response = (BadRequestObjectResult)await new BallotLookup(svc.Object).GetMatchingBallotsForPattern(request, null, logger);

            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task ImportResultsOnBlobUpdate_ImportsData()
        {
            var fn     = "somefilename.ext";
            var stream = Stream.Null;
            var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List);
            var svc    = TestFactory.CreateElectionResultsService();

            await new ElectionDataManagement(svc.Object).ImportResultsOnBlobUpdate(stream, fn, logger);

            svc.Verify(m => m.ImportElectionResults(stream), Times.Once);
        }
        public async Task GetElectionSummary_ReturnDefaultSummary()
        {
            var request  = TestFactory.CreateHttpRequest();
            var logger   = TestFactory.CreateLogger();
            var svc      = TestFactory.CreateElectionResultsService();
            var response = (JsonResult)await new Functions.Api.ElectionSummary(svc.Object).GetElectionSummary(request, logger);
            var summary  = response.Value as Models.ElectionSummary;

            Assert.IsNotNull(summary);
            Assert.IsFalse(summary.IsComplete);
        }
        public async Task GetMatchingBallotsForPattern_ReturnsEmptyList()
        {
            var pattern  = "dance";
            var request  = TestFactory.CreateHttpRequest("pattern", pattern);
            var logger   = TestFactory.CreateLogger();
            var svc      = TestFactory.CreateElectionResultsService();
            var response = (JsonResult)await new BallotLookup(svc.Object).GetMatchingBallotsForPattern(request, pattern, logger);
            var list     = response?.Value as List <BallotStatus>;

            Assert.IsNotNull(list);
            Assert.AreEqual(0, list.Count);
        }
        public async Task ImportResultsOnBlobUpdate_LogsImport()
        {
            var fn     = "somefilename.ext";
            var stream = Stream.Null;
            var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List);
            var svc    = TestFactory.CreateElectionResultsService();

            await new ElectionDataManagement(svc.Object).ImportResultsOnBlobUpdate(stream, fn, logger);

            Assert.AreEqual(1, logger.Logs.Count);
            var msg = logger.Logs[0];

            Assert.IsTrue(msg.Contains("ImportElectionResults:"));
            Assert.IsTrue(msg.Contains(fn));
        }
        public async Task GetMatchingBallotsForPattern_ReturnsMatchingPattern()
        {
            var pattern = "dance";
            var request = TestFactory.CreateHttpRequest("pattern", pattern);
            var logger  = TestFactory.CreateLogger();
            var svc     = TestFactory.CreateElectionResultsService(new List <BallotStatus>
            {
                new BallotStatus
                {
                    TrackingId          = $"{pattern} 6XYBN2 book 5TYN89",
                    ApproximateCastTime = DateTime.Now,
                    Location            = "Unit testing",
                    Status = BallotCountStatus.Counted
                }
            });
            var response = (JsonResult)await new BallotLookup(svc.Object).GetMatchingBallotsForPattern(request, pattern, logger);
            var list     = response?.Value as List <BallotStatus>;

            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list[0].TrackingId.StartsWith(pattern));
        }
        public async Task GetElectionSummary_ReturnElectionResults()
        {
            var request = TestFactory.CreateHttpRequest();
            var logger  = TestFactory.CreateLogger();
            var svc     = TestFactory.CreateElectionResultsService(summary: new Models.ElectionSummary
            {
                IsComplete    = true,
                BallotEntries = new List <BallotEntry>
                {
                    new BallotEntry
                    {
                        RaceId  = "race1",
                        Name    = "representative 1",
                        Tallies = new List <Tally>
                        {
                            new Tally
                            {
                                Name        = "candidate 1",
                                SelectionId = "candidate1",
                                Party       = "party1",
                                VoteCount   = 20
                            },
                            new Tally
                            {
                                Name        = "candidate 2",
                                SelectionId = "candidate2",
                                Party       = "party2",
                                VoteCount   = 85
                            }
                        }
                    },
                    new BallotEntry
                    {
                        RaceId  = "race2",
                        Name    = "senate 1",
                        Tallies = new List <Tally>
                        {
                            new Tally
                            {
                                Name        = "candidate 3",
                                SelectionId = "candidate3",
                                Party       = "party1",
                                VoteCount   = 40
                            },
                            new Tally
                            {
                                Name        = "candidate 4",
                                SelectionId = "candidate4",
                                Party       = "party2",
                                VoteCount   = 65
                            }
                        }
                    },
                }
            });
            var response = (JsonResult)await new Functions.Api.ElectionSummary(svc.Object).GetElectionSummary(request, logger);
            var summary  = response.Value as Models.ElectionSummary;

            Assert.IsNotNull(summary);
            Assert.IsTrue(summary.IsComplete);
            Assert.AreEqual(2, summary.BallotEntries.Count());
        }