コード例 #1
0
        public void GivenStateCensusDataFileShouldReturnValidRecords()
        {
            int expectedNoOFRecords = 29;
            int records             = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath);

            Assert.AreEqual(expectedNoOFRecords, records);
        }
コード例 #2
0
        public void givenStateCensusCsv_sortOntheBasisOfStateName()
        {
            StateCensusAnalyser    stateCensusAnalyser = new StateCensusAnalyser();
            List <StateCensusData> JsonStateCensusData = stateCensusAnalyser.sortByStateName(IndiaCensusDataFilePath1);

            Assert.AreEqual("Andhra Pradesh", JsonStateCensusData[0].State);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: ahsan133/CensusAnalyser
        public void GivenCensusCSVFileAndCSVState_WhenNumberOfRecordMatch_ThenItShouldReturnTrue()
        {
            int CSVStateRecord    = CSVStates.GetRecord(FILE_PATH);
            int StateCensusRecord = StateCensusAnalyser.GetStateCensusRecord(STATE_CODE_FILE_PATH);

            Assert.AreEqual(CSVStateRecord, StateCensusRecord);
        }
コード例 #4
0
        public void GiventheStateCensusCSV_FilewhenCorrectbutcsvheaderincorrectReturnsCustomException()
        {
            StateCensusAnalyser matches = new StateCensusAnalyser();
            string filepath             = @"C:\Users\The Daddy\source\repos\IndianStatesCensus\IndianStatesCensus\StateCensusData.csv";

            Assert.AreEqual("File Contains Invalid Headers", matches.StateCensusAnalyzer(filepath));
        }
コード例 #5
0
        public void GiventheStateCensusCSVFileincorrectReturnscustomException()
        {
            StateCensusAnalyser matches = new StateCensusAnalyser();
            string filepath             = @"C:\Users\The Daddy\source\repos\IndianStatesCensus\IndianStatesCensus\StateCensusData.txt";

            Assert.AreEqual("There is No Such Files", matches.StateCensusAnalyzer(filepath));
        }
コード例 #6
0
        public void GiventheStateCensusCSV_File_type_IncorrectReturn_Exception()
        {
            StateCensusAnalyser matches = new StateCensusAnalyser();
            string filepath             = @"C:\Users\The Daddy\source\repos\IndianStatesCensus\IndianStatesCensus\StateCensusData.csv";

            Assert.AreEqual("File Contains Invalid Records", matches.StateCensusAnalyzer(filepath));
        }
コード例 #7
0
        public void SortAndJsonTestCSVStates()
        {
            //Code For StateCode
            string expectedStateCodeFirstState = "Andaman and Nicobar Islands";
            string expectedStateCodeLastState  = "West Bengal";
            int    stateCodeRecords            = new StateCensusAnalyser <CSVStates>().ReadFile(CensusLoader <CSVStates> .Country.INDIA, delimiter, StateCodeFilePath);
            var    stateCodeDictionary         = StateCensusAnalyser <CSVStates> .dataDictionary;
            string sortedStateCodeJson         = new StateCensusAnalyser <CSVStates>().SortCSVStatesByCode(stateCodeDictionary);
            var    jArray1             = JArray.Parse(sortedStateCodeJson);
            string stateCodeFirstState = jArray1[0]["Value"]["State1"].Value <string>();
            string stateCodeLastState  = jArray1[jArray1.Count - 1]["Value"]["State1"].Value <string>();

            Assert.AreEqual(expectedStateCodeFirstState, stateCodeFirstState);
            Assert.AreEqual(expectedStateCodeLastState, stateCodeLastState);

            //Code For StateCensus
            string expectedStateCensusFirstState = "Andhra Pradesh";
            string expectedStateCensusLastState  = "West Bengal";
            int    stateCensusRecords            = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath);
            var    stateCensusDictionary         = StateCensusAnalyser <CSVStateCensus> .dataDictionary;
            string sortedStateCensusJson         = new StateCensusAnalyser <CSVStateCensus>().SortCSVStateCensus(stateCensusDictionary, "State", false);
            var    jArray2 = JArray.Parse(sortedStateCensusJson);
            string stateCensusFirstState = jArray2[0]["Value"]["State"].Value <string>();
            string stateCensusLastState  = jArray2[jArray2.Count - 1]["Value"]["State"].Value <string>();

            Assert.AreEqual(expectedStateCensusFirstState, stateCensusFirstState);
            Assert.AreEqual(expectedStateCensusLastState, stateCensusLastState);
        }
