public async Task TestInsert() { try { Election election = new Election() { Date = new DateTime(2022, 11, 3).Date, StartDateLocal = new DateTime(2022, 11, 1, 8, 0, 0), EndDateLocal = new DateTime(2022, 11, 3, 20, 0, 0), Description = "2022 November Election", Version = "0.0.0.0", AllowUpdates = false }; UOW.BeginTransaction(); Election inserted = await electionService.Insert(UOW, election); UOW.CloseTransaction(); Assert.IsNotNull(inserted); Assert.IsTrue(inserted.Id != Guid.Empty, "Expect inserted Election Id not be empty"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsertUpdateVote() { try { // now add a vote for candidate1 Vote vote = new Vote() { ElectionId = DefaultElectionId, BallotId = Guid.NewGuid(), CategoryId = PresCategoryId, CategoryTypeId = 2, SelectionId = BidenTicketId, VoteStatus = 0, ApprovalDate = DateTime.Now }; UOW.BeginTransaction(); Vote inserted = await voteRepository.Insert(UOW, vote); Assert.IsNotNull(inserted); Assert.IsTrue(inserted.Id != Guid.Empty, "Expect inserted vote Id not be empty"); // now change the ballot selection to candidate2 vote.Id = inserted.Id; vote.VoteStatus = (int)VoteStatusEnum.choiceRejected; Vote updated = await voteRepository.Update(UOW, vote); Assert.IsNotNull(updated); Assert.IsTrue(inserted.Id == updated.Id, "Expect inserted and updated Id to be the same"); UOW.CloseTransaction(); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsert() { try { List <Ticket> ans = (await ticketService.GetByElection(Context, DefaultElectionId)).ToList(); int ndxToGet = rand.Next(0, ans.Count); Guid categoryId = ans[ndxToGet].CategoryId; int partyId = rand.Next(1, 6); Ticket ticket = new Ticket() { ElectionId = DefaultElectionId, CategoryId = categoryId, Description = "TestTicketInsert", PartyId = partyId, TicketType = ans[ndxToGet].TicketType, Information = "TextTicketInformation", Sequence = 1 }; UOW.BeginTransaction(); Ticket result = await ticketService.Insert(UOW, ticket); UOW.CloseTransaction(); Assert.IsNotNull(result); Assert.IsTrue(result.Description == ticket.Description, "Expect description to be TestTicketInsert"); Assert.IsTrue(result.Information == ticket.Information, "Expect description to be TestTicketInformation"); Assert.IsTrue(result.Id != Guid.Empty, "Expect Id to not be empty"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsertElection() { Guid BallotId = Guid.NewGuid(); List <Vote> votes = new List <Vote>() { new Vote() { ElectionId = DefaultElectionId, BallotId = BallotId, CategoryId = PresCategoryId, CategoryTypeId = 2, SelectionId = BidenTicketId, VoteStatus = 0, ApprovalDate = DateTime.Now } }; int countBeforeInsert1 = await GetCurrentVoteSummary(BidenTicketId); UOW.BeginTransaction(); List <Vote> results = await voteService.InsertElection(UOW, votes); int countAfterInsert1 = await GetCurrentVoteSummary(BidenTicketId); Assert.IsNotNull(results, "Expected votes to be inserted"); Assert.IsTrue(countAfterInsert1 == countBeforeInsert1 + 1, "Expecte VoteResult Table to be increased by 1 votes for candidate"); UOW.CloseTransaction(); }
public async Task <Vote> Create([FromBody] Vote vote) { try { UOW.BeginTransaction(); return(await this.voteRepository.Insert(UOW, vote)); } finally { UOW.SaveChanges(); UOW.CloseTransaction(); } }
public async Task <int> InsertElection([FromBody] List <Vote> electionObj) { try { UOW.BeginTransaction(); var result = await this.voteRepository.InsertElection(UOW, electionObj); } finally { UOW.SaveChanges(); UOW.CloseTransaction(); } return(0); }
public async Task TestDelete() { try { UOW.BeginTransaction(); Election result = await electionService.Delete(UOW, DefaultElectionId); UOW.CloseTransaction(); Assert.IsNull(result); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestUpdate() { try { Category insCat = new Category() { ElectionId = this.DefaultElectionId, CategoryTypeId = CategoryTypeEnum.federal, Heading = "TestHeadingInsert", Title = "TestTitleInsert", JudgePosition = 4, Information = "TestInformationInsert", SubTitle = "TestSubTitleInsert", Sequence = 1, Selection = null }; UOW.BeginTransaction(); Category result = await categoryRepository.Insert(UOW, insCat); Assert.IsNotNull(result, "Expect category to be inserted"); Assert.IsFalse(result.Id == Guid.Empty, "Expect a real guid id for inserted Category"); Assert.AreEqual(result.CategoryTypeId, insCat.CategoryTypeId, "Expect CategoryTypeId to be the same"); Assert.AreEqual(result.Heading, insCat.Heading, "Expect Heading to be the same"); Assert.AreEqual(result.Title, insCat.Title, "Expect Title to be the same"); Assert.AreEqual(result.JudgePosition, insCat.JudgePosition, "Expect JudgePosition to be the same"); Assert.AreEqual(result.Information, insCat.Information, "Expect Information to be the same"); Assert.AreEqual(result.SubTitle, insCat.SubTitle, "Expect SubTitle to be the same"); Assert.AreEqual(result.Sequence, insCat.Sequence, "Expect Sequence to be the same"); Assert.AreEqual(result.Selection, insCat.Selection, "Expect Selection to be the same"); result.Heading = "TestHeadingUpdate"; result.Title = "TestTitleUdate"; result.Information = "TestInformationUpdate"; result.SubTitle = "TestSubTitleUpdate"; Category update = await categoryRepository.Update(UOW, result); UOW.CloseTransaction(); Assert.IsNotNull(update, "Expected updated record"); Assert.IsTrue(update.Heading == result.Heading, "Expect Heading to be updated"); Assert.IsTrue(update.Title == result.Title, "Expect Title to be updated"); Assert.IsTrue(update.Information == result.Information, "Expect Information to be updated"); Assert.IsTrue(update.SubTitle == result.SubTitle, "Expect Subtitle to be updated"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task <Vote> Update([FromBody] Vote vote) { Vote result = new Vote(); try { UOW.BeginTransaction(); result = await this.voteRepository.Update(UOW, vote); UOW.SaveChanges(); return(result); } finally { UOW.CloseTransaction(); } }
public async Task <Signature> Create([FromBody] BlockChain electionChain) { Signature result = null; try { UOW.BeginTransaction(); Signature signature = this.GetSignatureFromBlockChain(electionChain); // now check to make sure the nonce matches the expected nonce (int expectedNonce, Guid ballotRequestId) = await this.signatureRepository.GetExpectedNonce(UOW, signature.BallotId); if (ballotRequestId != Guid.Empty) { var br = await ballotRepository.BallotRequestGetById(Context, ballotRequestId); // make sure the nonce and device id are correct if (signature == null || expectedNonce != electionChain.GetLatestBlock().Nonce || (br != null && signature.DeviceId != br.DeviceId)) { return(null); } Signature existingSignature = await this.GetByBallotId(signature.BallotId); if (existingSignature != null) { result = await signatureRepository.UpdateBallotVotes(UOW, existingSignature, signature); } else { result = await this.InsertNewSignatureBallot(UOW, signature); } UOW.SaveChanges(); } } catch (Exception ex) { string err = ex.Message; } finally { UOW.CloseTransaction(); } return(result); }
public async Task TestDelete() { try { UOW.BeginTransaction(); CategoryType result = await categoryTypeRepository.GetByID(Context, 1); Assert.IsNotNull(result, "Expect to find CategoryType Measure"); Assert.AreEqual(result.Description, "Measure", "Expect to find CategoryType Description = Measure"); CategoryType deleted = await categoryTypeRepository.Delete(UOW, result.Id); UOW.CloseTransaction(); Assert.IsNull(deleted, "Expect new CategoryType to be deleted."); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestDelete() { try { List <Ticket> ans = (await ticketService.GetByElection(Context, DefaultElectionId)).ToList(); int ndxToGet = rand.Next(0, ans.Count); UOW.BeginTransaction(); Ticket deleted = await ticketService.Delete(UOW, ans[ndxToGet].Id); List <Ticket> results = (await ticketService.GetByElection(Context, DefaultElectionId)).ToList(); UOW.CloseTransaction(); Assert.IsNull(deleted, "Expect to not find deleted ticket"); Assert.IsTrue(results.Count == ans.Count - 1, "Expect total Tickets to be one less that starting value"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsertUpdateVote() { try { Vote vote = new Vote() { ElectionId = DefaultElectionId, BallotId = Guid.NewGuid(), CategoryId = PresCategoryId, CategoryTypeId = 2, SelectionId = BidenTicketId, VoteStatus = 0, ApprovalDate = DateTime.Now }; UOW.BeginTransaction(); int countBeforeInsert1 = await GetCurrentVoteSummary(BidenTicketId); Vote inserted = await voteService.Insert(UOW, vote); Assert.IsNotNull(inserted); Assert.IsTrue(inserted.Id != Guid.Empty, "Expect inserted vote Id not be empty"); int countAfterInsert1 = await GetCurrentVoteSummary(BidenTicketId); Assert.IsTrue(countAfterInsert1 == countBeforeInsert1 + 1, "Expected trigger to increase the count in VoteResult Table"); // now change the ballot selection to candidate2 vote.Id = inserted.Id; vote.VoteStatus = (int)VoteStatusEnum.choiceRejected; Vote updated = await voteService.Update(UOW, vote); Assert.IsNotNull(updated); Assert.IsTrue(inserted.Id == updated.Id, "Expect inserted and updated Id to be the same"); int countAfterUpdate1 = await GetCurrentVoteSummary(BidenTicketId); Assert.IsTrue(countBeforeInsert1 == countAfterUpdate1, "Expected trigger to decrease the count in VoteResult Table when VoteStatus changed"); UOW.CloseTransaction(); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestPartyDelete() { try { UOW.BeginTransaction(); Party result = await PartyService.GetByID(Context, 1); Assert.IsNotNull(result, "Expect to find Democratic Party"); Assert.AreEqual(result.Description, "Democratic Party", "Expect to find Party Description = Democratic Party"); Party deleted = await PartyService.Delete(UOW, result.Id); UOW.CloseTransaction(); Assert.IsTrue(deleted.Active == false, "Expect new Party active flag to be false."); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task <List <Vote> > InsertElection([FromBody] List <Vote> votes) { List <Vote> result = new List <Vote>(); try { UOW.BeginTransaction(); result = await this.voteRepository.InsertElection(UOW, votes); if (votes.Count == result.Count) { UOW.SaveChanges(); } return(result); } finally { UOW.CloseTransaction(); } }
public async Task <Signature> Create([FromBody] Signature electionObj) { Signature result = null; try { UOW.BeginTransaction(); result = await this.signatureRepository.Insert(Context, electionObj); if (result.Id != Guid.Empty && result.Confirmed && result.Votes.Count == electionObj.Votes.Count) { UOW.SaveChanges(); } } finally { UOW.CloseTransaction(); } return(result); }
public async Task TestPartyUpdate() { try { UOW.BeginTransaction(); Party result = await PartyService.GetByID(Context, 3); Assert.IsNotNull(result, "Expect to find Party State"); Assert.AreEqual(result.Description, "Libertarian Party", "Expect to find Party Description = Libertarian Party"); result.Description = "Libertarian Test Update"; Party updated = await PartyService.Update(UOW, result); UOW.CloseTransaction(); Assert.IsNotNull(updated, "Expect new Party to be updated."); Assert.AreEqual(updated.Description, result.Description, "Expect for Description to be changed to 'Libertarian Test Update'"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestPartyInsert() { try { UOW.BeginTransaction(); Party catType = new Party() { Description = "My Test Party", Active = true }; Party result = await PartyService.Insert(UOW, catType); UOW.CloseTransaction(); Assert.IsNotNull(result, "Expect new Party to be inserted."); Assert.IsTrue(result.Id > 6, "Expect Inserted Id to be > 6"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestDelete() { try { List <Category> result = (await categoryService.GetByElection(Context, this.DefaultElectionId)).ToList(); int total = result.Count; Assert.IsNotNull(result, "Expect to find at least once category in default dataset"); int ndxToDelete = rand.Next(1, total); Category catToDelete = result[ndxToDelete]; UOW.BeginTransaction(); Category deleted = (await categoryService.Delete(UOW, catToDelete.Id)); List <Category> result2 = (await categoryService.GetByElection(Context, this.DefaultElectionId)).ToList(); UOW.CloseTransaction(); Assert.IsNull(deleted, "Expected Category to be deleted"); Assert.IsTrue(result2.Count == total - 1, "Expect one less category in default dataset"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsert() { try { UOW.BeginTransaction(); CategoryType catType = new CategoryType() { Description = "TestInsertCategory", Active = true }; CategoryType result = await categoryTypeRepository.Insert(UOW, catType); UOW.CloseTransaction(); Assert.IsNotNull(result, "Expect new CategoryType to be inserted."); Assert.IsTrue(result.Id > 5, "Expect Inserted Id to be > 5"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestUpdate() { try { UOW.BeginTransaction(); CategoryType result = await categoryTypeRepository.GetByID(Context, 3); Assert.IsNotNull(result, "Expect to find CategoryType State"); Assert.AreEqual(result.Description, "State", "Expect to find CategoryType Description = State"); result.Description = "State Test Update"; CategoryType updated = await categoryTypeRepository.Update(UOW, result); UOW.CloseTransaction(); Assert.IsNotNull(updated, "Expect new CategoryType to be updated."); Assert.AreEqual(updated.Description, result.Description, "Expect for Description to be changed to 'State Test Update'"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsert() { try { Ballot ans = new Ballot() { ElectionId = DefaultElectionId, Nonce = 525, BallotChain = "Something" }; UOW.BeginTransaction(); Ballot inserted = await ballotRepository.Insert(Context, ans); UOW.CloseTransaction(); Assert.IsNotNull(inserted, "Expected inserted ballot"); Assert.IsTrue(ans.Nonce == 525, "Expect Nonce to be 525"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestUpdate() { try { Election election = new Election() { Date = new DateTime(2022, 11, 3).Date, StartDateLocal = new DateTime(2022, 11, 1, 8, 0, 0), EndDateLocal = new DateTime(2022, 11, 3, 20, 0, 0), Description = "2022 November Election", Version = "0.0.0.0", AllowUpdates = false }; UOW.BeginTransaction(); Election inserted = await electionService.Insert(UOW, election); Assert.IsNotNull(inserted); Assert.IsTrue(inserted.Id != Guid.Empty, "Expect inserted Election Id not be empty"); inserted.Date = new DateTime(2023, 11, 3).Date; inserted.StartDateLocal = new DateTime(2023, 11, 1, 8, 0, 0); inserted.EndDateLocal = new DateTime(2023, 11, 3, 20, 0, 0); inserted.Description = "2023 November Election"; inserted.AllowUpdates = true; Election updated = await electionService.Update(UOW, inserted); UOW.CloseTransaction(); Assert.IsNotNull(updated, "Expected election to be updated"); Assert.IsTrue(updated.Date.Year == 2023, "Expected election year to be 2023"); Assert.IsTrue(updated.StartDateLocal.Year == 2023, "Expected election year to be 2023"); Assert.IsTrue(updated.EndDateLocal.Year == 2023, "Expected election year to be 2023"); Assert.IsTrue(updated.Description == "2023 November Election", "Expected desription to be updated"); Assert.IsTrue(updated.AllowUpdates, "Expected allowUpdates to be true"); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }
public async Task TestInsertElection() { Guid BallotId = Guid.NewGuid(); List <Vote> votes = new List <Vote>() { new Vote() { ElectionId = DefaultElectionId, BallotId = BallotId, CategoryId = PresCategoryId, CategoryTypeId = 2, SelectionId = TrumpTicketId, VoteStatus = 0, ApprovalDate = DateTime.Now } }; UOW.BeginTransaction(); List <Vote> results = await voteRepository.InsertElection(UOW, votes); Assert.IsNotNull(results, "Expected votes to be inserted"); UOW.CloseTransaction(); }
public async Task TestSaveAllElection() { try { Guid newElectionGuid = Guid.NewGuid(); Guid newCategoryGuid = Guid.NewGuid(); List <Ticket> ticketList = new List <Ticket>() { new Ticket() { Id = Guid.NewGuid(), ElectionId = newElectionGuid, CategoryId = newCategoryGuid, Description = "newTicketForCategory", PartyId = 2 } }; List <Category> categoryList = new List <Category>() { new Category() { Id = newCategoryGuid, ElectionId = newElectionGuid, CategoryTypeId = CategoryTypeEnum.federal, Heading = "TestNewElectionCategory", Sequence = 1, JudgePosition = 2, Tickets = ticketList, } }; Election election = new Election() { Id = newElectionGuid, Date = new DateTime(2022, 11, 3).Date, StartDateLocal = new DateTime(2022, 11, 1, 8, 0, 0), EndDateLocal = new DateTime(2022, 11, 3, 20, 0, 0), Description = "2022 November Election", Version = "0.0.0.0", AllowUpdates = false, CategoryList = categoryList }; UOW.BeginTransaction(); Election result = await electionService.SaveAllElection(UOW, election); Assert.IsNotNull(election, "Expected election to be saved"); Assert.IsTrue(election.CategoryList.Count == 1, "Expected Category to be saved."); Assert.IsTrue(election.CategoryList[0].Tickets.Count == 1, "Expect one Ticket in category"); CategoryService categoryService = new CategoryService(); List <Category> clist = (await categoryService.GetByElection(Context, newElectionGuid)).ToList(); Assert.IsTrue(clist.Count == 1, "Expect one Category"); TicketService ticketService = new TicketService(); List <Ticket> tlist = (await ticketService.GetByElection(Context, newElectionGuid)).ToList(); Assert.IsTrue(tlist.Count == 1, "Expect one Ticket"); UOW.CloseTransaction(); } catch (Exception ex) { Assert.IsNull(ex, "Exception Thrown: " + ex.Message); } }