public ProductObservableCollection <Product> Build() { ProductObservableCollection <Product> products = new ProductObservableCollection <Product>(); var filePath = String.Format("{0}{1}\\ProductModel.xml", AppDomain.CurrentDomain.BaseDirectory, DBUtility.FilePath); List <ProductModel> list = null; if (this.checkFileFirst) { if (!File.Exists(filePath)) { list = DBUtility.CreateFile <ProductModel>(DBUtility.MockProductModel()); } else { list = DBUtility.DeserializeParamsListOf <ProductModel>(filePath); } } if (list != null) { foreach (ProductModel sp in list) { products.Add(sp.ProductModel2Product()); } } return(products); }
public void Witch_Exception_Will_Fire_PathExist() { //Arrange string pathFile = null; try { //open file pathFile = String.Format("{0}{1}\\ProductModel.xml", AppDomain.CurrentDomain.BaseDirectory, DBUtility.FilePath); bool existexpected = File.Exists(pathFile); if (!File.Exists(pathFile)) { DBUtility.CreateFile <ProductModel>(DBUtility.MockProductModel(), pathFile); } Assert.IsTrue(existexpected); } catch (FileNotFoundException) { Assert.Pass("FileNotFoundException"); } catch (IOException) { Assert.Pass("IOException"); } }
public CustomerModel(bool checkFirsFile) { checkFirsFile = true; if (checkFirsFile) { // See if this file exists in the C:\ directory. [Note the @] var path = String.Format("{0}DBFiles\\CustomerModel.xml", AppDomain.CurrentDomain.BaseDirectory); if (!File.Exists(path)) { DBUtility.CreateFile <CustomerModel>(DBUtility.MockCustomerModel(), path); } } }
public UserObservableCollection <UserVM> Build() { UserObservableCollection <UserVM> users = new UserObservableCollection <UserVM>(); var filePath = String.Format("{0}{1}\\UserModel.xml", AppDomain.CurrentDomain.BaseDirectory, DBUtility.FilePath); List <UserModel> list = null; if (this.checkFileFirst) { if (!File.Exists(filePath)) { DBUtility.CreateFile <DeptoModel>(DBUtility.MockDepartment()); DBUtility.CreateFile <RoleModel>(DBUtility.MockRoles()); list = DBUtility.CreateFile <UserModel>(DBUtility.MockUserModel()); } else { list = DBUtility.DeserializeParamsListOf <UserModel>(filePath); } } //list = DBUtility.DeserializeXMLFileOf <List<UserModel>>(filePath); if (list != null) { foreach (UserModel sp in list) { users.Add(sp.UserModel2User()); } } return(users); }