public void ApplyVote(PollData data) { try { if (!data.Authenticate()) return; data.ApplyVote(); } catch (Exception error) { Error.Write(error); throw; } }
public void TestPolls() { Initialize(); var logins = new string[,] {{"One","1"},{"Two","2"},{"Three","3"},{"Four","4"}}; for (int i = 0; i <= logins.GetUpperBound(0); i++) { var messaging = new ClientService(); var polls = messaging.ListPolls(new AuthenticatedData() { Username = logins[i,0], Password = logins[i,1] }); Assert.AreEqual(2, polls.Count); PollData vote = new PollData() { //Each user votes for their option %3 (result being 1st option has 2 votes, other 2 have 1 vote) OptionId = polls[0].PollOptions[(Convert.ToInt16(logins[i,1])-1)%3].Id, Username = logins[i,0], Password = logins[i,1] }; messaging.ApplyVote(vote); messaging.ApplyVote(vote); //Send the vote again, prevent anyone from voting more than once. } using (var db = new CSSDataContext()) { Assert.AreEqual(2, db.PollVotes.Count(pv => pv.PollOption.Option == "Option1")); Assert.AreEqual(1, db.PollVotes.Count(pv => pv.PollOption.Option == "Option2")); } }