本文整理汇总了C#中GenericRepository.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository.Delete方法的具体用法?C# GenericRepository.Delete怎么用?C# GenericRepository.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericRepository
的用法示例。
在下文中一共展示了GenericRepository.Delete方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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);
//}
}
示例2: DoObsolete
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
});
}
}
示例3: DeleteNews_Should_Throw_Exeption_If_Object_Of_Deletion_Is_Invalid
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();
}
示例4: DeleteNews_Should_Successfully_Delete_Object_If_It_Exists
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();
}
示例5: Delete_Existing_Id_MUST_Delete
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);
}
示例6: Update_UnExisting_Object_Must_NOT_Update
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);
}
示例7: Delete_NULL_Object_Must_NOT_Delete
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);
}
示例8: Can_Remove_Entity_By_Predicate
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));
}
示例9: Can_Remove_Entity_By_It_Specifying
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));
}
示例10: DeleteMovieWhenExistingItemShouldDelete
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);
}
示例11: DeleteMovieWhenNotExistShouldThrowException
public void DeleteMovieWhenNotExistShouldThrowException()
{
//Arrange -> prepare the objects
var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
var movie = repo.GetById(234);
repo.Delete(movie);
}