public void CommaDelimited() { const string content = @"Name,WebSite,Created Google|,http://www.google.com|,9/4/98 Apple|,http://www.apple.com|,4/1/1976 Microsoft|,http://www.microsoft.com|,4/4/1975"; var fileName = Path.GetTempFileName(); File.WriteAllText(fileName, content); JunkResponse response; var request = new JunkRequest(fileName, "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { var importer = scope.Resolve<JunkImporter>(); response = importer.Import(); } var companies = new List<Company>(); using (var cn = new SqlConnection(ConnectionString)) { companies.AddRange(cn.Query<Company>("SELECT Name,Website,Created FROM " + response.TableName + ";")); } Assert.AreEqual(3, companies.Count); var google = companies.First(c => c.Name == "Google|"); var apple = companies.First(c => c.Name == "Apple|"); Assert.AreEqual("http://www.google.com|", google.WebSite); Assert.AreEqual(Convert.ToDateTime("4/1/1976"), apple.Created); }
public void Demo() { JunkResponse response; var request = new JunkRequest(@"C:\Code\JunkDrawer\Test\sample.txt", "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { response = scope.Resolve<JunkImporter>().Import(); } Assert.AreEqual("sample", response.TableName); Assert.AreEqual(4, response.Records); }
static void Main(string[] args) { if (args == null || args.Length == 0) { Console.Error.WriteLine("You must pass in the name of a file you'd like to import into your junk drawer."); WriteUsage(); Environment.Exit(Error); } var file = args[0]; var config = args.Length > 1 ? args[1] : "default.xml"; // check if request has valid file var request = new JunkRequest(file, config); if (!request.IsValid) { Console.Error.WriteLine(request.Message); Environment.Exit(Error); } try { using (var bootstrapper = new AutofacJunkBootstrapper(request)) { var cfg = bootstrapper.Resolve<JunkCfg>(); if (cfg.Errors().Any()) { foreach (var error in cfg.Errors()) { Console.Error.WriteLine(error); Environment.ExitCode = Error; } } else { var response = bootstrapper.Resolve<JunkImporter>().Import(); if (response.Records != 0) return; Console.Error.WriteLine("Did not import any records!"); Environment.ExitCode = Error; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Environment.ExitCode = Error; } }
public void FixedWidth() { const string content = @"Name WebSite Created Google http://www.google.com 9/4/98 Apple http://www.apple.com 4/1/1976 Microsofthttp://www.microsoft.com4/4/1975"; var fileName = Path.GetTempFileName(); File.WriteAllText(fileName, content); JunkResponse response; var request = new JunkRequest(fileName, "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { response = scope.Resolve<JunkImporter>().Import(); } var lines = new List<string>(); using (var cn = new SqlConnection(ConnectionString)) { lines.AddRange(cn.Query<string>("SELECT [Name WebSite Created] FROM " + response.TableName + ";")); } Assert.AreEqual(3, lines.Count); Assert.NotNull(lines.FirstOrDefault(l => l.StartsWith("Google"))); Assert.NotNull(lines.FirstOrDefault(l => l.StartsWith("Apple"))); Assert.NotNull(lines.FirstOrDefault(l => l.StartsWith("Microsoft"))); }
public void ExcelXlsx() { const string fileName = @"C:\Code\JunkDrawer\Test\Files\Excel.xlsx"; JunkResponse response; var request = new JunkRequest(fileName, "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { var importer = scope.Resolve<JunkImporter>(); response = importer.Import(); } var companies = new List<Company>(); using (var cn = new SqlConnection(ConnectionString)) { companies.AddRange(cn.Query<Company>("SELECT Name,Website,Created FROM " + response.TableName + ";")); } Assert.AreEqual(4, companies.Count); var google = companies.First(c => c.Name == "Google"); var apple = companies.First(c => c.Name == "Apple"); var nike = companies.First(c => c.Name == "Nike, Inc."); Assert.AreEqual("http://www.google.com", google.WebSite); Assert.AreEqual(Convert.ToDateTime("4/1/1976"), apple.Created); Assert.AreEqual(Convert.ToDateTime("1/25/1964"), nike.Created); }
public void CommaSeparatedValues() { const string content = @"Name,WebSite,Created ""Google"",http://www.google.com,9/4/98 Apple,http://www.apple.com,""April, 1 1976"" Microsoft,""http://www.microsoft.com"",4/4/1975 ""Nike, Inc."",http://www.nike.com,1/25/1964"; var fileName = Path.GetTempFileName().Replace(".tmp", ".csv"); File.WriteAllText(fileName, content); JunkResponse response; var request = new JunkRequest(fileName, "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { var importer = scope.Resolve<JunkImporter>(); response = importer.Import(); } var companies = new List<Company>(); using (var cn = new SqlConnection(ConnectionString)) { companies.AddRange(cn.Query<Company>("SELECT Name,Website,Created FROM " + response.TableName + ";")); } Assert.AreEqual(4, companies.Count); var google = companies.First(c => c.Name == "Google"); var apple = companies.First(c => c.Name == "Apple"); var nike = companies.First(c => c.Name == "Nike, Inc."); Assert.AreEqual("http://www.google.com", google.WebSite); Assert.AreEqual(Convert.ToDateTime("4/1/1976"), apple.Created); Assert.AreEqual(Convert.ToDateTime("1/25/1964"), nike.Created); }
public JunkConfigurationCreator(JunkCfg cfg, JunkRequest request, ISchemaReader schemaReader) { _cfg = cfg; _request = request; _schemaReader = schemaReader; }