コード例 #8
0
        public void GiventheStatesWhenAnalyseShouldRecordNumberOfRecordmatches()
        {
            StateCensusAnalyser matches = new StateCensusAnalyser();
            string filepath             = @"C:\Users\The Daddy\source\repos\IndianStatesCensus\IndianStatesCensus\StateCensusData.csv";

            Assert.AreEqual("30", matches.StateCensusAnalyzer(filepath));
        }
コード例 #9
0
        public void incorrectFileExtensionForStateCode()
        {
            var analyser = new StateCensusAnalyser();
            StateCensusAnalyserDelegate deligate = new StateCensusAnalyserDelegate(analyser.LoadCsvData);
            var ex = Assert.Throws <CsvCustomException>(() => deligate.Invoke("C:/Users/User/source/repos/StateCode.txt", CsvStateCensusHeader, CsvStateCodeHeader));

            Assert.AreEqual("Incorrect file Extension", ex.Message);
        }
コード例 #10
0
        public void incorrectHeader()
        {
            var analyser = new StateCensusAnalyser();
            StateCensusAnalyserDelegate deligate = new StateCensusAnalyserDelegate(analyser.LoadCsvData);
            var ex = Assert.Throws <CsvCustomException>(() => deligate.Invoke("C:/Users/User/source/repos/StateCensusData.csv", CsvStateCensusHeader, CsvStateCodeHeader));

            Assert.AreEqual("Delimeter or Header is incorrect", ex.Message);
        }
コード例 #11
0
        public void GivenCSVFile_WhenNumberOfRecordsMatches_ShoulReturnTrue()
        {
            string filePath   = @"E:\CodinClub\Assignments_Fellowship\Census_Analyser_Problem\CensusAnalyser\CensusAnalyser\IndiaStateCensusData.csv";
            int    CSVRecords = CSVStateCensusAnalyser.GetRecords(filePath);
            int    records    = StateCensusAnalyser.GetStateCensusRecords(filePath);

            Assert.AreEqual(CSVRecords, records);
        }
コード例 #12
0
        public void UseCase4_CheckEndState_InAJsonFile_WhenAnalyse_ItShouldReturnMatched()
        {
            var    json = StateCensusAnalyser.SortStateAlphabatic(3, CorrectFilePath_Usecase2);
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[experiencesArrary.Count - 1]["StateName"].ToString();
            var    Expected          = "West Bengal";

            Assert.AreEqual(actual, Expected);
        }
コード例 #13
0
        public void UseCase3_CheckStartState_InAJsonFile_WhenAnalyse_ItShouldReturnMatched()
        {
            var    json = StateCensusAnalyser.SortStateAlphabatic(State, CorrectFilePath_Usecase1);
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[0]["State"].ToString();
            var    Expected          = "Andhra Pradesh";

            Assert.AreEqual(actual, Expected);
        }
コード例 #14
0
        public void UseCase6_CheckStateCensusData_MostDensityPerSqKmState_WhenAnalyse_ItShouldReturnCorrect()
        {
            var    json = StateCensusAnalyser.StateCensusSortByIntegerValue(DensityPerSqKm, @"C:\Users\Bridge Labz\source\repos\CensusAnalyserLibrary\StateCensusData.CSV");
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[0]["State"].ToString();
            var    Expected          = "Bihar";

            Assert.AreEqual(actual, Expected);
        }
コード例 #15
0
        public void UseCase5_CheckStateCensusData_LesspopulationState_WhenAnalyse_ItShouldReturnCorrect()
        {
            var    json = StateCensusAnalyser.StateCensusSortByIntegerValue(Population, @"C:\Users\Bridge Labz\source\repos\CensusAnalyserLibrary\StateCensusData.CSV");
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[experiencesArrary.Count - 1]["State"].ToString();
            var    Expected          = "Sikkim";

            Assert.AreEqual(actual, Expected);
        }
