Пример #1
0
        private static void LoadFile(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                var csv = new CsvReader(sr);
                while (csv.Read())
                {
                    //Import Customer(Account and Parent)
                    int accountId = ImportCustomer(csv);

                    //ClassInfo
                    ClassInfo classInfo = new ClassInfo();
                    classInfo.FromCsv(csv);

                    using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
                    {
                        ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                        repo.Add(classInfo);

                        try
                        {
                            //Save to DB
                            dbContext.SaveChanges();
                        }
                        catch (DbEntityValidationException)
                        {
                            throw;
                        }
                    }
                }
            }
        }
Пример #2
0
        public void ClassInfoIntegationTests_AddClass()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);
                repo.Add(new ClassInfo {
                    ClassCategoryId = 1, ClassName = "TestClass", Location = "Trails", ProductCode = "C12345", DateStart = DateTime.Now, DateEnd = DateTime.Now
                });
                try
                {
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    Assert.Fail(exc.EntityValidationErrors.ToString());
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.FindOne(c => c.ClassName == "TestClass");
                Assert.IsNotNull(res);
            }
        }