当前位置: 首页>>代码示例>>C#>>正文


C# GenericRepository.GetById方法代码示例

本文整理汇总了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));
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:12,代码来源:GenericRepositoryTests.cs

示例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);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:23,代码来源:RepositoeisTest.cs

示例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);
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:14,代码来源:GenericRepositoryTests.cs

示例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));
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:12,代码来源:GenericRepositoryTests.cs

示例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));
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:13,代码来源:GenericRepositoryTests.cs

示例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);
        }
开发者ID:sashaalex67,项目名称:CityTravel,代码行数:13,代码来源:GenericRepositoryTests.cs

示例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);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:25,代码来源:RepositoeisTest.cs

示例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);
        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:28,代码来源:RepositoeisTest.cs

示例9: DeleteMovieWhenNotExistShouldThrowException

        public void DeleteMovieWhenNotExistShouldThrowException()
        {
            //Arrange -> prepare the objects
            var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
            var movie = repo.GetById(234);
            repo.Delete(movie);

        }
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:8,代码来源:RepositoeisTest.cs


注:本文中的GenericRepository.GetById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。