示例#1
0
        private void CreateCorrectTestData()
        {
            var data          = GenerateData();
            var dataWords     = GenerateDataWords();
            var dataUserWords = GenerateDataUserWords();
            var _rep          = new Mock <IUserDictionaryRepository>();

            _rep.Setup(x => x.Add(It.IsAny <int>(), It.IsAny <UserWord>()))
            .Returns(true);
            _rep.Setup(x => x.Delete(It.IsAny <int>(), It.IsAny <int>()))
            .Returns <int, int>((id, x) => x);
            _rep.Setup(x => x.GetUserDictionary(It.IsAny <int>()))
            .Returns <int>(id => new UserDictionary
            {
                User  = data.FirstOrDefault(x => x.Id == id),
                Words = dataWords.Where(x => x.WordId == dataUserWords.FirstOrDefault(y => y.UserId == id).WordId)
            });
            _rep.Setup(x => x.GetAllCategories(It.IsAny <int>())).Returns(dataWords.GroupBy(x => x.Category).Select(x => x.Key));
            _rep.Setup(x => x.GetByCategory(It.IsAny <int>(), It.IsAny <string>()))
            .Returns <int, string>((id, str) => new UserDictionary
            {
                User  = data.FirstOrDefault(x => x.Id == id),
                Words = dataWords.Where(x => x.WordId == dataUserWords.FirstOrDefault(y => y.UserId == id).WordId&& x.Category.Equals(str))
            });
            service = new UserDictionaryService(_rep.Object);
            rep     = _rep.Object;
        }
示例#2
0
        private void CreateCorrectTestData()
        {
            var data = GenerateData();

            context = new Mock <EFDbContext>();
            var mockSet = new Mock <DbSet <UserWord> >();

            mockSet.As <IQueryable <UserWord> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <UserWord> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <UserWord> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <UserWord> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator());
            context.Setup(x => x.Set <UserWord>()).Returns(mockSet.Object);
            rep = new UserDictionaryRepository(context.Object);
        }
 public UserDictionaryService(IUserDictionaryRepository _rep)
 {
     rep = _rep;
 }