Esempio n. 1
0
        public async Task VoteRepository_CRD_Tests()
        {
            const int firstWarId  = 1234;
            const int secondWarId = 5678;
            var       sqlServerConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WarDb"].ConnectionString;
            var       repository = new VoteRepository(sqlServerConnectionString);

            var firstVote = await CreateVote(repository, firstWarId);

            var firstVoteWrongWarId = await repository.Get(secondWarId, firstVote.MatchId);

            firstVoteWrongWarId.Should().BeNullOrEmpty();

            var secondVote = await CreateVote(repository, firstWarId);

            var thirdVote = await CreateVote(repository, secondWarId);

            var firstWarCollection = await repository.GetAll(firstWarId);

            VerifyVoteInCollection(firstWarCollection, firstVote);
            VerifyVoteInCollection(firstWarCollection, secondVote);
            VerifyVoteNotInCollection(firstWarCollection, thirdVote);

            var secondWarCollection = await repository.GetAll(secondWarId);

            VerifyVoteNotInCollection(secondWarCollection, firstVote);
            VerifyVoteNotInCollection(secondWarCollection, secondVote);
            VerifyVoteInCollection(secondWarCollection, thirdVote);

            await VerifyVoteDelete(repository, firstWarId, firstVote.MatchId);
            await VerifyVoteDelete(repository, firstWarId, secondVote.MatchId);
            await VerifyVoteDelete(repository, secondWarId, thirdVote.MatchId);
        }
Esempio n. 2
0
        public void Delete_Normal_Conditions()
        {
            var repo = new VoteRepository();
            var vote = new Vote();

            vote.OptionId = 2;
            vote.SurveyId = 3;
            var count = repo.GetAll().Count();

            repo.Add(vote);
            repo.Delete(vote);
            Assert.IsTrue(repo.GetAll().Count() == count);
        }
Esempio n. 3
0
        public List <VoteDTO> GetAll()
        {
            List <VoteEntity> allvotes = ur.GetAll();
            List <VoteDTO>    l1       = Mapper.Map <List <VoteDTO> >(allvotes);

            return(l1);
        }
Esempio n. 4
0
 public async Task TestGetAllByCategory()
 {
     try
     {
         List <Vote> ans = (await voteRepository.GetAll(Context, DefaultElectionId, PresCategoryId)).ToList();
         if (ans != null)
         {
             Assert.IsNotNull(ans, "Expected Vote from default dataset- Save a ballot to get votes back!");
         }
     }
     catch (Exception ex)
     {
         Assert.IsNull(ex, "Exception Thrown: " + ex.Message);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Get API/Vote
 /// </summary>
 /// <returns>List de tous les Votes</returns>
 public IHttpActionResult Get()
 {
     if ((new[] { "Admin" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         IEnumerable <VoteModel> List = repo.GetAll().Select(Vote => Vote?.ToModel());
         if (List.Count() == 0)
         {
             return(NotFound());
         }
         else
         {
             return(Json(List));
         }
     }
     else
     {
         return(Unauthorized());
     }
 }