public void ItemService_Add_2_Ok() { var theater = new Theater { Name = "Arena", Type = TheaterType.Cinema }; var theater2 = new Theater { Name = "SNP", Type = TheaterType.Play }; _unitOfWork.Theaters.Add(theater); _unitOfWork.Theaters.Add(theater2); _unitOfWork.SaveChanges(); _itemService.AddItem(theater.TheaterId, new Item { Name = "Arena item" }); _itemService.AddItem(theater.TheaterId, new Item { Name = "Arena item" }); _itemService.AddItem(theater2.TheaterId, new Item { Name = "SNP item" }); var theaterItems = _itemService.GetItemsForTheater(theater.TheaterId); var theater2Items = _itemService.GetItemsForTheater(theater2.TheaterId); Assert.AreEqual(2, theaterItems.Count()); Assert.AreEqual(1, theater2Items.Count()); }
public void AddItemTest() { var serv = new ItemService(new MVCHContext()); serv.AddItem(new Item { Name = "Hospital Stretcher", Description = "For easy transport of patients during emergencies", UnitCost = 5000 }); serv.AddItem(new Item { Name = "Defibrillator", Description = "Restores a normal heartbeat through electric pulse or shock to the heart", UnitCost = 125000 }); serv.AddItem(new Item { Name = "Anesthesia Machine", Description = "For the purpose of inducing and maintaining anesthesia", UnitCost = 500000 }); serv.AddItem(new Item { Name = "Wheelchair", Description = "For easy transport of leg-impaired persons", UnitCost = 12500 }); serv.AddItem(new Item { Name = "Sterilized Blanket", Description = "Warms and comforts patients", UnitCost = 5000 }); }
public void Post([FromBody] ItemViewModel itemViewModel) { if (ModelState.IsValid) { _itemService.AddItem(itemViewModel); } }
protected void BtnSave_Click(object sender, EventArgs e) { using (var itemService = new ItemService()) { CurrentItem = new Item(); int itemId; int.TryParse(Request.QueryString["ItemId"], out itemId); CurrentItem.ItemId = itemId; CurrentItem.Name = txtName.Value; CurrentItem.Price = decimal.Parse(txtPrice.Value); CurrentItem.ItemTypeId = int.Parse(slcItemType.Value); CurrentItem.DefaultIncluded = chkDefaultIncluded.Checked; CurrentItem.MonthsPeriod = int.Parse(txtMonthsPeriod.Value); CurrentItem.ClientId = int.Parse(Request.Cookies["ClientId"].Value); if (CurrentItem.ItemId != 0) { itemService.UpdateItem(CurrentItem); } else { itemService.AddItem(CurrentItem); } } Response.RedirectPermanent(Request, "AllItems.aspx"); }
public async Task <IActionResult> Form(/*ItemAddVM userAddItemVM*/ Item item) { var currentUserID = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); await itemService.AddItem(item, currentUserID); return(Redirect("/lagga-till")); }
public void AddItem_ShowdThrowArgumenNullException_WhenItemIsNull() { // Arrange var itemService = new ItemService(this.dataMock.Object); // Act & Assert itemService.AddItem(null); }
public async Task AddItem_ValidObjectPassed_ReturnsSuccess() { // Arrange Contracts.Item item = new Contracts.Item { Name = "WiFi Router", Description = "On Sale", Price = 67, ImgUrl = string.Empty }; // Act var result = await _itemService.AddItem(item); // Assert Assert.True(result.isSuccess); Assert.NotNull(result); }
private void btnStart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (string.IsNullOrEmpty(ccbNick.Text)) { XtraMessageBox.Show("请选择店铺!"); return; } #region 买家自定义类目 //读取买家自定义类目列表中被选中的子节点 string sellercids = string.Empty; foreach (TreeListNode node in treeListSellerCat.Nodes) { if (node.HasChildren) { foreach (TreeListNode childNode in node.Nodes) { if (childNode.CheckState == CheckState.Checked) { sellercids += string.Format("{0},", childNode.Tag.ToString()); } } } else { if (node.CheckState == CheckState.Checked) { sellercids += string.Format("{0},", node.Tag.ToString()); } } } itemreq.SellerCids = sellercids.TrimEnd(','); #endregion /*在这里判断stockItem中是否存在此商品,不存在要生成一个*/ string session = SystemHelper.GetSessionKey(ccbNick.Text); ItemRsp addRsp = TopService.ItemAdd(session, itemreq); //上传成功执行 if (addRsp != null && addRsp.Item != null) { ItemRsp rsp = TopService.ItemGet(session, ccbNick.Text, addRsp.Item.Iid, null); Alading.Entity.Item item = new Alading.Entity.Item(); if (rsp.Item == null) { rsp.Item = itemreq as Taobao.Entity.Item; } UIHelper.ItemCopyData(item, rsp.Item); ItemService.AddItem(item); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } }
public ActionResult <Item> addItem(Item item) { var items = _service.AddItem(item); if (items == null) { return(NotFound()); } return(items); }
public void GivenFollowingItemsShouldBeAdded(IEnumerable <ItemFieldDefinition> items) { foreach (var item in items) { if (!ItemService.ItemExists(item)) { ItemService.AddItem(item); } } }
public async Task <ActionResult <Models.Public.Response.Item> > PostListItem([FromBody] Models.Public.Request.Item item) { var newItem = await _service.AddItem(item, getID()); if (newItem != null) { return(new CreatedResult("/api/item/" + newItem.itemID, newItem)); } return(BadRequest()); }
public IHttpActionResult PostItem(ItemDTO item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool result = Service.AddItem(item); return(CreatedAtRoute("DefaultApi", new { id = item.ID }, item)); }
public IActionResult Create(ItemViewModel item) { Item model = new Item(); model.Name = item.Name; model.Price = item.Price; model.Description = item.Description; model.Category = categoryService.Get(item.Category); itemService.AddItem(model); return(RedirectToAction("Index")); }
public void GivenAnItemDatabaseAndAnItem_WhenAddItem_ThenItemIsAddedToDatabase() { //Given ItemService itemService = new ItemService(); Item item = new Item("test", "test", 5.0, 3, 1); //When itemService.AddItem(item); //Then var actual = Database.Items.First(find => find.ID == item.ID); Assert.Equal(item, actual); }
public void GivenAnItemDatabase_WhenGetByID_ThenItemWithThatIDIsReturned() { //Given ItemService itemService = new ItemService(); Item item = new Item("test", "test", 5.0, 3, 1); itemService.AddItem(item); //When var actual = itemService.GetByID(item.ID); //Then Assert.Equal(item, actual); }
public void AddItemByNesseseryData_Test() { //Arrange var itemService = new ItemService(); itemService.AddItem(new Item(100)); //Act var output = itemService.AddItemByNesseseryData("", 1, 1, 1, 1, new Category("name", 1)); //Assert output.Should().NotBe(null); output.Should().Be(101); }
public void FindBrand_ShouldFoundBrand() { //Arrange var itemService = new ItemService(); Item item1 = new Item(1, "Polo", "Volkswagen", DateTime.Now); Item item2 = new Item(2, "Astra", "Opel", DateTime.Now); Item item3 = new Item(3, "Yaris", "Toyota", DateTime.Now); //Act itemService.AddItem(item1); itemService.AddItem(item2); itemService.AddItem(item3); var givenCarBrand = itemService.FindBrand("Toyota"); //Assert givenCarBrand.Should().NotBeNull(); Assert.Equal("Toyota", givenCarBrand); //Clear itemService.RemoveItem(item1); itemService.RemoveItem(item2); itemService.RemoveItem(item3); }
public void ShowAllGivenCars_ShouldShowAllItems() { //Arrange var itemService = new ItemService(); Item item1 = new Item(1, "Polo", "Volkswagen", DateTime.Now); Item item2 = new Item(2, "Up!", "Volkswagen", DateTime.Now); Item item3 = new Item(3, "Golf", "Volkswagen", DateTime.Now); //Act itemService.AddItem(item1); itemService.AddItem(item2); itemService.AddItem(item3); var allCarsList = itemService.ShowAllGivenCars(); //Assert allCarsList.Should().NotBeNull(); Assert.Equal(3, allCarsList.Count); //Clear itemService.RemoveItem(item1); itemService.RemoveItem(item2); itemService.RemoveItem(item3); }
public void UpdateItem_ShouldUpdateAndReturnUpdatedValue() { //Arrange var itemService = new ItemService(); Item item1 = new Item(1, "Polo", "Volkswagen", DateTime.Now); Item item2 = new Item(2, "Up!", "Volkswagen", DateTime.Now); //Act itemService.AddItem(item1); itemService.AddItem(item2); var itemToUpdate = itemService.UpdateItem(item1); var itemUpdated = itemService.GetItemById(itemToUpdate); itemUpdated = item2; //Assert Assert.Equal(item2.CarModel, itemUpdated.CarModel); //Clear itemService.RemoveItem(item1); itemService.RemoveItem(item2); }
public void AddItem_ShouldCallDataCommit_WhenValidItemIsPassed() { // Arrange var item = new Item(); this.dataMock.SetupGet(d => d.Items).Returns(this.itemRepoMock.Object); var itemService = new ItemService(this.dataMock.Object); // Act itemService.AddItem(item); // Assert this.dataMock.Verify(d => d.Commit(), Times.Once); }
protected async Task HandleValidSubmit() { var response = await ItemService.AddItem(ItemToAdd); if (response.IsSuccess) { ShowDialog = false; await CloseEventCallback.InvokeAsync(true); } else { this.Error.Show(response.ErrorMessage); } await InvokeAsync(StateHasChanged); }
public void AddNewItem() { var addNewItemMenu = _actionService.GetMenuActionsByName("AddNewItemMenu"); for (int i = 0; i < addNewItemMenu.Count; i++) { Console.WriteLine($"{addNewItemMenu[i].Id}. {addNewItemMenu[i].Name}"); } var operation = Console.ReadLine(); if (_itemService.IsUserInputCorrect(operation, addNewItemMenu.Count)) { Console.WriteLine("Given incorrect values"); } else { int carBrandChoosed; Int32.TryParse(operation, out carBrandChoosed); string carBrandChosed = addNewItemMenu[carBrandChoosed - 1].Name; Console.WriteLine(); Console.WriteLine("Please enter your car model"); var carModel = Console.ReadLine(); if (_itemService.IsUserInputCorrect(carModel)) { Console.WriteLine("Given incorrect values"); } else { Console.WriteLine("Please enter the city where the car is located"); string carLocation = Console.ReadLine(); if (_itemService.IsUserInputCorrect(carLocation)) { Console.WriteLine("Given incorrect values"); } else { var lastId = _itemService.GetLastId(); Item item = new Item(lastId + 1, carModel, carBrandChosed, DateTime.Now, carLocation); _itemService.AddItem(item); _dataService.SaveXMLData("xmlFile", _itemService.GetAllItems()); Console.WriteLine(); } } } }
public void AddNewItem_ShouldAddItemAndReturnId() { //Arrange var itemService = new ItemService(); Item item = new Item(1, "Polo", "Volkswagen", DateTime.Now); //Act var id = itemService.AddItem(item); var newItem = itemService.GetItemById(id); //Assert item.Id.Should().NotBe(null); newItem.Should().BeOfType(typeof(Item)); item.Id.Should().Be(id); //Clear itemService.RemoveItem(item); }
public void AddItemToList(string itemName, double price, string url, string picKey, Guid userID) { var item = itemService.GetItem(itemName); if (item == null) { Item newItem = new Item(itemName, price, url, picKey); itemService.AddItem(newItem); item = itemService.GetItem(itemName); } ItemList itemlist = new ItemList(userID, item.itemID); if (!itemlistService.AddItemList(itemlist)) { throw new AddFailedException("Failed to add item to list."); } }
public void Mojpierwszytest() { //Arrange Item item = new Item(150, "Cos", 20, 20, 20, 20, 2); var mock = new Mock <IService <Item> >(); mock.Setup(s => s.AddItem(item)).Returns(item.Id); var manager = new ItemService(); //Act int returnedItem = manager.AddItem(item); //Assert returnedItem.Should().Be(item.Id); returnedItem.Should().NotBe(null); }
void worker_DoWork(object sender, DoWorkEventArgs e) { ItemTask itemTask = e.Argument as ItemTask; List <string> iidlist = itemTask.iidList; BackgroundWorker worker = (BackgroundWorker)sender; int n = iidlist.Count; for (int i = 0; i < n; i++) { //完成数加1 itemCompleteNum++; if (isCancel) { e.Cancel = true; break; } string iid = iidlist[i]; ReturnType returntype = ItemService.IsItemExisted(iid); if (checkEditIsUpdate.CheckState != CheckState.Checked && returntype == ReturnType.PropertyExisted) { /*跳过本次下载*/ worker.ReportProgress(-2, string.Format("线程号{0},数据库已存在第{1}个宝贝,跳过下载", itemTask.threadIndex, i + 1)); continue; } string session = itemTask.sessionKey; string nick = itemTask.shopNic; try { ItemRsp myrsp = TopService.ItemGet(session, nick, iid, string.Empty); if (myrsp != null && myrsp.Item != null) { Alading.Entity.Item item = new Alading.Entity.Item(); UIHelper.ItemCopyData(item, myrsp.Item); ItemService.AddItem(item, checkEditIsUpdate.Checked); } else { if (failedDownload.iidList == null) { failedDownload.iidList = new List <string>(); } failedDownload.iidList.Add(iid); failedDownload.shopNick = nick; failedDownload.sessionKey = session; } //int progress = (int)((float)(i + 1) / (float)n * 100); worker.ReportProgress(itemCompleteNum, string.Format("{0}已成功下载第{1}个宝贝,线程号{2}", DateTime.Now.ToString(Constants.DATE_TIME_FORMAT), itemCompleteNum, itemTask.threadIndex)); } catch (System.Exception ex) { MyException myexc = new MyException(); myexc.position = i + 1; myexc.iid = iid; myexc.msg = ex.Message; myexc.threadIndex = itemTask.threadIndex; worker.ReportProgress(-1, myexc); if (failedDownload.iidList == null) { failedDownload.iidList = new List <string>(); } failedDownload.iidList.Add(iid); failedDownload.shopNick = nick; failedDownload.sessionKey = session; } } e.Result = itemTask.threadIndex; }
//Add new item method public void addNewItem() { String ItemName = textBox5.Text.ToString(); String ItemRate = textBox6.Text.ToString(); int rate = 0; int rflag = 0; if (fieldCheckForItemRate(ItemName, ItemRate)) { if (numberVerify(textBox6)) { rate = int.Parse(ItemRate); rflag = 1; } if (rflag == 1) { Item item = new Item(); item.Name = ItemName; item.Rating = rate; ItemService itemService = new ItemService(); Restaurant restaurant = new Restaurant(); restaurant.Name = name; restaurant.Location = location; RestaurantService restaurantService = new RestaurantService(); if (restaurantService.GetByLocation(restaurant) == "exist") { int RID = restaurantService.GetRID(restaurant); item.Rid = RID; if (itemService.GetByItemName(item) == "non-exist") { int IID = itemService.GetIID(); item.Iid = IID + 1; if (itemService.AddItem(item) == 1) { MessageBox.Show("Item Created and Rated Successfully!"); ratingsetDel.Invoke(name, location); } else { MessageBox.Show("Couldn't Create Item!"); } } else { MessageBox.Show("Item Already Exist!"); } } else { MessageBox.Show("Restaurant Doesn't Exist"); } } else { MessageBox.Show("Please check new item rate is given or not"); } } else { MessageBox.Show("Please check Item Name and Rate is filled or not"); } }
//Item add button recieves texts from ItemName, ItemRate and add to item table private void button2_Click(object sender, EventArgs e) { String name = RestaurantName.Text.ToString(); String location = RestaurantLocation.Text.ToString(); String IName = ItemName.Text.ToString(); String IRate = ItemRate.Text.ToString(); int rate = 0; int rflag = 0; if (fieldCheckForItem(name, location, IName, IRate)) { if (RateVerify(ItemRate)) { rate = int.Parse(IRate); rflag = 1; } if (rflag == 1) { Item item = new Item(); item.Name = IName; item.Rating = rate; ItemService itemService = new ItemService(); Restaurant restaurant = new Restaurant(); restaurant.Name = name; restaurant.Location = location; RestaurantService restaurantService = new RestaurantService(); if (restaurantService.GetByLocation(restaurant) == "exist") { int RID = restaurantService.GetRID(restaurant); item.Rid = RID; if (itemService.GetByItemName(item) == "non-exist") { int IID = itemService.GetIID(); item.Iid = IID + 1; if (itemService.AddItem(item) == 1) { MessageBox.Show("Item Added Successfully!"); LoadItem(item.Rid); } else { MessageBox.Show("Couldn't Add Item!"); } } else if (itemService.GetByItemName(item) == "exist") { MessageBox.Show("Item Already Exist!"); } } else { MessageBox.Show("Restaurant Doesn't Exist"); } } else { MessageBox.Show("Please check new item rate is given or not"); } } else { MessageBox.Show("Please check restaurant Name, Location, Item Name and Rate is filled or not"); } }
public void AddItem(Item item) { Items.Add(item); //ObservableCollection _itemService.AddItem(item); }
void worker_DoWork(object sender, DoWorkEventArgs e) { ItemTask itemTask = e.Argument as ItemTask; List <Taobao.Entity.Item> items = itemTask.ItemList; BackgroundWorker worker = (BackgroundWorker)sender; int totalCount = itemTask.totalCount; for (int i = 0; i < items.Count; i++) { lock (lockObject) { //进度递增 progressCurrent++; } if (worker.CancellationPending) { e.Cancel = true; break; } try { ItemRsp myrsp = TopService.ItemGet(SystemHelper.GetSessionKey(items[i].Nick), items[i].Nick, items[i].Iid, string.Empty); if (myrsp != null && myrsp.Item != null) { Alading.Entity.Item item = new Alading.Entity.Item(); UIHelper.ItemCopyData(item, myrsp.Item); //添加到数据库,如果存在则更新,否则添加 ReturnType result = ItemService.AddItem(item); //计算进度条值 int progress = (int)((float)progressCurrent / (float)totalCount * 100); if (result == ReturnType.Success) { UserState state = new UserState(); state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; state.Message = "下载成功!"; worker.ReportProgress(progress, state); } else { UserState state = new UserState(); state.Message = "数据库存储发生错误。"; state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; //发生数据库错误的报告 worker.ReportProgress(-1, state); } } } catch (Exception ex) { UserState state = new UserState(); state.Message = ex.Message; state.Index = i + 1; state.Iid = items[i].Iid; state.ItemTaskIndex = itemTask.Index; //发生下载错误的报告 worker.ReportProgress(-1, state); } } e.Result = itemTask.Index; }