コード例 #16
0
        public void UseCase7_CheckStateCensusData_SmallestStateByArea_WhenAnalyse_ItShouldReturnCorrect()
        {
            var    json = StateCensusAnalyser.StateCensusSortByIntegerValue(AreaInSqKm, @"C:\Users\Bridge Labz\source\repos\CensusAnalyserLibrary\StateCensusData.CSV");
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[experiencesArrary.Count - 1]["State"].ToString();
            var    Expected          = "Arunachal Pradesh";

            Assert.AreEqual(actual, Expected);
        }
コード例 #17
0
        public void UseCase9_CheckUSStateCensusData_LessPopulusState_WhenAnalyse_ItShouldReturnCorrect()
        {
            var    json = StateCensusAnalyser.StateCensusSortByIntegerValue(2, @"C:\Users\Bridge Labz\source\repos\CensusAnalyserLibrary\USCensus.csv");
            JArray experiencesArrary = JArray.Parse(json);
            var    actual            = experiencesArrary[experiencesArrary.Count - 1]["State"].ToString();
            var    Expected          = "Wyoming";

            Assert.AreEqual(actual, Expected);
        }
コード例 #18
0
        public void givenStateCensusData_ifHasCorrectNumberOfRecord_ShouldReturnTrue()
        {
            StateCensusAnalyser    stateCensusAnalyser = new StateCensusAnalyser();
            List <StateCensusData> list = stateCensusAnalyser.loadStateCensusData(IndiaCensusDataFilePath1);
            int count = list.Count;

            Console.WriteLine(count);
            Assert.AreEqual(29, count);
        }
コード例 #19
0
        public void GivenStateCodeFileShouldReturnValidRecords()
        {
            int expectedRecordsOfStateCode   = 37;
            int expectedRecordsOfStateCensus = 29;
            int stateCodeRecords             = new StateCensusAnalyser <CSVStates>().ReadFile(CensusLoader <CSVStates> .Country.INDIA, delimiter, StateCodeFilePath);
            int statCensusRecords            = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath);

            Assert.AreEqual(expectedRecordsOfStateCode, stateCodeRecords);
            Assert.AreEqual(expectedRecordsOfStateCensus, statCensusRecords);
        }
コード例 #20
0
        public void UseCase1_GivenCSVFilePathProper_whenAnalyse_ItMatchesTheRecord()
        {
            StateCensusAnalyser obj         = new StateCensusAnalyser();
            DelegateCSVDirector delegateCSV = bb.CSVDirector;
            var obj1 = delegateCSV(ff.createInstance("AdapterClass"), CorrectFilePath_Usecase1);

            string[] myitems = File.ReadAllLines(@"C:\Users\Bridge Labz\Desktop\censusdata\StateCensusData.CSV");
            int      item    = (int)myitems.Length - 1;

            Assert.AreEqual(item, obj1);
        }
コード例 #21
0
        public void GivenListShouldReturnSortedJsonFormat()
        {
            string expectedFirstState = "Andhra Pradesh";
            string expectedLastState  = "West Bengal";
            int    records            = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath);
            var    dataDictionary     = StateCensusAnalyser <CSVStateCensus> .dataDictionary;
            string sortedJson         = new StateCensusAnalyser <CSVStateCensus>().SortCSVStateCensus(dataDictionary, "State", false);
            var    jArray             = JArray.Parse(sortedJson);
            string firstState         = jArray[0]["Value"]["State"].Value <string>();
            string lastState          = jArray[28]["Value"]["State"].Value <string>();

            Assert.AreEqual(expectedFirstState, firstState);
            Assert.AreEqual(expectedLastState, lastState);
        }
コード例 #22
0
        public void SortByStateAndJsonTestCSVStateCensus()
        {
            string expectedFirstState    = "Uttar Pradesh";
            string expectedLastState     = "Sikkim";
            int    records               = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath);
            var    stateCensusDictionary = StateCensusAnalyser <CSVStateCensus> .dataDictionary;
            string sortedJson            = new StateCensusAnalyser <CSVStateCensus>().SortCSVStateCensus(stateCensusDictionary, "Population", true);
            var    jsonArray             = JArray.Parse(sortedJson);
            string firstState            = jsonArray[0]["Value"]["State"].Value <string>();
            string lastState             = jsonArray[jsonArray.Count - 1]["Value"]["State"].Value <string>();

            Assert.AreEqual(expectedFirstState, firstState);
            Assert.AreEqual(expectedLastState, lastState);
        }
