Ejemplo n.º 1
0
        public void TestSaveAndDeleteRecords()
        {
            int month = 1;
            int year = 1990;

            repos.DeleteOxfordRecords(year, month);
            repos.SaveChanges();

            int count = repos.RawOxfordRecordsCount(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
            OxfordLineItemCollection oxfords = new OxfordLineItemCollection(OxfordUtils.ReadFile(OxfordTestFile));
            oxfords.SaveToDatabase(year, month, true);

            count = repos.RawOxfordRecordsCount(year, month);
            Assert.AreEqual(318, count, String.Format("Should be 318 records (M/Y): {0}/{1}; found {2}.", month, year, count));

            // try to do it again, should fail
            try
            {
                oxfords.SaveToDatabase(year, month);
                Assert.Fail("Records overwritten!");
            } catch {
                // all good, check count
                count = repos.RawOxfordRecordsCount(year, month);
                Assert.AreEqual(318, count, String.Format("Should be 318 records (M/Y): {0}/{1}; found {2}.", month, year, count));
            }

            //try again, with overwrite -
            oxfords.SaveToDatabase(year, month, true);
            count = repos.RawOxfordRecordsCount(year, month);
            Assert.AreEqual(318, count, String.Format("Should be 318 records (M/Y): {0}/{1}; found {2}.", month, year, count));
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        public void TestOverwrite()
        {
            OxfordLineItemCollection oxfords = new OxfordLineItemCollection(OxfordUtils.ReadFile(OxfordTestFile));

            // try to overwrite
            try
            {
                oxfords.SaveToDatabase(1990, 1);
                Assert.Fail("Records Overwritten!");
            }
            catch
            {
                Assert.IsTrue(true, "");
            }
        }