예제 #1
0
        /// <summary>
        /// Display the results of the requested LINQ Query by the user based on the button selection
        /// </summary>
        public void DisplayResults()
        {
            // Clear any items in listbox
            lstRelevant.Items.Clear();
            constituencyList.data(selectedReportType);


            if (selectedReportType == "ElectionWinner")
            {
                foreach (var con in constituencyList.dataCand(selectedReportType))
                {
                    lstRelevant.Items.Add(con);
                }
            }

            else if (selectedReportType == "Votes")
            {
                foreach (var con in constituencyList.data(selectedReportType))
                {
                    lstRelevant.Items.Add(con);
                }
            }
            else if (selectedReportType == "Candidates")
            {
                foreach (var con in constituencyList.dataCand(selectedReportType))
                {
                    lstRelevant.Items.Add(con);
                }
            }
            else if (selectedReportType == "PartyWinner")
            {
                foreach (var con in constituencyList.data(selectedReportType))
                {
                    lstRelevant.Items.Add(con);
                }
            }
            else if (selectedReportType == "ConstituencyWinner")
            {
                foreach (var con in constituencyList.dataCon(selectedReportType, cboCons.SelectedItem.ToString()))
                {
                    lstRelevant.Items.Add(con);
                }
            }
            else if (selectedReportType == "ConstituencyCandidates")
            {
                foreach (var con in constituencyList.dataCon(selectedReportType, cboCons.SelectedItem.ToString()))
                {
                    lstRelevant.Items.Add(con);
                }
            }
            else if (selectedReportType == "ElectedCandidates")
            {
                foreach (var con in constituencyList.dataCon(selectedReportType))
                {
                    lstRelevant.Items.Add(con);
                }
            }
        }
        private void Helper_Test_dataCand_Method_Three_Constituency1(string reportType, List <DataMeasureCandidate> expectedDataMeasuresList)
        {
            // Arrange
            // Instantiate a ConstituencyList object
            var testedClass = new TestedClass();

            // Add the three constituencies to the list
            testedClass.constituency.Add(Helper_KnownConstituencyDataRepository.GetKnownMiddlesbrough());
            testedClass.constituency.Add(Helper_KnownConstituencyDataRepository.GetKnownNewcastleN());
            testedClass.constituency.Add(Helper_KnownConstituencyDataRepository.GetKnownSunderlandN());

            // Act
            // Has constituencies in the list so expected to return an populated data measures list
            var actualDataMeasuresList = testedClass.dataCand(reportType);

            // Assert
            // Expected data measures list should contain the same number of items as the actual data measures list
            Assert.AreEqual(expectedDataMeasuresList.Count, actualDataMeasuresList.Count);

            // Each expected data measure should be equal to the actual data measure, note that the values are given
            // an accuracy of 4 decimal places to ensure they can be deemed equal (due to rounding)
            for (int i = 0; i < expectedDataMeasuresList.Count; i++)
            {
                Assert.AreEqual(expectedDataMeasuresList[i].PartyName, actualDataMeasuresList[i].PartyName);
                Assert.AreEqual(expectedDataMeasuresList[i].Firstname, actualDataMeasuresList[i].Firstname);
                Assert.AreEqual(expectedDataMeasuresList[i].Lastname, actualDataMeasuresList[i].Lastname);
                Assert.AreEqual(expectedDataMeasuresList[i].Votes, actualDataMeasuresList[i].Votes, 0.0001);
            }
        }
        public void Test_dataCand_Method_No_Constituency_Candidates_Report()
        {
            // Arrange
            // Instantiate a ConstituencyList object
            var testedClass = new TestedClass();

            // Act
            // No constituencies in the list so expected to return an empty data measures list
            var actualDataMeasuresList = testedClass.dataCand("Candidates");

            // Assert
            // Actual data measures list should be empty
            Assert.AreEqual(0, actualDataMeasuresList.Count);
        }
        public void Test_dataCand_Method_Invalid_Report()
        {
            // Arrange
            // Instantiate a ConstituencyList object
            var testedClass = new TestedClass();

            // Act
            // Invalid report type asked for so should return null
            var actualDataMeasuresList = testedClass.dataCand("INVALID");

            // Assert
            // Actual data measures list should be null
            Assert.IsNull(actualDataMeasuresList);
        }