public void Delete_ShouldRemoveItemWithId1_ShouldNowHaveCountTwo() { // act _genericRepository.Delete(1); // assert _data.Should().HaveCount(2); }
/// <summary> /// <see cref="IFunctionalService.Unbind(string)"/> /// </summary> public virtual void Unbind(string ownerId) { bindings.Delete(bindings.Retrieve(new SifObjectBinding() { OwnerId = ownerId })); log.Info("Unbound all objects from the session token " + ownerId); }
public void DeleteNotiObjectById(int nObjectId) { NotificationObject nChange = notificationObjectRepository.FindById(nObjectId); if (nChange != null) { notificationObjectRepository.Delete(nChange); } }
public void DeleteNotiChangeById(int notiChangeId) { NotificationChange nChange = findNotificationChange(notiChangeId); if (nChange != null) { notificationChangeRepository.Delete(nChange); } }
public async Task DeleteByIdDetachedTest() { var entity = _DbContext.Set <Race>().Find(_Ids[0]); _DbContext.Entry(entity).State = EntityState.Detached; _DbContext.SaveChanges(); _Sut.Delete(entity); _DbContext.SaveChanges(); Assert.IsFalse(await _DbContext.Races.AnyAsync(r => r.RaceId == _Ids[0])); }
public string MesajSil(int id) { try { msjj.Delete(id); return("1"); } catch (Exception) { return("-1"); } }
public string TeklifSil(int id) { try { tek.Delete(id); return("1"); } catch (Exception) { return("-1"); } }
public virtual async Task <ResultStatus> Delete(int Id) { ResultStatus resultStatus = new ResultStatus(); resultStatus.IsSuccessed = true; resultStatus.Type = MessageType.Success; try { T model = await genericRepository.GetByIdAsync(Id); if (model != null) { genericRepository.Delete(model); await genericRepository.SaveAsync(); } else { resultStatus.IsSuccessed = false; resultStatus.Message = "رکورد یافت نشد"; resultStatus.Type = MessageType.Warning; } return(resultStatus); } catch (Exception exception) { resultStatus.IsSuccessed = false; resultStatus.Message = "خطایی رخ داده است"; resultStatus.Type = MessageType.Danger; resultStatus.ErrorException = exception; return(resultStatus); } }
public virtual void Delete(int id) { var modelToDelete = _repo.Read(x => x.Id == id).FirstOrDefault(); _repo.Delete(modelToDelete); _repo.Save(); }
public void ASaveTest() { Questions TestQuestion = new Questions { Question = "SaveTestQuestion?", TimeQuestion = DateTime.Now, UserName = "******", UserMail = "*****@*****.**" }; GenericRepository <Questions> RepQ = new GenericRepository <Questions>(); RepQ.Add(TestQuestion); RepQ.Save(); Answers TestAnswer = new Answers { Answer = "SaveTestAnswer", TimeAnswer = DateTime.Now, IdQuestions = TestQuestion.Id }; GenericRepository <Answers> RepA = new GenericRepository <Answers>(); RepA.Add(TestAnswer); int x = RepA.GetAll().Where(item => item.Answer == "SaveTestAnswer").Count(); Assert.AreEqual(x, 0); RepA.Save(); x = RepA.GetAll().Where(item => item.Answer == "SaveTestAnswer").Count(); Assert.AreEqual(x, 1); RepA.Delete(TestAnswer); x = RepA.GetAll().Where(item => item.Answer == "SaveTestAnswer").Count(); Assert.AreEqual(x, 1); RepA.Save(); x = RepA.GetAll().Where(item => item.Answer == "SaveTestAnswer").Count(); Assert.AreEqual(x, 0); RepQ.Delete(TestQuestion); RepQ.Save(); }
public JsonResult RemoveSupplier(int id) { supplierrepo.Delete(id); return(Json("İşlem başarılı", JsonRequestBehavior.AllowGet)); }
public void AGetAllTest() { Questions TestQuestion = new Questions { Question = "GetAllTestQuestion?", TimeQuestion = DateTime.Now, UserName = "******", UserMail = "*****@*****.**" }; GenericRepository <Questions> RepQ = new GenericRepository <Questions>(); RepQ.Add(TestQuestion); RepQ.Save(); Answers TestAnswer = new Answers { Answer = "GetAllTestAnswer", TimeAnswer = DateTime.Now, IdQuestions = TestQuestion.Id }; GenericRepository <Answers> RepA = new GenericRepository <Answers>(); int x = RepA.GetAll().Count(); RepA.Add(TestAnswer); RepA.Save(); Assert.IsTrue(RepA.GetAll().Count() > x); RepA.Delete(TestAnswer); RepA.Save(); RepQ.Delete(TestQuestion); RepQ.Save(); }
public void DeleteTest() { IGenericRepository <Employee> dept = new GenericRepository <Employee>(); dept.Delete(4); dept.Save(); }
public ActionResult Delete(int?id) { try { var productId = _product.GetById(id); var checkExitOrder = _orderDetail.GetBy(x => x.ProductId == productId.Id); if (checkExitOrder == null) { if (_product.Delete(id)) { TempData["DeleteSuccess"] = "Delete Success"; return(RedirectToAction("Index")); } TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } catch (Exception) { TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } }
public JObject DeleteSubject(Materia materia) { var JObject = new JObject(); try { var matter = repositorio.GetByID(materia.IdMateria); if (matter != null) { var idMatter = materia.IdMateria; repositorio.Delete(matter); repositorio.Save(); JObject["Codigo"] = "0000"; JObject["Descripcion"] = idMatter; return(JObject); } else { JObject["Codigo"] = "0100"; JObject["Descripcion"] = "La materia no existe"; return(JObject); } } catch (Exception e) { var CodigoError = new ErrorCode(); var error = CodigoError.Error(e.ToString()); JObject["Codigo"] = error; JObject["Descripcion"] = e.ToString(); return(JObject); } }
public ActionResult DeleteSkill(int id) { var skill = repo.Find(x => x.ID == id); repo.Delete(skill); return(RedirectToAction("Index")); }
public JObject DeleteStudent(Alumno alumno) { var JObject = new JObject(); try { var student = repositorio.GetByID(alumno.IdAlumno); if (student != null) { var idStudent = alumno.IdAlumno; repositorio.Delete(student); repositorio.Save(); JObject["Codigo"] = "0000"; JObject["Descripcion"] = idStudent; return(JObject); } else { JObject["Codigo"] = "0100"; JObject["Descripcion"] = "No se encontro alumno"; return(JObject); } } catch (Exception e) { var CodigoError = new ErrorCode(); var error = CodigoError.Error(e.ToString()); JObject["Codigo"] = error; JObject["Descripcion"] = e.ToString(); return(JObject); } }
//delete House public void deleteHouse(int Id) { House deleteHouse = new House(); deleteHouse.Id = Id; allHouseInfo.Delete(allHouseInfo.FindById(deleteHouse.Id)); }
static void Main(string[] args) { var contactsRepository = new GenericRepository<Contact>(); contactsRepository.Delete(5); //for (int i = 0; i < 1000; i++) //{ // var currentContact = new Contact(); // currentContact.FirstName = "ContactFirstName" + i; // currentContact.LastName = "ContactLastName" + i; // if (i % 3 == 0) // { // currentContact.Sex = Sex.Male; // currentContact.Status = Status.Active; // } // else if (i % 3 == 1) // { // currentContact.Sex = Sex.Female; // currentContact.Status = Status.Inactive; // } // else // { // currentContact.Sex = Sex.Other; // currentContact.Status = Status.Deleted; // } // Random rand = new Random(); // currentContact.Telephone = rand.Next(1000000000, 2000000000).ToString(); // contactsRepository.Add(currentContact); //} }
public ActionResult Delete(int?id) { try { var attributeId = _attribute.GetById(id); var checkExitProduct = _productAttribute.GetBy(x => x.AttributeId == attributeId.Id); if (checkExitProduct == null) { if (_attribute.Delete(id)) { TempData["DeleteSuccess"] = "Delete Success"; return(RedirectToAction("Index")); } TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } catch (Exception) { TempData["DeleteFalse"] = "Delete False"; return(RedirectToAction("Index")); } }
public ActionResult DeleteCertificate(int id) { var selectedItem = repo.Find(x => x.ID == id); repo.Delete(selectedItem); return(RedirectToAction("Index")); }
public List <BodyBasicIndex> Del(BodyBasicIndex_VM _VM) { GenericRepository _repository = new GenericRepository(); BodyBasicIndex model = new BodyBasicIndex() { ID = _VM.ID, BMI = _VM.BMI, Date = _VM.Date, BodyFat = _VM.BodyFat, Height = _repository.GetT(_VM.ID).Height, SkeletalMuscleRate = _VM.SkeletalMuscleRate, VisceralFat = _VM.VisceralFat, Weight = _VM.Weight }; _repository.Delete(model); List <BodyBasicIndex> result = new List <BodyBasicIndex>(); //result.Add(_repository.GetT(model.ID, model.Date)); return(result); }
public virtual string Update(RegularOrder order, Collection <OrderItem> orderItems) { string result = string.Empty; AppLogger.logInfo(this.ToString(), "Begin updating order."); try { Repository.Update(order); if (UseAuditTrail) { LogAuditTrail(order, Constants.UPDATE_ACTION); } GenericRepository <OrderItem> orderItemRepository = new GenericRepository <OrderItem>(Repository.Context); // Clears all order items in the order and insert the new order items orderItemRepository.Delete(o => o.order_id.Equals(order.id)); orderItemRepository.Insert(orderItems); Repository.Commit(); } catch (Exception ex) { AppLogger.logError(this.ToString(), string.Format("Error occurs while updating order [{0}].", order.id), ex); Repository.Rollback(); result = Constants.Messages.CREATE_ORDER_ERROR_MESSAGE; } AppLogger.logInfo(this.ToString(), "Finish updating order."); return(result); }
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { int roleID = GetSelectedDataKeyID(Grid1); if (e.CommandName == "Delete") { // 在操作之前进行权限检查 if (DB.PermissionRoles.Find(roleID).ForbidDelete) { Alert.ShowInTop("系统必须的角色, 不能删除"); return; } int userCountUnderThisRole = DB.Users.Where(u => u.UserPermissionRoles.Any(r => r.ID == roleID)).Count(); if (userCountUnderThisRole > 0) { Alert.ShowInTop("删除失败!需要先清空属于此角色的用户!"); return; } // 执行数据库操作 //DB.PermissionRoles.Where(item => item.ID == roleID).Delete<PermissionRole>(); PermissionRole permissionRole = DB.PermissionRoles.Where(item => item.ID == roleID).FirstOrDefault(); GenericRepository <PermissionRole> repository = UnitOfWork.Repository <PermissionRole>(); if (!repository.Delete(permissionRole, out msg)) { Alert.ShowInTop("删除失败!"); } BindGrid(); } }
public void DeletesEntity_When_InvokedWithCorrectValues() { var context = new BookstoreContext(Effort.DbConnectionFactory.CreateTransient()); var countryRepository = new GenericRepository <Author>(context); var author = new Author() { AuthorName = "gosho", Id = 1 }; var country1 = new Author() { AuthorName = "gosho1" }; context.Authors.Add(author); context.SaveChanges(); context.Authors.Add(country1); context.SaveChanges(); countryRepository.Delete(author); context.SaveChanges(); Assert.AreEqual(1, context.Authors.Count()); }
public void Delete_CalledWithDetachedEntity_RemoveCalledAfterAttach() { _mockAppointment = new Mock <DbSet <Appointment> >(); var appointment = new Appointment() { Id = 1 }; _mockAppointment.SetSource(new[] { appointment }); _mockAppointment.Setup(a => a.Find(appointment.Id)).Returns(appointment); _mockAppointment.Setup(a => a.Attach(appointment)).Returns(appointment); _mockAppointment.Setup(a => a.Remove(appointment)).Returns(appointment); _mockContext = new Mock <IApplicationDbContext>(); _mockContext.Setup(c => c.GetEntityState(appointment)).Returns(EntityState.Detached); _mockContext.Setup(c => c.Set <Appointment>()).Returns(_mockAppointment.Object); _repository = new AppointmentRepository(_mockContext.Object); _repository.Delete(appointment); _mockContext.Verify(c => c.GetEntityState(appointment), Times.Once); _mockAppointment.Verify(c => c.Attach(appointment), Times.Once); _mockAppointment.Verify(c => c.Remove(appointment), Times.Once); }
public JObject DeleteScore(Notas notas) { var JObject = new JObject(); try { var score = repositorio.GetByID(notas.IdNota); if (score != null) { var idScore = notas.IdNota; repositorio.Delete(score); repositorio.Save(); JObject["Codigo"] = "0000"; JObject["Descripcion"] = idScore; return(JObject); } else { JObject["Codigo"] = "0100"; JObject["Descripcion"] = "No existen notas"; return(JObject); } } catch (Exception e) { var CodigoError = new ErrorCode(); var error = CodigoError.Error(e.ToString()); JObject["Codigo"] = error; JObject["Descripcion"] = e.ToString(); return(JObject); } }
public void Delete_ShouldRemoveEntityFromDb() { this.options = new DbContextOptionsBuilder <TwitterContext>() .UseInMemoryDatabase(databaseName: "Delete_ShouldRemoveEntityFromDb") .Options; var tweetId = "12349891273482342"; var tweet = new Tweet { Id = tweetId, Content = "some_content", CreatedOn = DateTime.Now, TwitterId = "1234892374972234", TwitterScreenName = "Trump", }; using (this.context = new TwitterContext(this.options)) { this.context.Tweets.Add(tweet); this.context.SaveChanges(); var tweetRepository = new GenericRepository <Tweet, string>(this.context); tweetRepository.Delete(tweet); this.context.SaveChanges(); } using (this.context = new TwitterContext(this.options)) { var actual = this.context.Tweets.Find(tweetId); Assert.That(actual, Is.Null); } }
public void DeleteIncludAllTable() { var option = new DbContextOptionsBuilder <PermaContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryContext = new PermaContext(option)) { //Act GenericRepository <Location> locationRepository = new GenericRepository <Location>(memoryContext); GenericRepository <Site> siteRepository = new GenericRepository <Site>(memoryContext); //Arrang Location location = new Location { City = "bxl", Number = "20", Street = "Av. Sloubie", Zipcode = "1000" }; Site site = new Site { Location = location, Name = "Kaamelott", Phone = "047852948" }; locationRepository.Insert(location); siteRepository.Insert(site); memoryContext.SaveChanges(); //Assert var testLocation = locationRepository.GetByID(location.Id); var testSite = siteRepository.GetByID(site.Id); //siteRepository.Delete(site.Id); locationRepository.Delete(location.Id); memoryContext.SaveChanges(); //Assert.AreEqual(siteRepository.Get().Count(),0); //Assert.AreEqual(locationRepository.Get().Count(), 0); Assert.AreEqual(locationRepository.Get().Count(), 0); } }
public static ResultModel DeleteAuthor(BaseRequest request) { if (request.Id > 0) { try { GenericRepository.Delete <Author>(request.Id); return(new ResultModel { Data = null, Status = ResultStatus.Success, Message = "Başarılı bir şekilde silindi" }); } catch (Exception ex) { return(new ResultModel { Data = null, Status = ResultStatus.ServerInternalError, Message = "Hata oluştu" }); } } else { return new ResultModel { Data = null, Status = ResultStatus.BadRequest, Message = "Geçersiz değer" } }; }
public void Delete() { int count = repo.GetAll().Count(); repo.Delete(count); Category result = repo.Get(count); Assert.IsNull(result); }
public ActionResult DoObsolete(int id) { try { var repository = new GenericRepository<Media>(Db); var model = repository.FindById(id); if (model == null) { return Json(new ResponseMessageModel { HasError = false, Title = ResShared.TITLE_OBSOLETE_FAILED, Message = ResShared.ERROR_MODEL_NOTFOUND }); } repository.Delete(model); return Json(new ResponseMessageModel { HasError = false, Title = ResShared.TITLE_OBSOLETE_SUCCESS, Message = ResShared.INFO_REGISTER_DELETED }); } catch (Exception ex) { SharedLogger.LogError(ex, id); return Json(new ResponseMessageModel { HasError = true, Title = ResShared.TITLE_OBSOLETE_FAILED, Message = ResShared.ERROR_REGISTER_CANNOT_DELETE }); } }
public void DeleteMovieWhenNotExistShouldThrowException() { //Arrange -> prepare the objects var repo = new GenericRepository<Movie>(new MoviesGalleryContext()); var movie = repo.GetById(234); repo.Delete(movie); }
public void DeleteNews_Should_Throw_Exeption_If_Object_Of_Deletion_Is_Invalid() { var repository = new GenericRepository<News>(new NewsContext()); var newsToDelete = new News { Title = "Update aaa", Content = "Update aaa", PublishDate = DateTime.Now }; repository.Delete(newsToDelete); repository.SaveChanges(); }
public void DeleteNews_Should_Successfully_Delete_Object_If_It_Exists() { var repository = new GenericRepository<News>(new NewsContext()); var newsModel = repository.All().FirstOrDefault(); if (newsModel == null) { Assert.Fail("Cannot perform test - Unable to delete unexisting object."); } repository.Delete(newsModel); repository.SaveChanges(); }
public void DeleteMovieWhenExistingItemShouldDelete() { //Arrange -> prepare the objects var repo = new GenericRepository<Movie>(new MoviesGalleryContext()); var movie = new Movie() { Id = 1, Length = 10, Ration = 10 }; //Act -> perform some logic repo.Add(movie); repo.SaveChanges(); var movieFromDb = repo.GetById(movie.Id); repo.Delete(movieFromDb); repo.SaveChanges(); var newMovieFromDb = repo.GetById(movie.Id); //Asssert -> expect and exception Assert.IsNull(newMovieFromDb); }
public void Can_Remove_Entity_By_It_Specifying() { // Arrange var routesRepository = new GenericRepository<Route>(this.dataBaseContext); var entityToDelete = routesRepository.GetById(2); // Act routesRepository.Delete(entityToDelete); // Assert Assert.AreEqual(1, routesRepository.Count); Assert.AreEqual(null, routesRepository.GetById(2)); }
public void Can_Remove_Entity_By_Predicate() { // Arrange var routesRepository = new GenericRepository<Route>(this.dataBaseContext); // Act routesRepository.Delete(x => x.Id == 2); // Assert Assert.AreEqual(1, routesRepository.Count); Assert.AreEqual(null, routesRepository.GetById(2)); }
public void Delete_Existing_Id_MUST_Delete() { // // Arrange // var mockModel = new Mock<IModel>(); var mockDbSet = new Mock<DbSet<IModel>>(); mockDbSet.Setup(x => x.Find(It.IsAny<object[]>())).Returns<object[]>(x => { return mockModel.Object; }); var mockContext = new Mock<EFDbContext>(); mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object); mockContext.Setup(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>())).Callback<object, RecordState>((obj, state) => { return; }); var repository = new GenericRepository<IModel>(mockContext.Object); // // Act // repository.Delete(1); // // Assert // mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Once); }
public void Update_UnExisting_Object_Must_NOT_Update() { // // Arrange // var mockModel = new Mock<IModel>(); var mockDbSet = new Mock<DbSet<IModel>>(); mockDbSet.Setup(x => x.Find(It.IsAny<object[]>())).Returns<object[]>(x => { return null; }); var mockContext = new Mock<EFDbContext>(); mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object); var repository = new GenericRepository<IModel>(mockContext.Object); // // Act // repository.Delete(mockModel.Object); // // Assert // mockDbSet.Verify(x => x.Find(It.IsAny<object[]>()), Times.Once); mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Never); }
public void Delete_NULL_Object_Must_NOT_Delete() { // // Arrange // var mockDbSet = new Mock<DbSet<IModel>>(); var mockContext = new Mock<EFDbContext>(); mockContext.Setup(x => x.Set<IModel>()).Returns(mockDbSet.Object); var repository = new GenericRepository<IModel>(mockContext.Object); // // Act // repository.Delete(null); // // Assert // mockContext.Verify(x => x.ChangeState(It.IsAny<object>(), It.IsAny<RecordState>()), Times.Never); }