public void Create_An_Item_With_A_Unique_Code() { // Arrange ItemService _itemService = new ItemService(); List <Item> items = new List <Item>(); Guid book1_guid = Guid.NewGuid(); Guid book2_guid = Guid.NewGuid(); Guid section_guid = Guid.NewGuid(); Guid category_guid = Guid.NewGuid(); Item book1 = new Item { Id = book1_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0001", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; Item book2 = new Item { Id = book2_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0001", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; // Act bool book1_result = _itemService.Add(book1, items); bool book2_result = _itemService.Add(book2, items); // Assert Assert.AreEqual(true, book1_result); Assert.AreEqual(false, book2_result); Assert.AreEqual(1, items.Count); }
public void ShouldNotSaveNullName() { Item item = new Item(0, null, Category.Edible, 5.00M); Result <Item> result = service.Add(item); Assert.IsFalse(result.Success); }
public void AddItem_ValidInput_ExpectTwoItems() { var item1 = new DtoItem() { Availability = true, CategoryID = 3, ItemContent = "Something awesome", ItemDescription = "Yummy", ItemName = "Food", ItemPrice = 200 }; var item2 = new DtoItem() { Availability = true, CategoryID = 2, ItemContent = "Something awesome", ItemDescription = "Yummy", ItemName = "Drink", ItemPrice = 100 }; var item3 = new DtoItem() { Availability = true, CategoryID = 5, ItemContent = "Something awesome", ItemDescription = "Yummy", ItemName = "NjamNjam", ItemPrice = 200 }; var service = new ItemService(); var result1 = service.Add(item1); var result2 = service.Add(item2); var result3 = service.Add(item3); var resultCategories = service.LoadAll(); Assert.IsNotNull(result1); Assert.IsTrue(result1.Success); Assert.IsNotNull(result2); Assert.IsTrue(result2.Success); Assert.IsNotNull(result3); Assert.IsFalse(result3.Success); Assert.IsNotNull(resultCategories); Assert.IsTrue(resultCategories.Success); }
public ResultViewModel <ItemEditViewModel> Add(ItemEditViewModel emp) { ResultViewModel <ItemEditViewModel> result = new ResultViewModel <ItemEditViewModel>(); try { if (!ModelState.IsValid) { result.Message = "In Valid Item Name"; } else { ItemEditViewModel selectedEmp = ItemService.Add(emp); result.Successed = true; result.Data = selectedEmp; } } catch (Exception ex) { result.Successed = false; result.Message = "Semething Went Wrong"; } return(result); }
public void Amend_An_Item_Code() { // Arrange ItemService _itemService = new ItemService(); List <Item> items = new List <Item>(); Guid book1_guid = Guid.NewGuid(); Guid book2_guid = Guid.NewGuid(); Guid book3_guid = Guid.NewGuid(); Guid section_guid = Guid.NewGuid(); Guid category_guid = Guid.NewGuid(); Item book1 = new Item { Id = book1_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0001", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; Item book2 = new Item { Id = book2_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0002", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; Item book3 = new Item { Id = book3_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0003", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; _itemService.Add(book1, items); book1.Code = "ADLTBOOKBROW0099"; // Act bool result = _itemService.Update(book1_guid, book1, items); // Assert Item updated_item = items.Find(i => i.Id == book1_guid); Assert.AreEqual("ADLTBOOKBROW0099", updated_item.Code); }
public IActionResult AddItem(AddItemViewModel model, bool @return) { if (ModelState.IsValid) { _dropdownHelper.CategoryDropdown(); Item item = new Item() { SerialNumber = model.SerialNumber, Description = model.Description, Cost = model.Cost, ItemType = new ItemType { Name = model.Name, CategoryId = model.CategoryId } }; _itemService.Add(item); } else { return(View(model)); } if (@return) { return(RedirectToAction(nameof(ItemList))); } return(View()); }
public ActionResult Create(Item model) { itemService = new ItemService(); var chk = itemService.Add(model); if (chk) { return(RedirectToAction("Index")); } else { return(HttpNotFound()); } }
public void Delete_An_Item() { // Arrange ItemService _itemService = new ItemService(); List <Item> items = new List <Item>(); Guid book1_guid = Guid.NewGuid(); Guid book2_guid = Guid.NewGuid(); Guid book3_guid = Guid.NewGuid(); Guid book4_guid = Guid.NewGuid(); Guid section_guid = Guid.NewGuid(); Guid category_guid = Guid.NewGuid(); Item book1 = new Item { Id = book1_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0001", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277" }; Item book2 = new Item { Id = book2_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0002", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277" }; Item book3 = new Item { Id = book3_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0003", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277" }; Item book4 = new Item { Id = book4_guid, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0004", Author = "Daniel Brown", Title = "The Lost Symbol Large Font", ISBN = "9780593054278" }; _itemService.Add(book1, items); _itemService.Add(book2, items); _itemService.Add(book3, items); _itemService.Add(book4, items); // Act bool result = _itemService.Delete(book1_guid, items); // Assert Assert.AreEqual(3, items.Count); CollectionAssert.DoesNotContain(items, book1); }
private void AddItem() { Item item = view.MakeItem(); Result <Item> result = itemService.Add(item); if (!result.Success) { view.DisplayStatus(false, result.Messages); } else { string successMessage = $"Item {result.Value.Id} created."; view.DisplayStatus(true, successMessage); } }
public void Can_add_item() { using (var context = new ApplicationDbContext(_contextOptions)) { var service = new ItemService(context); Assert.True(service.Add("ItemFour")); } using (var context = new ApplicationDbContext(_contextOptions)) { var item = context.Items.Single(e => e.Name == "ItemFour"); Assert.Equal("ItemFour", item.Name); Assert.Equal(0, item.Tags.Count); } }
public ActionResult Create(ItemCreateViewModel viewModel) { if (ModelState.IsValid) { ServiceResult result = _itemService.Add(viewModel.Model); if (result.Status) { AddSuccessCreatedToastMessage(); return(RedirectToAction("Index")); } else { AddServiceErrorToastMessage(result); return(View(GetCreateViewModel(viewModel))); } } return(View(GetCreateViewModel(viewModel))); }
public void Create_An_Item() { // Arrange ItemService _itemService = new ItemService(); List <Item> items = new List <Item>(); Guid _id = Guid.NewGuid(); Guid section_guid = Guid.NewGuid(); Guid category_guid = Guid.NewGuid(); Item item = new Item { Id = _id, SectionId = section_guid, CategoryId = category_guid, Code = "ADLTBOOKBROW0001", Author = "Dan Brown", Title = "The Lost Symbol", ISBN = "9780593054277", Status = ItemStatus.OnShelf }; // Act bool result = _itemService.Add(item, items); // Assert Assert.AreEqual(true, result); }
private void btnAddNewItem_Click(object sender, RoutedEventArgs e) { if (newItemName.Text == "" || newItemPrice.Text == "" || int.TryParse(newItemPrice.Text, out int itemPrice) == false) { return; } var itemName = newItemName.Text; var newItem = new Item { Name = itemName, Price = itemPrice }; allItems.Add(newItem); itemsListView.Items.Add(new ListViewItem() { Tag = newItem.Name, Content = newItem.Name + " : " + newItem.Price }); newItemName.Text = ""; newItemPrice.Text = ""; }
protected void btnSave_Click(object sender, EventArgs e) { Page.Validate("AddEdit"); if (Page.IsValid) { try { switch (RowID) { case 0: ItemService.Add( txtBarcode.Text, txtDescription.Text, Convert.ToInt32(ddlAccount.SelectedValue), Convert.ToInt32(ddlItemType.SelectedValue), Convert.ToDecimal(txtUnitPrice.Text), chkIsActive.Checked, chkIsTaxed.Checked, String.IsNullOrEmpty(txtUnitName1.Text.Trim()) ? "UNIT" : txtUnitName1.Text, txtUnitName2.Text, txtUnitName3.Text, String.IsNullOrEmpty(txtUnitName2.Text.Trim()) ? 0 : Convert.ToInt32(txtUnitFactor2.Value), String.IsNullOrEmpty(txtUnitName3.Text.Trim()) ? 0 : Convert.ToInt32(txtUnitFactor3.Value), chkHasSessions.Checked ? Convert.ToInt16(txtSessionBalance.Value.GetValueOrDefault(0)) : (short?)null); break; default: ItemService.Update( RowID, txtBarcode.Text, txtDescription.Text, Convert.ToInt32(ddlAccount.SelectedValue), Convert.ToInt32(ddlItemType.SelectedValue), Convert.ToDecimal(txtUnitPrice.Text), chkIsActive.Checked, chkIsTaxed.Checked, String.IsNullOrEmpty(txtUnitName1.Text.Trim()) ? "UNIT" : txtUnitName1.Text, txtUnitName2.Text, txtUnitName3.Text, String.IsNullOrEmpty(txtUnitName2.Text.Trim()) ? 0 : Convert.ToInt32(txtUnitFactor2.Value.GetValueOrDefault(0)), String.IsNullOrEmpty(txtUnitName3.Text.Trim()) ? 0 : Convert.ToInt32(txtUnitFactor3.Value.GetValueOrDefault(0)), chkHasSessions.Checked ? Convert.ToInt16(txtSessionBalance.Value.GetValueOrDefault(0)) : (short?)null); break; } Refresh(); } catch (Exception ex) { WebFormHelper.SetLabelTextWithCssClass(lblMessage, ex.Message, LabelStyleNames.ErrorMessage); LogService.ErrorException(GetType().FullName, ex); } } }
public ItemEditViewModel AddResturantMenuItem(ItemEditViewModel ResturantMenuItemEditView) { var ResturantMenuItem = ItemService.Add(ResturantMenuItemEditView); return(ResturantMenuItem); }
public void AddItem_ValidInput_ExpectTwoItems() { //Act //add categories first if none exist in the database!!! //DtoCategory category1 = new DtoCategory() //{ // MenuId = 1, // CategoryName = "Salads" //}; //DtoCategory category2 = new DtoCategory() //{ // MenuId = 2, // CategoryName = "Sodas" //}; //DtoCategory category3 = new DtoCategory() //{ // MenuId = 3, // CategoryName = "Sandwiches" //}; DtoItem item1 = new DtoItem() { ItemName = "Sandwich", ItemPrice = 120, ItemDescription = "Tuna sandwich", ItemContents = "Bread, tuna, sesame, mayonnaise", ItemAvailability = true, CategoryId = 3 }; DtoItem item2 = new DtoItem() { ItemName = "Caesar salad", ItemPrice = 140, ItemDescription = "Caesar salad", ItemContents = "Chicken meat, iceberg salad, carrots, cheese, sauce", ItemAvailability = true, CategoryId = 1 }; DtoItem item3 = new DtoItem() { ItemName = "Coca-Cola", ItemPrice = 40, ItemDescription = "Coca-Cola", ItemContents = "Coca-Cola soda drink", ItemAvailability = true, CategoryId = 2 }; //Arrange var itemService = new ItemService(); var result1 = itemService.Add(item1); // will add them to the database each time the test is run, and the entries are repeated var result2 = itemService.Add(item2); var result3 = itemService.Add(item3); var resultItems = itemService.LoadAll(); //Assert Assert.IsNotNull(result1); Assert.IsTrue(result1.Success); Assert.IsNotNull(result2); Assert.IsTrue(result2.Success); Assert.IsNotNull(result3); Assert.IsTrue(result3.Success); Assert.IsNotNull(resultItems); Assert.IsTrue(resultItems.Success); Assert.IsNotNull(resultItems.ListItems); //Assert.AreEqual(2, resultItems.ListItems.Count); Assert.IsTrue(resultItems.ListItems.Count >= 3); // since test method adds the same entries to the database, here we check if there are at least 2 created }
public IActionResult Post([FromBody] Item item) { _itemService.Add(item); return(new JsonResult(item)); }
public Item Post(Item item) { return(BaseItemService.Add(item)); }