public void CreateCategory() { cat.Add(new Category(1, "test", "billede.jpeg", true, 2)); Category cats = cat.GetById(1); Assert.AreEqual(cats._name, "test"); }
public void ShouldGetACategoryWithProductInfo() { var category = new Category { CategoryName = "Foo" }; _repo.Add(category, true); //var cat = _repo.GetOneWithProducts(2); //Assert.Equal(2, cat.Products.Count()); }
public void ShouldNotDeleteACategoryFromSameContextWithConcurrencyIssue() { var category = new Category { CategoryName = "Foo" }; _repo.Add(category); Assert.Equal(1, _repo.Count); var ex = Assert.Throws <Exception>(() => _repo.Delete(category.Id, null, false)); }
public void ShouldAddACategory() { var category = new Category { CategoryName = "Foo" }; var count = _repo.Add(category); Assert.Equal(1, count); Assert.Equal(0, category.Id); Assert.Equal(1, _repo.Count); }
public void GetAll() { MySqlCommand cmd = new MySqlCommand(@" SELECT Id, Name, Thumbnail, Service, Alarm FROM Category "); DataTable dt = db.GetData(cmd); if (dt != null) { foreach (DataRow rw in dt.Rows) { MySqlCommand cmdProp = new MySqlCommand(@" SELECT CategoryId, ValueId FROM CategoryValues WHERE CategoryId = @id "); cmdProp.Parameters.AddWithValue("@id", Convert.ToInt32(rw["id"])); DataTable dtProp = db.GetData(cmdProp); List <Property> ListProp = new List <Property>(); foreach (DataRow row in dtProp.Rows) { Property prop = PropRep.GetById(Convert.ToInt32(row["ValueId"])); ListProp.Add(prop); } Category cat = new Category(Convert.ToInt32(rw["Id"]), rw["Name"].ToString(), ListProp, rw["Thumbnail"].ToString(), Convert.ToBoolean(rw["Service"]), Convert.ToInt32(rw["Alarm"])); rep.Add(cat); } } }
public IActionResult Create(Category model) { if (ModelState.IsValid) { _categoryRepo.Add(model); return(RedirectToAction("Index")); } return(View()); }
public void ShouldDeleteACategoryFromSameContext() { var category = new Category { CategoryName = "Foo" }; _repo.Add(category); Assert.Equal(1, _repo.Count); var count = _repo.Delete(category.Id, category.TimeStamp, false); Assert.Equal(0, count); count = _repo.SaveChanges(); Assert.Equal(1, count); Assert.Equal(0, _repo.Count); }
public void ShouldThrowRetryExeptionWhenCantConnect() { var contextOptionsBuilder = new DbContextOptionsBuilder <StoreContext>(); var connectionString = @"Server=(localdb)\mssqllocaldb;Database=SpyStore;user id=foo;password=bar;MultipleActiveResultSets=true;"; //contextOptionsBuilder.UseSqlServer(connectionString, // o => o.EnableRetryOnFailure(2,new TimeSpan(0,0,0,0,100),new Collection<int>{ -2146232060 })); contextOptionsBuilder.UseSqlServer(connectionString, o => o.ExecutionStrategy(c => new MyExecutionStrategy(c, 5, new TimeSpan(0, 0, 0, 0, 30)))); var repo = new CategoryRepo(contextOptionsBuilder.Options); var category = new Category { CategoryName = "Foo" }; var ex = Assert.Throws <RetryLimitExceededException>(() => repo.Add(category)); }
public void AddCategory(Category obj) { Category newCat = catData.Add(obj); CatRep.Add(newCat); }
private void btsave_Click(object sender, EventArgs e) { ListCategory = categoryRepo.GetAll(); int samename = 0; if (Editmode) { foreach (var existingdetails in ListCategory) { if (existingdetails.name == tbcatname.Text && existingdetails.catid != CategoryData.catid) { samename += 1; break; } } if (tbcatname.Text == "") { MessageBox.Show("Yang bertanda Bintang tidak boleh kosong"); } else if (samename > 0) { MessageBox.Show("Nama yang anda masukkan sudah terdaftar"); samename = 0; } else { var CatDataBefore = new CategoryColumns(); CatDataBefore.name = CategoryData.name; CatDataBefore.remark = CategoryData.remark; CategoryData.name = tbcatname.Text; CategoryData.remark = tbremark.Text; CategoryData.updated_by = userdata.username; bool havechanges = false; if (CatDataBefore.name == CategoryData.name && CatDataBefore.remark == CategoryData.remark) { havechanges = true; } if (havechanges) { MessageBox.Show("Tidak ada data yang anda ubah"); CategoryData.name = CatDataBefore.name; CategoryData.remark = CatDataBefore.remark; } else if (categoryRepo.Update(CategoryData)) { MessageBox.Show("Data telah berhasil di ubah"); Close(); } else { MessageBox.Show("Data gagal di ubah"); CategoryData.name = CatDataBefore.name; CategoryData.remark = CatDataBefore.remark; } } } else { foreach (var existingdetails in ListCategory) { if (existingdetails.name == tbcatname.Text) { samename += 1; break; } } if (tbcatname.Text == "") { MessageBox.Show(" Yang bertanda Bintang tidak boleh kosong"); } else if (samename > 0) { MessageBox.Show("Nama yang anda masukkan sudah terdaftar"); samename = 0; } else { var cats = new CategoryColumns(); cats.name = tbcatname.Text; cats.remark = tbremark.Text; cats.created_by = userdata.username; if (categoryRepo.Add(cats)) { MessageBox.Show("Data baru telah berhasil di tambahkan"); Close(); } else { MessageBox.Show("Data baru gagal ditambahkan"); } } } }
public bool Add(Category category) { return(_categoryRepository.Add(category)); }