public async Task <BallotCandidate> AddAsync(Ballot ballot, Candidate candidate)
        {
            var ballotCandidate = new BallotCandidate
            {
                Ballot    = ballot,
                Candidate = candidate
            };

            return(await _repository.AddAsync(ballotCandidate));
        }
        public async Task RemoveBallotCandidateService()
        {
            // Arrange
            var mockRepo = new Mock <IRepository <BallotCandidate> >();

            mockRepo.Setup(repo => repo.RemoveAsync(It.IsAny <BallotCandidate>()))
            .Returns(Task.CompletedTask);

            var ballotCandidate = new BallotCandidate();

            var service = new BallotCandidateService(mockRepo.Object);

            // Act
            await service.RemoveAsync(ballotCandidate);

            // Assert
            mockRepo.Verify(repo => repo.RemoveAsync(ballotCandidate), Times.AtMostOnce);
        }
        public async Task UpdateBallotCandidateService()
        {
            // Arrange
            var mockRepo = new Mock <IRepository <BallotCandidate> >();

            mockRepo.Setup(repo => repo.UpdateAsync(It.IsAny <BallotCandidate>()))
            .ReturnsAsync((BallotCandidate bc) => bc);

            var ballotCandidate = new BallotCandidate
            {
                BallotId    = 1,
                CandidateId = 1,
                VoteCount   = 20
            };

            var service = new BallotCandidateService(mockRepo.Object);

            // Act
            await service.UpdateAsync(ballotCandidate);

            // Assert
            mockRepo.Verify(repo => repo.UpdateAsync(ballotCandidate), Times.AtMostOnce);
        }
        private async void SaveCompleteElection(VotingContext context, IRepository <Election> saver)
        {
            var candidate1 = new Candidate()
            {
                Name = "Candidate 1"
            };
            var candidate2 = new Candidate()
            {
                Name = "Candidate 1"
            };

            candidate1 = (await context.Candidates.AddAsync(candidate1)).Entity;
            candidate2 = (await context.Candidates.AddAsync(candidate2)).Entity;

            var ballot1 = new Ballot()
            {
                Name = "Ballot 1",
            };

            ballot1 = (await context.Ballots.AddAsync(ballot1)).Entity;

            var ballot2 = new Ballot()
            {
                Name = "Ballot 2",
            };

            ballot2 = (await context.Ballots.AddAsync(ballot2)).Entity;

            var bc1 = new BallotCandidate()
            {
                BallotId    = ballot1.Id,
                CandidateId = candidate1.Id
            };

            bc1 = (await context.BallotCandidates.AddAsync(bc1)).Entity;
            var bc2 = new BallotCandidate()
            {
                BallotId    = ballot1.Id,
                CandidateId = candidate2.Id
            };

            bc2 = (await context.BallotCandidates.AddAsync(bc2)).Entity;
            var bc3 = new BallotCandidate()
            {
                BallotId    = ballot2.Id,
                CandidateId = candidate1.Id
            };

            bc3 = (await context.BallotCandidates.AddAsync(bc3)).Entity;
            var bc4 = new BallotCandidate()
            {
                BallotId    = ballot2.Id,
                CandidateId = candidate2.Id
            };

            bc4 = (await context.BallotCandidates.AddAsync(bc4)).Entity;

            var election = new Election()
            {
                CreatedDate = DateTime.Now.Subtract(new TimeSpan(15, 0, 0, 0)),
                ElectionQr  = Guid.NewGuid(),
                Ballots     = new List <Ballot>()
                {
                    ballot1, ballot2
                },
                ExpirationDate = DateTime.Now.Subtract(new TimeSpan(5, 0, 0, 0))
            };
            await saver.AddAsync(election);
        }
 public async Task UpdateAsync(BallotCandidate ballotCandidate)
 {
     await _repository.UpdateAsync(ballotCandidate);
 }
 public async Task RemoveAsync(BallotCandidate ballotCandidate)
 {
     await _repository.RemoveAsync(ballotCandidate);
 }