public void Repository_Add()
        {
            var post = new Post {
                Id = 6
            };

            _postRepository.Add(post);
            _codingSoldierDbContext.Set <Post>().Received().Add(post);
            _codingSoldierDbContext.Received().SaveChanges();
        }
        public RepositoryTests()
        {
            var data  = GetPosts();
            var posts = Substitute.For <DbSet <Post>, IQueryable <Post> >();

            (posts as IQueryable).Provider.Returns(data.Provider);
            (posts as IQueryable).Expression.Returns(data.Expression);
            (posts as IQueryable).ElementType.Returns(data.ElementType);
            (posts as IQueryable).GetEnumerator().Returns(data.GetEnumerator());

            Database.SetInitializer <CodingSoldierDbContext>(null);
            _codingSoldierDbContext = Substitute.For <CodingSoldierDbContext>();
            _codingSoldierDbContext.Set <Post>().Returns(posts);

            _postRepository = new Repository <Post>(_codingSoldierDbContext);
        }
Beispiel #3
0
 public void Add(T item)
 {
     _dbContext.Set <T>().Add(item);
     _dbContext.SaveChanges();
 }