public bool Save(string newName = null) { if (!string.IsNullOrEmpty(newName)) { SaveName = newName; } if (string.IsNullOrEmpty(SaveName)) { Utils.Alert("Error", "An error occured saving the variables. No save name was provided."); return(false); } try { var stream = File.Create(SavePath); var streamWriter = new StreamWriter(stream); var csvWriter = new CsvFactory().CreateWriter(streamWriter); csvWriter.WriteHeader <Variable>(); csvWriter.WriteRecords(Items); streamWriter.Flush(); streamWriter.Close(); IsModified = false; return(true); } catch { Utils.Alert("Error", "An error has occured saving the variables to \"" + SavePath + "\"."); return(false); } }
public void checkForNumberOfRecordsInCsvCode() { //send 1 for not sorting and not json format int jasonForm = 1; int sort = 1; int columnNumber = 3; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(PathOfCsvStateCode, jasonForm, sort, columnNumber, stringIsCharOrInt); //get number of record from csv code var numberOfRecord = state.getNumberOfRecrd(); //if same then pass Assert.AreEqual(37, numberOfRecord); string pathStateCensusData = @"D:\trimbak\state analys\StateCensusData.csv"; //call the read data and retun the output dynamically and store in var CsvFactory state2 = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); var numberOfRecord1 = state2.getNumberOfRecrd(); //if same then pass Assert.AreEqual(29, numberOfRecord1); }
static void Main(string[] args) { var customerLines = System.IO.File.ReadAllLines(@"Customers.csv"); var orderLines = System.IO.File.ReadAllLines(@"Orders.csv"); var orderItemLines = System.IO.File.ReadAllLines(@"OrderItemLines.csv"); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.Name).Type(typeof(string)).Index(1); builder.AddNavigation(n => n.Orders).RelationKey <Order, int>(k => k.CustomerId); }, false, ',', customerLines); CsvFactory.Register <Order>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.CustomerId).Type(typeof(int)).Index(1); builder.Add(a => a.Quantity).Type(typeof(int)).Index(2); builder.Add(a => a.Amount).Type(typeof(int)).Index(3); builder.AddNavigation(n => n.OrderItems).RelationKey <OrderItem, int>(k => k.OrderId); }, true, ',', orderLines); CsvFactory.Register <OrderItem>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.OrderId).Type(typeof(int)).Index(1); builder.Add(a => a.ProductName).Type(typeof(string)).Index(2); }, false, ',', orderItemLines); var customers = CsvFactory.Parse <Customer>(); }
public void skip_header_test() { string customer2 = @"1,Project 1 2,Project 2 3,Project 3 4,Project 4 5,Project 5"; var lines = customer2.Split('\n'); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0); builder.Add(a => a.Name).Type(typeof(string)).Index(1); }, true, ',', lines); var list = CsvFactory.Parse <Customer>(); Assert.IsTrue(4 == list.Count); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0); builder.Add(a => a.Name).Type(typeof(string)).Index(1); }, false, ',', lines); list = CsvFactory.Parse <Customer>(); Assert.IsTrue(5 == list.Count); }
public void Load() { if (!File.Exists(SavePath)) { IsModified = true; return; } try { var stream = File.OpenRead(SavePath); var streamReader = new StreamReader(stream); var csvReader = new CsvFactory().CreateReader(streamReader); foreach (var variable in csvReader.GetRecords <Variable>()) { Add(variable); } streamReader.Close(); } catch { Utils.Alert("Error", "An error has occured reading the variables from \"" + SavePath + "\"."); return; } }
public void csv_parser_test() { var lines = customer.Split('\n'); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0); builder.Add(a => a.Name).Type(typeof(string)).Index(1); }, true, ',', lines); var list = CsvFactory.Parse <Customer>(); Assert.IsTrue(5 == list.Count); }
public GetProjectCards( ILogger <GetProjectCards> logger, IOptions <ConfigRoot> options, ClientFactory clientFactory, CsvFactory csvFactory ) { _logger = logger; _clientFactory = clientFactory; _projects = options.Value.GitHub?.Projects ?? throw new ConfigurationException(nameof(GitHubConfig.Projects)); _columns = options.Value.GitHub?.Columns; _output = options.Value.Outputs?.FirstOrDefault(o => o.Workload == this.Name); _output?.Verify(); _csvFactory = csvFactory; }
public void checkForNumberOfRecordsInUScensusData() { //send 1 for not sorting and not json format int jasonForm = 1; int sort = 1; int columnNumber = 3; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(Path, jasonForm, sort, columnNumber, stringIsCharOrInt); //get number of record from csv code var numberOfRecord = state.getNumberOfRecrd(); //if same then pass Assert.AreEqual(51, numberOfRecord); }
public void navigation_test() { string customer = @"1,Ahmet 2,Alper 3,Osman 4,Ayse 5,Melek"; var customerLines = customer.Split("\n"); string order = @"Id,CustomerId,Quantity,Amount 1,1,1,10 2,1,2,25 4,1,1,50 8,1,1,7 3,2,4,324 6,2,2,5 5,5,1,50 7,5,4,4"; var orderLines = order.Split("\n"); CsvFactory.Register <Order>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.CustomerId).Type(typeof(int)).Index(1); builder.Add(a => a.Quantity).Type(typeof(int)).Index(2); builder.Add(a => a.Amount).Type(typeof(int)).Index(3); }, true, ',', orderLines); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.Name).Type(typeof(string)).Index(1); builder.AddNavigation(n => n.Orders).RelationKey <Order, int>(k => k.CustomerId); }, false, ',', customerLines); var customers = CsvFactory.Parse <Customer>(); Assert.IsTrue(customers.Count == 5); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ahmet").Orders.Count == 4, "Ahmet"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Alper").Orders.Count == 2, "Alper"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Osman").Orders.Count == 0, "Osman"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ayse").Orders.Count == 0, "Ayse"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Melek").Orders.Count == 2, "Melek"); }
public void CheckForJsonFormatLastState() { int jasonForm = 0; int sort = 0; int columnNumber = 3; int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(PathOfCsvStateCode, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); //get last string of record int column = 3; string lastState = sortedList[state.getNumberOfRecrd()][column]; Assert.AreEqual("WB", lastState); }
public void CheckForJsonFormatLeastPopulatedState() { int jasonForm = 0; int sort = 0; int columnNumber = 1; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 1; //call constructor of csv file CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); int ColumnNumber = 0; //get last string of record string firstLowPopulation = sortedList[1][ColumnNumber]; Assert.AreEqual("Sikkim", firstLowPopulation); }
public void ChecklessPopulatedState() { int jasonForm = 0; int sort = 0; int columnNumber = 2; int stringIsCharOrInt = 1; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(Path, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); //get first string of record int row = 1; int column = 1; string first = sortedList[row][column]; Assert.AreEqual("Wyoming", first); }
public void CheckForJsonFormatLastState() { int jasonForm = 0; int sort = 0; int columnNumber = 0; //if it is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call constructor of csv file CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); int ColumnNumber = 0; //get last string of record string lastState = sortedList[state.getNumberOfRecrd()][ColumnNumber]; Assert.AreEqual("West Bengal", lastState); }
public void CheckForJsonFormatFirstState() { int jasonForm = 0; int sort = 0; int columnNumber = 0; //call the constructor int stringIsCharOrInt = 0; //call readdata and return output store in var output CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); int rowNumber = 0; int ColumnNumber = 0; //get first string of record string first = sortedList[rowNumber][ColumnNumber]; Assert.AreEqual("Andhra Pradesh", first); }
public void CanWriteCsvFromDataReader() { using (var conn = TestDb.Open()) { using (var reader = Db.getDateDetailsDataReader(conn, DateTime.Parse("2013/06/30"), DateTime.Parse("2014/12/31"))) { using (var stringWriter = new StringWriter()) { using (var writer = new CsvFactory().CreateWriter(stringWriter)) { writer.WriteRecords(reader); var text = stringWriter.ToString(); Debug.WriteLine(text); text.Should().NotBeEmpty(); } } } } }
public void CheckForJsonFormatsmallestAreaState() { int jasonForm = 0; int sort = 0; int columnNumber = 4; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 1; //call the constructor CsvFactory state = new CsvFactory(Path, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); //var output=state.getRecord(); int ColumnNumber = 1; //get last string of record string lastState = sortedList[1][ColumnNumber]; Assert.AreEqual("District of Columbia", lastState); }
public void CheckForJsonFormatLargestAreaState() { int jasonForm = 0; int sort = 0; int columnNumber = 2; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 1; //call the constructor CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //get json formated output var sortedJsonFile = state.getJesonFormatRecord(); //deserialize objects to list var sortedList = JsonConvert.DeserializeObject(sortedJsonFile); // var output=state.getRecord(); int rowNumber = 29; int ColumnNumber = 0; //get first string of record string highest = sortedList[rowNumber][ColumnNumber]; Assert.AreEqual("Rajasthan", highest); }
public void checkForFirstStateCsvCode() { //expected output var expectedState = "AD"; //send o for sorting and json format int jasonForm = 0; int sort = 0; //sorting apply on this column int columnNumber = 3; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(PathOfCsvStateCode, jasonForm, sort, columnNumber, stringIsCharOrInt); //get sorted record from csv code var firstState = state.getRecord(); int row = 0; int column = 3; firstState = firstState[row][column]; //if equal then pass Assert.AreEqual(expectedState, firstState); }
public void checkForFirstStateCsvData() { //expected output var expectedState = "Andhra Pradesh"; //send o for sorting and json format int jasonForm = 0; int sort = 0; //sorting apply on this column int columnNumber = 0; //if it is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call readdata and return output store in var output CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //var output = builder.readData(pathStateCensusData, jasonForm, sort, columnNumber); //second output is store in firststate first sorted record int rowNumber = 0; int ColumnNumber = 0; var firstState = state.getRecord(); firstState = firstState[rowNumber][ColumnNumber]; //if equal then pass Assert.AreEqual(expectedState, firstState); }
public void checkForHeadersInCsvData() { //expected headers name string[] expectedHeader = { "State", "Population", "AreaInSqKm", "DensityPerSqKm" }; //assign parameters 1 for not run int jasonForm = 1; int sort = 1; //send sorting column number int columnNumber = 0; int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var //return tuple this is new concept to return mulltiple values //and get pertcular value Item1,Item2,Item3,Item4 CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); var output = state.getHeaders(); //my itoe three is heeders name //if expected output and real output cheack if equal then pass the test for (int i = 0; i < expectedHeader.Length; i++) { Assert.AreEqual(expectedHeader[i], output[i]); } }
public void checkForLastStateCsvCode() { //expected output var expectedState = "WB"; //send 0 for sorting and json format int jasonForm = 0; int sort = 0; int columnNumber = 3; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(PathOfCsvStateCode, jasonForm, sort, columnNumber, stringIsCharOrInt); //last record index get from number of record var lastRecordIndex = state.getNumberOfRecrd(); //get sorted list last state in alphabetical order var LastState = state.getRecord(); //get last record from sorted file int column = 3; LastState = LastState[lastRecordIndex][column]; //if same then pass Assert.AreEqual(expectedState, LastState); }
public void checkForHeadersInCsvCode() { //expected headers name string[] expectedHeader = { "SrNo", "StateName", "TIN", "StateCode" }; //assign parameters 1 for not run int jasonForm = 1; int sort = 1; //send sorting column number int columnNumber = 3; //if sorting column is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call the read data and retun the output dynamically and store in var CsvFactory state = new CsvFactory(PathOfCsvStateCode, jasonForm, sort, columnNumber, stringIsCharOrInt); //geting heders name by this function var output = state.getHeaders(); //my itoe three is heeders name //if expected output and real output cheack if equal then pass the test for (int i = 0; i < expectedHeader.Length; i++) { Assert.AreEqual(expectedHeader[i], output[i]); } }
public void checkForLastStateCsvData() { //expected output var expectedState = "West Bengal"; //send 0 for sorting and json format int jasonForm = 0; int sort = 0; int columnNumber = 0; //if it is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call readdata and return output store in var output CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //geting number of record var lastRecordIndex = state.getNumberOfRecrd(); //geting sorted record var LastState = state.getRecord(); int ColumnNumber = 0; LastState = LastState[lastRecordIndex][ColumnNumber]; //if same then pass Assert.AreEqual(expectedState, LastState); }
public void checkForNumberOfRecordsInCsvData() { //send 1 for not sorting and not json format int jasonForm = 1; int sort = 1; int columnNumber = 0; //if it is alphabetical then send 0 otherwise send 1 int stringIsCharOrInt = 0; //call readdata and return output store in var output CsvFactory state = new CsvFactory(pathStateCensusData, jasonForm, sort, columnNumber, stringIsCharOrInt); //itome three is number of record var numberOfRecord = state.getNumberOfRecrd(); //if same then pass Assert.AreEqual(29, numberOfRecord); /* string PathOfCsvStateCode = @"D:\trimbak\state analys\StateCode.csv"; * //call the comstructor and send path * csvData state1 = new csvData(PathOfCsvStateCode, jasonForm, sort, columnNumber); * var numberOfRecord2 = state1.getNumberOfRecrd(); * //if same then pass * Assert.AreEqual(37, numberOfRecord2);*/ }
[TestMethod]//navigation support infinity public void navigation_of_navigation_test() { string customer = @"1,Ahmet 2,Alper 3,Osman 4,Ayse 5,Melek"; var customerLines = customer.Split("\n"); string order = @"Id,CustomerId,TotalQuantity,TotalAmount 1,1,1,10 2,1,2,25 3,1,1,50 4,1,1,7 5,2,4,324 6,2,2,5 7,5,1,50 8,5,4,4"; var orderLines = order.Split("\n"); string orderItem = @"Id,OrderId,ProductName 1,1,1 2,8,2 3,1,1 4,2,1 5,7,4 6,3,2 7,6,1 8,3,1 9,4,1 10,4,1 11,1,1 12,8,1 13,1,1 14,5,1 15,4,1 16,5,1 17,7,1 18,8,1 19,5,4"; var orderItemLines = orderItem.Split("\n"); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.Name).Type(typeof(string)).Index(1); builder.AddNavigation(n => n.Orders).RelationKey <Order, int>(k => k.CustomerId); }, false, ',', customerLines); CsvFactory.Register <Order>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.CustomerId).Type(typeof(int)).Index(1); builder.Add(a => a.Quantity).Type(typeof(int)).Index(2); builder.Add(a => a.Amount).Type(typeof(int)).Index(3); builder.AddNavigation(n => n.OrderItems).RelationKey <OrderItem, int>(k => k.OrderId); }, true, ',', orderLines); CsvFactory.Register <OrderItem>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.OrderId).Type(typeof(int)).Index(1); builder.Add(a => a.ProductName).Type(typeof(string)).Index(2); }, false, ',', orderItemLines); var customers = CsvFactory.Parse <Customer>(); Assert.IsTrue(customers.Count == 5); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ahmet").Orders.Count == 4, "Ahmet"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Alper").Orders.Count == 2, "Alper"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Osman").Orders.Count == 0, "Osman"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ayse").Orders.Count == 0, "Ayse"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Melek").Orders.Count == 2, "Melek"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ahmet").Orders.SelectMany(s => s.OrderItems).Count() == 10, "Ahmet"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Alper").Orders.SelectMany(s => s.OrderItems).Count() == 4, "Alper"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Osman").Orders.SelectMany(s => s.OrderItems).Count() == 0, "Osman"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ayse").Orders.SelectMany(s => s.OrderItems).Count() == 0, "Ayse"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Melek").Orders.SelectMany(s => s.OrderItems).Count() == 5, "Melek"); }
[TestMethod]//multiple navigation support infinity public void multiple_navigation_test() { string customer = @"1,Ahmet 2,Alper 3,Osman 4,Ayse 5,Melek"; var customerLines = customer.Split("\n"); string order = @"Id,CustomerId,TotalQuantity,TotalAmount 1,1,1,10 2,1,2,25 3,1,1,50 4,1,1,7 5,2,4,324 6,2,2,5 7,5,1,50 8,5,4,4"; var orderLines = order.Split("\n"); string adresItem = @"Id,CustomerId,Name 1,1,Ev 2,1,Ev 3,2,Is 4,3,Ev 5,4,Is 6,5,IS 7,1,Is 8,3,Ev 9,3,Ev"; var adresLines = adresItem.Split("\n"); CsvFactory.Register <Customer>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.Name).Type(typeof(string)).Index(1); builder.AddNavigation(n => n.Orders).RelationKey <Order, int>(k => k.CustomerId); builder.AddNavigation(n => n.Addresses).RelationKey <Address, int>(k => k.CustomerId); }, false, ',', customerLines); CsvFactory.Register <Order>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.CustomerId).Type(typeof(int)).Index(1); builder.Add(a => a.Quantity).Type(typeof(int)).Index(2); builder.Add(a => a.Amount).Type(typeof(int)).Index(3); }, true, ',', orderLines); CsvFactory.Register <Address>(builder => { builder.Add(a => a.Id).Type(typeof(int)).Index(0).IsKey(true); builder.Add(a => a.CustomerId).Type(typeof(int)).Index(1); builder.Add(a => a.Name).Type(typeof(string)).Index(2); }, false, ',', adresLines); var customers = CsvFactory.Parse <Customer>(); Assert.IsTrue(customers.Count == 5); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ahmet").Orders.Count == 4, "Ahmet"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Alper").Orders.Count == 2, "Alper"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Osman").Orders.Count == 0, "Osman"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ayse").Orders.Count == 0, "Ayse"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Melek").Orders.Count == 2, "Melek"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ahmet").Addresses.Count == 3, "Ahmet"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Alper").Addresses.Count == 1, "Alper"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Osman").Addresses.Count == 3, "Osman"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Ayse").Addresses.Count == 1, "Ayse"); Assert.IsTrue(customers.SingleOrDefault(c => c.Name == "Melek").Addresses.Count == 1, "Melek"); }