/// <summary> /// Marks a user as willing to serve in a committee election. /// Don't forget to call transaction.Commit() to commit the pending /// changes. /// </summary> /// <param name="session">A valid session.</param> /// <param name="candidate">The user ID who has submitted a WTS.</param> /// <param name="election">The pertinent election ID.</param> /// <param name="statement">THe statement provided by the user.</param> public static void WillingToServe(ISession session, int candidate, int election, string statement) { CommitteeWTS toSubmit = new CommitteeWTS(); toSubmit.Election = election; toSubmit.User = candidate; toSubmit.Statement = statement; session.SaveOrUpdate(toSubmit); session.Flush(); }
public static void NominationPhaseSkipped() { Console.Write("Nomination Phase Skipped:\n"); ISessionFactory factory = NHibernateHelper.CreateSessionFactory(); // Clear out database using (ISession session = factory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { Clear(session, transaction); } } // Preconditions using (ISession session = factory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { // create a committee Console.Write("Create committee with 3 positions.\n"); Committee com = new Committee(); com.Name = "Acommittee"; com.PositionCount = 3; session.SaveOrUpdate(com); // add 2 users who are tenured and union members who are on // the committee Console.Write("Create 5 users and add 2 of them to the committee.\n"); for (int i = 0; i < 5; i++) { User user = User.CreateUser("e", i.ToString() + "F", i.ToString() + "L", "p", "h", false, false, true, true, false, DepartmentType.CSC, OfficerPositionType.None, true, User.NoCommittee); session.SaveOrUpdate(user); if(i < 2) user.AddToCommittee(session, "Acommittee"); } // create an election for the committee Console.Write("Create an election based off the committee.\n"); CommitteeElection election = CommitteeElection.CreateElection(session, com); session.SaveOrUpdate(election); session.Flush(); // submit WTS for 2 users Console.Write("Submitting WTSes for 2 users."); for (int i = 2; i < 4; i++) { CommitteeWTS wts = new CommitteeWTS(); wts.Election = election.ID; wts.Statement = "thisisastatement."; wts.User = i; session.SaveOrUpdate(wts); session.Flush(); } session.Flush(); transaction.Commit(); } } // Assertions using (ISession session = factory.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { CommitteeElection election = CommitteeElection.FindElection(session, "Acommittee"); ElectionPhase phase = election.NextPhase(session); Assert.AreEqual(phase, ElectionPhase.VotePhase); } } }