public void Import() { var importer = new TankCapacityImporter { AccessFile = ".\\Data\\Data.mdb" }; importer.RawDataFiles.AddRange(new[] { ".\\Data\\tank 01 raw data.txt", ".\\Data\\tank 02 raw data.txt" }); importer.Import(); var tankDb = new TankDb(); var vessel = tankDb.GetVessel(); var tanks = tankDb.GetAllTanks(); var volItems = tankDb.GetAllOilVolumeItems(); Assert.AreEqual("imported vessel 01", vessel.Name); Assert.AreEqual("imported cert 01", vessel.CertNo); Assert.IsTrue(tanks.Any(t => t.Name == "imported tank 01")); Assert.IsTrue(tanks.Any(t => t.Name == "imported tank 02")); Assert.AreEqual(27 + 8, volItems.Count()); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 01" && v.HInclination == -0.5m && v.VInclination == -0.6m && v.Height == 3m && v.Volume == 100m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 01" && v.HInclination == -0.5m && v.VInclination == 0m && v.Height == 1m && v.Volume == 99m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 01" && v.HInclination == 0m && v.VInclination == -0.3m && v.Height == 2m && v.Volume == 1099.2m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 01" && v.HInclination == 0.5m && v.VInclination == 0m && v.Height == 2m && v.Volume == 2099.3m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 02" && v.HInclination == -5m && v.VInclination == -6m && v.Height == 2m && v.Volume == 1m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 02" && v.HInclination == 0m && v.VInclination == -3m && v.Height == 1m && v.Volume == 8m)); Assert.IsTrue(volItems.Any(v => v.TankName == "imported tank 02" && v.HInclination == 0m && v.VInclination == -3m && v.Height == 2m && v.Volume == 6m)); Assert.IsTrue(!volItems.Any(v => v.TankName == "imported tank 02" && v.HInclination == 0m && v.VInclination == -3m && v.Height == 2m && v.Volume == 8m)); }
public TankCapacityImportingForm() { InitializeComponent(); this.menuAddRawDataFiles.Click += (sender, e) => this.AddRawDataFiles(); this.menuSelectAccessFile.Click += (sender, e) => this.SelectAccessFile(); this.listTxtFiles.SelectedIndexChanged += (sender, e) => this.menuRemoveSelected.Enabled = this.listTxtFiles.SelectedIndex >= 0; this.menuRemoveSelected.Click += (sender, e) => this.RemoveSelected(); this.menuImport.Click += (sender, e) => this.StartImport(); this.chkWrapOutput.CheckedChanged += (sender, e) => this.txtOutput.WordWrap = chkWrapOutput.Checked; this.worker.DoWork += (sender, e) => { this.stopwatch.Start(); this.ResetOutput(); this.WriteOutput(TraceLevel.Info, String.Format("Start importing ({0})", DateTime.Now.ToString("HH:mm:ss"))); var importer = new TankCapacityImporter { AccessFile = this.txtAccessFile.Text }; importer.WriteLog += (l, m) => this.WriteOutput(l, m); this.listTxtFiles.Items.OfType <string>().Each(f => importer.RawDataFiles.Add(f)); importer.Import(); }; this.worker.RunWorkerCompleted += (sender, e) => { this.menuAddRawDataFiles.Enabled = true; this.menuSelectAccessFile.Enabled = true; this.menuImport.Enabled = true; this.listTxtFiles.Enabled = true; if (e.Error == null) { this.WriteOutput(TraceLevel.Off, "Importing finished successfully)"); } else { this.WriteOutput(TraceLevel.Error, String.Format("Importing finished with error: {0}", e.Error.Message)); } this.WriteOutput(TraceLevel.Info, String.Format("Time elapsed: {0}", this.stopwatch.Elapsed.ToString())); this.stopwatch.Reset(); }; }
private void VerifyThatShouldThrow(IEnumerable <string> rawDataFiles, string expectedPrefix) { var importer = new TankCapacityImporter { AccessFile = ".\\Data\\Data.mdb" }; importer.RawDataFiles.AddRange(rawDataFiles); Exception actual = null; try { importer.Import(); } catch (Exception ex) { actual = ex; } Assert.AreEqual(expectedPrefix, actual.InnerException.Message.Substring(0, expectedPrefix.Length)); }