예제 #1
0
 public DbContext(
     IGenericBase <User> _user,
     IGenericBase <Genre> _genre,
     IGenericBase <Novel> _novel,
     IGenericBase <NovelChapter> _novelChapter,
     IGenericBase <NovelGenre> _novelGenre
     )
 {
     User         = _user;
     Genre        = _genre;
     Novel        = _novel;
     NovelChapter = _novelChapter;
     NovelGenre   = _novelGenre;
 }
        public MockGenericDataAccess(IEnumerable <T> data)
        {
            _data = data.ToList();
            _moqDataAccess.Setup(m => m.GetSingleFilteredByAsync(It.IsAny <Expression <Func <T, bool> > >()))
            .Returns((Expression <Func <T, bool> > condition) => Task.FromResult(_data.FirstOrDefault(condition.Compile())));

            _moqDataAccess.Setup(m => m.All()).Returns(Task.FromResult(_data.AsEnumerable()));

            _moqDataAccess.Setup(m => m.Insert(It.IsAny <T>())).Returns((T forInsert) =>
            {
                _data.Add(forInsert);
                return(Task.FromResult(new Result()
                {
                    IsSuccess = true, Message = "Inserted"
                }));
            });

            _moqDataAccess.Setup(m => m.GetAllFilteredBy(It.IsAny <Expression <Func <T, bool> > >()))
            .Returns((Expression <Func <T, bool> > condition) => Task.FromResult(_data.Where(condition.Compile()).ToList()));

            DataAccess = _moqDataAccess.Object;
        }