public void GivenStateCensusDataFileShouldReturnValidRecords() { int expectedNoOFRecords = 29; int records = new StateCensusAnalyser <CSVStateCensus>().ReadFile(CensusLoader <CSVStateCensus> .Country.INDIA, delimiter, StateCensusFilePath); Assert.AreEqual(expectedNoOFRecords, records); }
public void givenStateCensusCsv_sortOntheBasisOfStateName() { StateCensusAnalyser stateCensusAnalyser = new StateCensusAnalyser(); List <StateCensusData> JsonStateCensusData = stateCensusAnalyser.sortByStateName(IndiaCensusDataFilePath1); Assert.AreEqual("Andhra Pradesh", JsonStateCensusData[0].State); }
public void GivenCensusCSVFileAndCSVState_WhenNumberOfRecordMatch_ThenItShouldReturnTrue() { int CSVStateRecord = CSVStates.GetRecord(FILE_PATH); int StateCensusRecord = StateCensusAnalyser.GetStateCensusRecord(STATE_CODE_FILE_PATH); Assert.AreEqual(CSVStateRecord, StateCensusRecord); }
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)); }
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)); }
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)); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); } }
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); } }
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); } }
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); } }
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"); } }
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); } }
public void GivenCSVAndJsonPathToAddIntoJSon_AfterSortingOnArea_WhenAnalyse_ReturnlastState() { string lastValue = StateCensusAnalyser.SortCSVFileOnNumbersAndWriteInJsonAndReturnData(stateCensusDatapath, jsonCsvStateCensuspathjson, "AreaInSqKm"); Assert.AreEqual("0", lastValue); }
public void GivenCsvStateCensusAndJson_ToSortFromMostPopulousToLeast_WhenAnalyse_ReturnTheNumberOfSatetesSorted() { int count = StateCensusAnalyser.SortCSVFileOnNumberAndWriteInJsonAndReturnNumberOfStatesSorted(stateCensusDatapath, jsonCsvStateCodepathjson, "Population"); Assert.Zero(count); }