Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new controller
 /// </summary>
 public Controller()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     this.welcomeForm = new WelcomeForm();
     this.mainForm = new MainForm();
     this.networkClient = new VoterClient("Client: " + System.Net.Dns.GetHostName());
     this.model = new Model();
     this.currentVoter = null;
 }
Ejemplo n.º 2
0
        public void TestRpc()
        {
            // Setup test objects
            Init();

            // Start a server that will be active for 10 seconds
            Thread serverThread = new Thread(new ThreadStart(SetupServer));
            serverThread.Start();

            // Wait to make sure its active
            Thread.Sleep(5000);

            // Start testing
            VoterClient voterClient = new VoterClient("Client1");

            // Test the name
            Assert.That(voterClient.Name.Equals("Client1"));
            voterClient.Name = "Client1.1";
            Assert.That(voterClient.Name.Equals("Client1.1"));

            // Connected
            Assert.True(voterClient.Connected());

            //Testing person from cpr
            Person person = voterClient.GetPersonFromCpr(0);
            Assert.That(person.Equals(emptyPerson));
            person = voterClient.GetPersonFromCpr(1);
            Assert.That(person.Equals(person1));

            //Testing person from id
            person = voterClient.GetPersonFromId(0);
            Assert.That(person.Equals(emptyPerson));
            person = voterClient.GetPersonFromId(2);
            Assert.That(person.Equals(person2));

            //Register voter
            bool b = voterClient.RegisterVoter(person1);
            Assert.True(b);

            //unregister voter
            b = voterClient.UnregisterVoter(person2);
            Assert.False(b);

            //Valid tables
            string[] arr = voterClient.ValidTables();
            Assert.That(arr.Length == 3);
            Assert.That(arr[0] == tables[0]);
            Assert.That(arr[1] == tables[1]);
            Assert.That(arr[2] == tables[2]);

            // Await that the server runs out of time
            Thread.Sleep(10000);

            // Abort the server thread
            serverThread.Abort();

            // Make sure that the thraed is not allive
            Thread.Sleep(5000);

            // Test that it perfomrs well when not connected to a server
            //Connected
            Assert.False(voterClient.Connected());

            //Testing person from cpr
            person = voterClient.GetPersonFromCpr(1);
            Assert.That(person == null);

            //Testing person from id
            person = voterClient.GetPersonFromId(2);
            Assert.That(person == null);

            //Register voter
            b = voterClient.RegisterVoter(person1);
            Assert.False(b);

            //unregister voter
            b = voterClient.UnregisterVoter(person2);
            Assert.False(b);

            //Valid tables
            arr = voterClient.ValidTables();
            Assert.That(arr == null);
        }