コード例 #23
0
 public void GivenCSVFileName_WhenIncorrectTypeOfFile_ShouldThrowCustomException()
 {
     try
     {
         string filePath   = @"E:\CodinClub\Census_Analyser_Problem\CensusAnalyser\CensusAnalyser\IndiaStateCensusData.txt";
         int    CSVRecords = CSVStateCensusAnalyser.GetRecords(filePath);
         int    records    = StateCensusAnalyser.GetStateCensusRecords(filePath);
         Assert.AreEqual(CSVRecords, records);
     }
     catch (StateCensusAnalyserException e)
     {
         Assert.AreEqual("Name of the file is incorrect", e.Message);
     }
 }
コード例 #24
0
        public void GivenInvalidDelimiterShouldThrowException()
        {
            string expected         = "Invalid Delimiter";
            string custom_Delimiter = ";";

            try
            {
                int records = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, custom_Delimiter, StateCensusFilePath);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(expected, exception.Message);
            }
        }
コード例 #25
0
        public void GivenFileWithInvalidHeaderShouldThrowException()
        {
            string expected = "Invalid Header";
            string filePath = @"C:\Users\Shubham\source\repos\Census-Analyser\CensusAnalyser\StateCensusData.csv";

            try
            {
                int records = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, filePath);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(expected, exception.Message);
            }
        }
コード例 #26
0
        public void GivenIncorrectStatCoDeFileShouldThrowCustomException()
        {
            string expected = "Invalid File";

            try
            {
                int stateCodeRecords   = new StateCensusAnalyser <CSVStates>().ReadFile(CensusLoader <CSVStates> .Country.INDIA, delimiter, StateCensusFilePath);
                int stateCensusRecords = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCodeFilePath);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(expected, exception.Message);
            }
        }
コード例 #27
0
 public void GivenCSVFilePath_WhenIncorrect_ShouldThrowCustomException()
 {
     try
     {
         string filePath   = @"E:\CodinClub\Census_Analyser_Problem\CensusAnalyser\CensusAnalyser\IndiaStateCensusData.csv";
         int    CSVRecords = CSVStateCensusAnalyser.GetRecords(filePath);
         int    records    = StateCensusAnalyser.GetStateCensusRecords(filePath);
         Assert.AreEqual(CSVRecords, records);
     }
     catch (StateCensusAnalyserException e)
     {
         Assert.AreEqual(StateCensusAnalyserException.ExceptionType.INVALID_PATH, e.Type);
         //Assert.AreEqual(e.Message,"Entered wrong path");
     }
 }
コード例 #28
0
        public void GivenInvalidFileTypeShouldThrowCensusAnalyssiException()
        {
            string filepath1 = @"C:\Users\Shubham\source\repos\Census-Analyzer-Problem\StateCode.txt";
            string filepath2 = @"C:\Users\Shubham\source\repos\Census-Analyzer-Problem\StateCensusData.txt";
            string expected  = "Invalid File Type";

            try
            {
                int stateCodeRecords   = new StateCensusAnalyser <CSVStates>().ReadFile(CensusLoader <CSVStates> .Country.INDIA, delimiter, filepath1);
                int stateCensusRecords = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, filepath2);
            }
            catch (Exception exception)
            {
                Assert.AreEqual(expected, exception.Message);
            }
        }
コード例 #29
0
        public void GivenCSVAndJsonPathToAddIntoJSon_AfterSortingOnArea_WhenAnalyse_ReturnlastState()
        {
            string lastValue = StateCensusAnalyser.SortCSVFileOnNumbersAndWriteInJsonAndReturnData(stateCensusDatapath, jsonCsvStateCensuspathjson, "AreaInSqKm");

            Assert.AreEqual("0", lastValue);
        }
コード例 #30
0
        public void GivenCsvStateCensusAndJson_ToSortFromMostPopulousToLeast_WhenAnalyse_ReturnTheNumberOfSatetesSorted()
        {
            int count = StateCensusAnalyser.SortCSVFileOnNumberAndWriteInJsonAndReturnNumberOfStatesSorted(stateCensusDatapath, jsonCsvStateCodepathjson, "Population");

            Assert.Zero(count);
        }