本文整理汇总了C#中GenericRepository.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository.GetById方法的具体用法?C# GenericRepository.GetById怎么用?C# GenericRepository.GetById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericRepository
的用法示例。
在下文中一共展示了GenericRepository.GetById方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Add_New_Entity
public void Can_Add_New_Entity()
{
// Arrange
var routesRepository = new GenericRepository<Route>(this.dataBaseContext);
// Act
routesRepository.Add(new Route { Id = 4, Name = "newRoute" });
// Assert
Assert.AreEqual(2, routesRepository.Count);
Assert.AreNotEqual(null, routesRepository.GetById(1));
}
示例2: AddMovieWhenMovieIsAddedToDbShouldReturnMovie
public void AddMovieWhenMovieIsAddedToDbShouldReturnMovie()
{
//Arange -> prepare the objects
var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
var movie = new Movie()
{
Id = 1,
Length = 1,
Ration = 3
};
//Act -> perform some logic
repo.Add(movie);
repo.SaveChanges();
//Assert -> validate the results
var movieFromDb = repo.GetById(movie.Id);
Assert.IsNotNull(movieFromDb);
Assert.AreEqual(movie.Length, movieFromDb.Length);
Assert.AreEqual(movie.Ration, movieFromDb.Ration);
Assert.IsTrue(movieFromDb.Id != 0);
}
示例3: Can_Update_Entity
public void Can_Update_Entity()
{
// Arrange
var routesRepository = new GenericRepository<Route>(this.dataBaseContext);
var entityToUpdate = routesRepository.GetById(1);
entityToUpdate.Name = "Updated";
// Act
routesRepository.Update(entityToUpdate);
// Assert
Assert.AreEqual(1, routesRepository.Count);
Assert.AreEqual("Updated", routesRepository.GetById(1).Name);
}
示例4: 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));
}
示例5: 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));
}
示例6: Can_Get_Entity_By_Specified_Id
public void Can_Get_Entity_By_Specified_Id()
{
// Arrange
var routesRepository = new GenericRepository<Route>(this.dataBaseContext);
// Act
var resultNormal = routesRepository.GetById(1);
var resultFailure = routesRepository.GetById(100);
// Assert
Assert.AreNotEqual(null, resultNormal);
Assert.AreEqual(null, resultFailure);
}
示例7: 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);
}
示例8: ModifyMovieWhenExistingItemShouldModify
public void ModifyMovieWhenExistingItemShouldModify()
{
//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();
movie.Length = 2;
movie.Ration = 7;
repo.Update(movie);
repo.SaveChanges();
var movieFromDb = repo.GetById(movie.Id);
Assert.IsNotNull(movieFromDb);
Assert.AreEqual(2, movieFromDb.Length);
Assert.AreEqual(7, movieFromDb.Ration);
Assert.IsTrue(movieFromDb.Id != 0);
}
示例9: DeleteMovieWhenNotExistShouldThrowException
public void DeleteMovieWhenNotExistShouldThrowException()
{
//Arrange -> prepare the objects
var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
var movie = repo.GetById(234);
repo.Delete(movie);
}