public WordSuiteEditModel MapForEdit(WordSuite wordSuite) { if (wordSuite == null) { throw new ArgumentNullException("wordSuite"); } WordSuiteEditModel model = new WordSuiteEditModel(); model.Id = wordSuite.Id; model.Name = wordSuite.Name; model.Language = wordSuite.Language.Name; model.LanguageId = wordSuite.LanguageId; model.TranslationLanguageId = wordSuite.TranslationLanguageId; if (wordSuite.TranslationLanguage != null) { model.TranslationLanguageName = wordSuite.TranslationLanguage.Name; } else { model.TranslationLanguageName = ""; } model.PrototypeId = wordSuite.PrototypeId; model.Threshold = wordSuite.Threshold; model.QuizResponseTime = wordSuite.QuizResponseTime; model.ProhibitedQuizzesId = wordSuite.ProhibitedQuizzes.Select(q => q.Id).ToList(); return(model); }
public void MapForEditTest() { // Arrange WordSuite initial = new WordSuite { Id = 100, Name = "WordSuite", Language = new Language { Name = "English" }, LanguageId = 200, PrototypeId = 300, Threshold = 50, QuizResponseTime = 10 }; // Act WordSuiteEditModel result = (new WordSuiteMapper()).MapForEdit(initial); // Assert Assert.AreEqual(initial.Id, result.Id); Assert.AreEqual(initial.Name, result.Name); Assert.AreEqual(initial.Language.Name, result.Language); Assert.AreEqual(initial.LanguageId, result.LanguageId); Assert.AreEqual(initial.PrototypeId, result.PrototypeId); Assert.AreEqual(initial.Threshold, result.Threshold); Assert.AreEqual(initial.QuizResponseTime, result.QuizResponseTime); }
public void Update_ReturnsTrue() { //Arrange WordSuite newWordSuite = new WordSuite { Id = 1, Name = "name", Threshold = 1, QuizResponseTime = 1 }; _repo.Setup(r => r.GetById(It.IsAny <int>())).Returns(new WordSuite() { Id = 1 }); _repo.Setup(r => r.Update(It.IsAny <WordSuite>())).Verifiable(); _uow.Setup(u => u.Save()).Verifiable(); //Act var actual = _service.Update(newWordSuite); //Assert _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.WordSuiteRepository, Times.Exactly(2)); _repo.VerifyAll(); _uow.VerifyAll(); Assert.IsTrue(actual); }
public async Task GetByID_ReturnsWordSuite() { //Arrange int wordSuiteId = 1; WordSuite expected = new WordSuite { Id = wordSuiteId }; IQueryable <WordSuite> suites = new List <WordSuite>() { expected }.AsQueryable <WordSuite>(); var mockSet = GenerateMockDbSet <WordSuite>(suites); _repo.Setup(x => x.GetAll()).Returns(mockSet.Object); //Act var actual = await _service.GetByIDAsync(wordSuiteId); //Assert _factory.Verify(x => x.GetUnitOfWork(), Times.Once); _uow.Verify(x => x.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetAll(), Times.Once); Assert.AreEqual(expected, actual); }
public WordSuite Map(CourseWordSuiteModel wordSuite) { WordSuite model = new WordSuite(); model.Id = wordSuite.Id; model.Name = wordSuite.Name; return(model); }
public CourseWordSuiteModel Map(WordSuite wordSuite) { return(new CourseWordSuiteModel() { Id = wordSuite.Id, Name = wordSuite.Name }); }
public CourseWordSuiteModel Map(WordSuite wordSuite) { CourseWordSuiteModel model = new CourseWordSuiteModel(); model.Id = wordSuite.Id; model.Name = wordSuite.Name; model.ProhibitedQuizzesId = wordSuite.ProhibitedQuizzes.Select(q => q.Id).ToList(); return(model); }
public async Task CopywordsuitesForTeacherByIdAsync_ReturnsBool_Positive() { //Arrange int teacherId = 1; int wordSuiteId = 2; int wordSuiteOwnerId = 3; int saveAsyncPositiveResult = 1; Mock <IUserRepository> _usersRepo = new Mock <IUserRepository>(); Mock <IWordProgressRepository> _wordProgressRepo = new Mock <IWordProgressRepository>(); _uow.Setup(u => u.UserRepository).Returns(_usersRepo.Object); _uow.Setup(u => u.WordProgressRepository).Returns(_wordProgressRepo.Object); WordSuite workSuite = new WordSuite { Id = wordSuiteId, OwnerId = wordSuiteOwnerId }; User teacherWhoShare = new User { Id = wordSuiteOwnerId }; WordTranslation wordTranslation = new WordTranslation(); IQueryable <WordProgress> wordProgresses = new List <WordProgress> { new WordProgress { WordSuiteId = wordSuiteId, WordTranslation = wordTranslation } }.AsQueryable <WordProgress>(); var mockSet = GenerateMockDbSet <WordProgress>(wordProgresses); _repo.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(workSuite); _usersRepo.Setup(u => u.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(teacherWhoShare); _wordProgressRepo.Setup(r => r.GetAll()).Returns(mockSet.Object); _wordProgressRepo.Setup(r => r.Add(It.IsAny <IEnumerable <WordProgress> >())); _repo.Setup(r => r.Add(It.IsAny <WordSuite>())); _uow.Setup(u => u.SaveAsync()).ReturnsAsync(saveAsyncPositiveResult); //Act var actual = await _service.CopyWordsuitesForTeacherByIdAsync(teacherId, wordSuiteId); bool expected = true; //Assert _repo.Verify(r => r.Add(It.Is <WordSuite>((ws => ws.OwnerId == teacherId)))); _repo.Verify(r => r.GetByIdAsync(It.IsAny <int>()), Times.Once); _usersRepo.Verify(u => u.GetByIdAsync(It.IsAny <int>()), Times.Once); _wordProgressRepo.Verify(r => r.GetAll(), Times.Once); _wordProgressRepo.Verify(r => r.Add(It.IsAny <IEnumerable <WordProgress> >()), Times.Once); _repo.Verify(r => r.Add(It.IsAny <WordSuite>()), Times.Once); _uow.Verify(u => u.SaveAsync(), Times.Once); Assert.AreEqual(actual, expected); }
public int Add(WordSuite wordSuite) { using (var context = new WorldOfWordsDatabaseContext()) { context.WordSuites.AddOrUpdate(wordSuite); context.SaveChanges(); return(wordSuite.Id); } }
public int Add(WordSuite wordSuite) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { uow.WordSuiteRepository.AddOrUpdate(wordSuite); uow.Save(); return(wordSuite.Id); } }
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); } }
public TrainingWordSuiteModel Map(WordSuite WordSuite) { TrainingWordSuiteModel wordSuiteModel = new TrainingWordSuiteModel(); wordSuiteModel.Id = WordSuite.Id; wordSuiteModel.OwnerId = WordSuite.OwnerId; wordSuiteModel.QuizResponseTime = WordSuite.QuizResponseTime; wordSuiteModel.QuizStartTime = WordSuite.QuizStartTime; wordSuiteModel.Name = WordSuite.Name; wordSuiteModel.WordTranslations = new List<WordTranslationModel>(); wordSuiteModel.WordTranslations.AddRange(WordSuite.WordProgresses.Select(x => _mapper.Map(x.WordTranslation)).ToList()); return wordSuiteModel; }
public bool Update(WordSuite wordSuite) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var oldWordSuite = uow.WordSuiteRepository.GetById(wordSuite.Id); oldWordSuite.Name = wordSuite.Name; oldWordSuite.Threshold = wordSuite.Threshold; oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime; uow.WordSuiteRepository.Update(oldWordSuite); uow.Save(); } return(true); }
public bool Update(WordSuite wordSuite) { using (var context = new WorldOfWordsDatabaseContext()) { var oldWordSuite = context.WordSuites.First(ws => ws.Id == wordSuite.Id); oldWordSuite.Name = wordSuite.Name; oldWordSuite.Threshold = wordSuite.Threshold; oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime; context.WordSuites.AddOrUpdate(oldWordSuite); context.SaveChanges(); } return(true); }
public int Add(WordSuite wordSuite) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { uow.WordSuiteRepository.AddOrUpdate(wordSuite); uow.Save(); return(wordSuite.Id); } //using (var context = new WorldOfWordsDatabaseContext()) //{ // context.WordSuites.AddOrUpdate(wordSuite); // context.SaveChanges(); // return wordSuite.Id; //} }
public void TrainingWordSuiteController_GetTest() { //Arrange var initial = new WordSuite() { Id = 1, Name = "Days of the week" }; var expected = new TrainingWordSuiteModel() { Id = 1, Name = "Days of the week", WordTranslations = new List <WordTranslationModel>() { new WordTranslationModel { Id = 1, OriginalWord = "sunday" }, new WordTranslationModel { Id = 1, OriginalWord = "monday" } } }; //Action Mock <IQuizWordSuiteMapper> testWordSuiteMapper = new Mock <IQuizWordSuiteMapper>(); Mock <ITrainingWordSuiteMapper> trainingWordSuiteMapper = new Mock <ITrainingWordSuiteMapper>(); Mock <IWordSuiteService> wordSuiteService = new Mock <IWordSuiteService>(); Mock <IWordProgressService> progressService = new Mock <IWordProgressService>(); Mock <IWordProgressMapper> progressMapper = new Mock <IWordProgressMapper>(); GenerateData("1", new[] { "NoRoles" }); TrainingWordSuiteController Controller = new TrainingWordSuiteController(testWordSuiteMapper.Object, trainingWordSuiteMapper.Object, wordSuiteService.Object, progressService.Object, progressMapper.Object); wordSuiteService.Setup(x => x.GetWithNotStudiedWords(1)).Returns(initial); testWordSuiteMapper .Setup(x => x.Map(initial)) .Returns(expected); var actual = Controller.GetTask(1); //Assert //Assert.AreEqual(expected, actual); }
public void SetTime_GetByIdNull() { //Arrange int id = 1; WordSuite wordSuite = null; _repo.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(wordSuite); //Act //Assert Assert.Throws <NullReferenceException>(async() => await _service.SetTimeAsync(id)); _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetByIdAsync(It.IsAny <int>()), Times.Once); }
public WordSuiteEditModel MapForEdit(WordSuite wordSuite) { if (wordSuite == null) { throw new ArgumentNullException("wordSuite"); } return(new WordSuiteEditModel() { Id = wordSuite.Id, Name = wordSuite.Name, Language = wordSuite.Language.Name, LanguageId = wordSuite.LanguageId, Threshold = wordSuite.Threshold, QuizResponseTime = wordSuite.QuizResponseTime }); }
public void GetWordSuiteProgress_ReturnsProgress() { //Arrange int id = 1; var expected = 1000.0; ICollection <WordProgress> progressCollection = new List <WordProgress>() { new WordProgress() { Progress = 10 }, new WordProgress() { Progress = 10 }, new WordProgress() { Progress = 10 } }; WordSuite wordSuite = new WordSuite { Id = id, Threshold = 1, WordProgresses = progressCollection }; IQueryable <WordSuite> wordSuites = new List <WordSuite> { wordSuite }.AsQueryable <WordSuite>(); _repo.Setup(x => x.GetAll()).Returns(wordSuites); //Act var actual = _service.GetWordSuiteProgress(id); //Assert _factory.Verify(x => x.GetUnitOfWork(), Times.Once); _uow.Verify(x => x.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetAll(), Times.Once); Assert.AreEqual(actual, expected); }
public TrainingWordSuiteModel Map(WordSuite WordSuite) { TrainingWordSuiteModel wordSuiteModel = new TrainingWordSuiteModel(); wordSuiteModel.Id = WordSuite.Id; wordSuiteModel.OwnerId = WordSuite.OwnerId; wordSuiteModel.QuizResponseTime = WordSuite.QuizResponseTime; wordSuiteModel.QuizStartTime = WordSuite.QuizStartTime; wordSuiteModel.Name = WordSuite.Name; wordSuiteModel.LanguageId = WordSuite.LanguageId; wordSuiteModel.Threshold = WordSuite.Threshold; wordSuiteModel.WordTranslations = new List <WordTranslationModel>(); wordSuiteModel.WordTranslations.AddRange(WordSuite.WordProgresses.Select(x => _mapper.Map(x.WordTranslation)).ToList()); for (int i = 0; i < wordSuiteModel.WordTranslations.Count; i++) { wordSuiteModel.WordTranslations[i].Progress = (int)(WordSuite.WordProgresses.ToList())[i].Progress; } return(wordSuiteModel); }
public void GetWordSuiteProgress_ReturnsInfinity() { //Arrange int id = 1; ICollection <WordProgress> progressCollection = new List <WordProgress>() { new WordProgress() { Progress = 10 }, new WordProgress() { Progress = 10 }, new WordProgress() { Progress = 10 } }; WordSuite wordSuite = new WordSuite { Id = id, WordProgresses = progressCollection }; IQueryable <WordSuite> wordSuites = new List <WordSuite> { wordSuite }.AsQueryable <WordSuite>(); _repo.Setup(x => x.GetAll()).Returns(wordSuites); //Act var actual = _service.GetWordSuiteProgress(id); //Assert _factory.Verify(x => x.GetUnitOfWork(), Times.Once); _uow.Verify(x => x.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetAll(), Times.Once); Assert.IsTrue(Double.IsInfinity(actual)); }
public void Map_WordSuiteAndCourseWordSuiteModelAreEqual() { //Arrange var initial = new WordSuite { Id = 1, Name = "Day of week" }; var expected = new CourseWordSuiteModel { Id = 1, Name = "Day of week" }; //Act var actual = (new WordSuiteMapper()).Map(initial); //Assert Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.Name, actual.Name); }
public async Task SetTimeTest() { //Arrange int id = 1; WordSuite wordSuite = new WordSuite { Id = id }; _repo.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(wordSuite); _uow.Setup(u => u.SaveAsync()).ReturnsAsync(It.IsAny <int>()).Verifiable(); //Act await _service.SetTimeAsync(id); //Assert _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetByIdAsync(It.IsAny <int>()), Times.Once); _uow.VerifyAll(); }
public async Task GetWithNotStudiedWords_ReturnsWordSuite() { //Arrange int id = 1; ICollection <WordProgress> progressCollection = new List <WordProgress>() { new WordProgress() { Progress = 2 }, new WordProgress() { Progress = 6 } }; WordSuite expected = new WordSuite { Id = id, Threshold = 5, WordProgresses = progressCollection }; IQueryable <WordSuite> wordSuites = new List <WordSuite> { expected }.AsQueryable <WordSuite>(); var mockSet = GenerateMockDbSet <WordSuite>(wordSuites); _repo.Setup(x => x.GetAll()).Returns(mockSet.Object); //Act var actual = await _service.GetWithNotStudiedWordsAsync(id); //Assert _factory.Verify(x => x.GetUnitOfWork(), Times.Once); _uow.Verify(x => x.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetAll(), Times.Once); Assert.AreEqual(expected, actual); }
public void Update_GetByIdNull() { //Arrange WordSuite newWordSuite = new WordSuite { Id = 1, Name = "name", Threshold = 1, QuizResponseTime = 1 }; WordSuite oldWordSuite = null; _repo.Setup(r => r.GetById(It.IsAny <int>())).Returns(oldWordSuite); //Act //Assert Assert.Throws <NullReferenceException>(() => _service.Update(newWordSuite)); _factory.Verify(f => f.GetUnitOfWork(), Times.Once); _uow.Verify(u => u.WordSuiteRepository, Times.Once); _repo.Verify(x => x.GetById(It.IsAny <int>()), Times.Once); }
public bool Update(WordSuite wordSuite) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var oldWordSuite = uow.WordSuiteRepository.GetById(wordSuite.Id); oldWordSuite.Name = wordSuite.Name; oldWordSuite.Threshold = wordSuite.Threshold; oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime; uow.WordSuiteRepository.Update(oldWordSuite); uow.Save(); } //using (var context = new WorldOfWordsDatabaseContext()) //{ // var oldWordSuite = context.WordSuites.First(ws => ws.Id == wordSuite.Id); // oldWordSuite.Name = wordSuite.Name; // oldWordSuite.Threshold = wordSuite.Threshold; // oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime; // context.WordSuites.AddOrUpdate(oldWordSuite); // context.SaveChanges(); //} return(true); }
public void Add_ReturnsWordSuiteId() { //Arrange int expected = 1; WordSuite wordSuite = new WordSuite { Id = expected, LanguageId = 1 }; _repo.Setup(x => x.AddOrUpdate(It.IsAny <WordSuite>())).Verifiable(); _uow.Setup(x => x.Save()).Verifiable(); //Act var actual = _service.Add(wordSuite); //Assert _uow.Verify(x => x.WordSuiteRepository, Times.Once); _uow.Verify(x => x.Save(), Times.Once); _uow.VerifyAll(); _repo.VerifyAll(); Assert.AreEqual(expected, actual); }
public void TrainingWordSuiteController_Check() { //Arrange var initial = new WordSuite() { Id = 1, Name = "Days of the week", }; var data = new TrainingWordSuiteModel() { Id = 1, Name = "Days of the week", QuizStartTime = DateTime.Now, QuizResponseTime = 10, WordTranslations = new List <WordTranslationModel>() { new WordTranslationModel { Id = 1, OriginalWord = "sunday", TranslationWord = "sunday" }, new WordTranslationModel { Id = 1, OriginalWord = "monday", TranslationWord = "monday" } } }; var expected = new TrainingWordSuiteModel() { Id = 1, Name = "Days of the week", QuizStartTime = DateTime.Now, QuizResponseTime = 10, WordTranslations = new List <WordTranslationModel>() { new WordTranslationModel { Id = 1, OriginalWord = "sunday", TranslationWord = "неділя" }, new WordTranslationModel { Id = 1, OriginalWord = "monday", TranslationWord = "понеділок" } } }; //Action Mock <IQuizWordSuiteMapper> testWordSuiteMapper = new Mock <IQuizWordSuiteMapper>(); Mock <ITrainingWordSuiteMapper> trainingWordSuiteMapper = new Mock <ITrainingWordSuiteMapper>(); Mock <IWordSuiteService> wordSuiteService = new Mock <IWordSuiteService>(); Mock <IWordProgressService> progressService = new Mock <IWordProgressService>(); Mock <IWordProgressMapper> progressMapper = new Mock <IWordProgressMapper>(); GenerateData("1", new[] { "NoRoles" }); TrainingWordSuiteController Controller = new TrainingWordSuiteController(testWordSuiteMapper.Object, trainingWordSuiteMapper.Object, wordSuiteService.Object, progressService.Object, progressMapper.Object); wordSuiteService.Setup(x => x.GetWithNotStudiedWords(1)).Returns(initial); trainingWordSuiteMapper .Setup(x => x.Map(initial)) .Returns(expected); progressService.Setup(x => x.IncrementProgress(It.IsAny <int>(), It.IsAny <int>())).Returns(true); var actual = Controller.CheckTask(data); //Assert Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <TrainingWordSuiteModel>), actual); }