public void IsStudentWord_False()
        {
            //Arrange
            WordProgress _wordProgress = new WordProgress
            {
                IsStudentWord = false,
                Progress = 0,
                WordSuite = null,
                WordSuiteId = 3,
                WordTranslation = null,
                WordTranslationId = 3

            };

            IQueryable<WordProgress> _queryable = new List<WordProgress>
            {
               _wordProgress
            }.AsQueryable();
            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);

            //Act
            var result = new WordProgressService(_factory.Object).IsStudentWord(_wordProgress);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Once);
            _uow.Verify(u => u.WordProgressRepository, Times.Once);
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(1));
            Assert.IsFalse(result, "IsNotStudentWord");

        }
예제 #2
0
 public bool IsStudentWord(WordProgress wordProgress)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         return context
                 .WordProgresses
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord;
     }
 }
 public bool IsStudentWord(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         return uow
                 .WordProgressRepository.GetAll()
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord;
     }
 }
예제 #4
0
 public bool RemoveByStudent(WordProgress wordProgress)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         if (IsStudentWord(wordProgress))
         {
             context
             .WordProgresses
             .Remove(context
                 .WordProgresses
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId));
             context.SaveChanges();
             return true;
         }
         return false;
     }
 }
 public bool RemoveByStudent(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         if (IsStudentWord(wordProgress))
         {
             uow
             .WordProgressRepository
             .Delete(uow
                 .WordProgressRepository.GetAll()
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId));
             uow.Save();
             return true;
         }
         return false;
     }
 }
        public void IncrementProgress_True()
        {
            //Arrange
            WordProgress _wordProgress = new WordProgress()
            {
                IsStudentWord = false,
                Progress = 4,
                WordSuite = null,
                WordSuiteId = 3,
                WordTranslation = null,
                WordTranslationId = 3

            };
            IQueryable<WordProgress> _queryable = new List<WordProgress>
            {
               _wordProgress
            }.AsQueryable();

            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);
            _progressRepository.Setup(p => p.AddOrUpdate(_wordProgress));
            _uow.Setup(u => u.Save());

            //Act
            var result = new WordProgressService(_factory.Object).IncrementProgress(_wordProgress.WordSuiteId, _wordProgress.WordTranslationId);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Once);
            _uow.Verify(u => u.WordProgressRepository, Times.Exactly(2));
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(1));
            _progressRepository.Verify(p => p.AddOrUpdate(_wordProgress), Times.Exactly(1));
            _uow.Verify(u => u.Save(), Times.Once);
            //if IncrementProgress returns true, _wordProgress.Progress=4+1=5
            Assert.AreEqual(_wordProgress.Progress, 5);
            Assert.IsTrue(result, "true");

        }
        public void RemoveByStudent_False()
        {
            //Arrange
            var _wordProgress = new WordProgress()
            {
                IsStudentWord = false,
                WordSuiteId = 5,
                WordTranslationId = 5
            };
            IQueryable<WordProgress> _queryable = new List<WordProgress>
            {
               _wordProgress
            }.AsQueryable();
            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);
            _progressRepository.Setup(p => p.Delete(It.IsAny<WordProgress>()));
            _uow.Setup(u => u.Save());

            //Act
            var result = new WordProgressService(_factory.Object).RemoveByStudent(_wordProgress);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Exactly(2));
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(1));
            _progressRepository.Verify(p => p.Delete(_wordProgress), Times.Exactly(0));
            _uow.Verify(u => u.Save(), Times.Never);
            Assert.IsFalse(result, "false");
        }
        public void RemoveRange_True()
        {
            //Arrange
            var _wordProgressRange = new List<WordProgress>()
            {
                new WordProgress()
                {
                    WordSuiteId = 7,
                    WordTranslationId = 8
                },
                new WordProgress()
                {
                    WordSuiteId = 7,
                    WordTranslationId = 8
                }
            };
            var _wordProgress = new WordProgress()
            {
                WordSuiteId = 7,
                WordTranslationId = 8
            };
            IQueryable<WordProgress> _queryable = new List<WordProgress>
            {
               _wordProgress
            }.AsQueryable();
            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.Delete(It.IsAny<WordProgress>()));
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);
            _uow.Setup(u => u.Save());
            var _service = new WordProgressService(_factory.Object);

            //Act
            var result = _service.RemoveRange(_wordProgressRange);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Once);
            _uow.Verify(u => u.WordProgressRepository, Times.Exactly(4));
            _progressRepository.Verify(p => p.Delete(It.IsAny<WordProgress>()), Times.Exactly(2));
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(2));
            _uow.Verify(u => u.Save(), Times.Once);
            Assert.IsTrue(result, "true");

        }
예제 #9
0
 public bool RemoveByStudent(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         if (IsStudentWord(wordProgress))
         {
             uow
             .WordProgressRepository
             .Delete(uow
                 .WordProgressRepository.GetAll()
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId));
             uow.Save();
             return true;
         }
         return false;
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    if (IsStudentWord(wordProgress))
     //    {
     //        context
     //        .WordProgresses
     //        .Remove(context
     //            .WordProgresses
     //            .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
     //                          wp.WordTranslationId == wordProgress.WordTranslationId));
     //        context.SaveChanges();
     //        return true;
     //    }
     //    return false;
     //}
 }
예제 #10
0
 public bool IsStudentWord(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         return uow
                 .WordProgressRepository.GetAll()
                 .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                               wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord;
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    return context
     //            .WordProgresses
     //            .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
     //                          wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord;
     //}
 }
 public async Task<bool> CopyWordsuitesForTeacherListByIdAsync(List<int> teacherIds, int wordSuiteId)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         WordSuite wordSuite = await uow.WordSuiteRepository.GetByIdAsync(wordSuiteId);
         if (wordSuite == null)
         {
             throw new ArgumentException("Word Suite with id you are requesting does not exist");
         }
         User teacherWhoShare = await uow.UserRepository.GetByIdAsync(wordSuite.OwnerId);
         List<WordProgress> wordProgresses = await uow.WordProgressRepository.GetAll().Where(t => t.WordSuiteId == wordSuiteId).ToListAsync();
         
         List<WordSuite> wordSuitesToCopy = new List<WordSuite>();
         foreach (int teacherId in teacherIds)
         {
             WordSuite wordSuiteToCopy = new WordSuite
             {
                 Name = wordSuite.Name + "_(Shared_by_" + teacherWhoShare.Name + ")",
                 LanguageId = wordSuite.LanguageId,
                 Threshold = wordSuite.Threshold,
                 QuizResponseTime = wordSuite.QuizResponseTime,
                 QuizStartTime = wordSuite.QuizStartTime,
                 OwnerId = teacherId,
                 PrototypeId = null
             };
             wordSuitesToCopy.Add(wordSuiteToCopy);
         };
         List<WordTranslation> wordTranslationsToCopy = new List<WordTranslation>();
         foreach (var wordProgress in wordProgresses)
         {
             wordTranslationsToCopy.Add(wordProgress.WordTranslation);
         }
         List<WordProgress> WordProgressList = new List<WordProgress>();
         foreach (var wordTranslation in wordTranslationsToCopy)
         {
             foreach (var wordSuiteToCopy in wordSuitesToCopy)
             {
                 WordProgress wordProgress = new WordProgress { WordSuite = wordSuiteToCopy, WordTranslation = wordTranslation };
                 WordProgressList.Add(wordProgress);
             }
         }
         uow.WordSuiteRepository.Add(wordSuitesToCopy);
         uow.WordProgressRepository.Add(WordProgressList);
         await uow.SaveAsync();
         return true;
     }
 }