public object ImportFile(string path, int month, int year, string provider) { JoeUtils.YearMonthCheck(year, month); if (provider.ToLower() == "oxford") { List<OxfordLineItem> items = OxfordUtils.ReadFile(path); OxfordLineItemCollection coll = new OxfordLineItemCollection(items); coll.SaveToDatabase(year, month, true); return new { LineItems = items.Count }; } else if (provider.ToLower() == "horizon") { List<HorizonLineItem> items = HorizonUtils.ReadFile(path); HorizonLineItemCollection coll = new HorizonLineItemCollection(items); coll.SaveToDatabase(year, month, true); return new { LineItems = items.Count }; } else { throw new InvalidOperationException(String.Format("'{0}' is not a valid provider name.", provider)); } }
public void TestOverwrite() { HorizonLineItemCollection Horizons = new HorizonLineItemCollection(HorizonUtils.ReadFile(HorizonTestFileText)); // try to overwrite try { Horizons.SaveToDatabase(1990, 1); Assert.Fail("Records Overwritten!"); } catch { Assert.IsTrue(true, ""); } }
public void TestSaveAndDeleteRecordsText() { int month = 1; int year = 1990; repos.DeleteHorizonRecords(year, month); repos.SaveChanges(); int count = repos.RawHorizonRecordsCount(year, month); Assert.AreEqual(0, count, String.Format("Should be no records (M/Y): {0}/{1}, they were deleted; found: {2}.", month, year, count)); // read from file, save items HorizonLineItemCollection Horizons = new HorizonLineItemCollection(HorizonUtils.ReadFile(HorizonTestFileText)); Horizons.SaveToDatabase(year, month, true); count = repos.RawHorizonRecordsCount(year, month); Assert.AreEqual(4269, count, String.Format("Should be 318 records (M/Y): {0}/{1}; found {2}.", month, year, count)); }