public async Task <IHttpActionResult> GetDescriptionTask(int id) { var _suite = _quizMapper.Map(await _service.GetWithNotStudiedWordsAsync(id)); TrainingWordSuiteModel suite = new TrainingWordSuiteModel(); suite.Id = _suite.Id; suite.OwnerId = _suite.OwnerId; suite.QuizResponseTime = _suite.QuizResponseTime; suite.QuizStartTime = _suite.QuizStartTime; suite.Name = _suite.Name; suite.WordTranslations = new List <WordTranslationModel>(); foreach (var t in _suite.WordTranslations) { if (t.OriginalWordDesc != null) { suite.WordTranslations.Add(t); } } if (suite.OwnerId == UserId) { if (suite.QuizStartTime == null) { suite.QuizStartTime = new DateTime(); } if (((DateTime)suite.QuizStartTime).AddDays(1) < DateTime.Now) { await _service.SetTimeAsync(suite.Id); Shuffle(suite.WordTranslations); return(Ok(suite)); } return(BadRequest(MessagesContainer.OneQuizPerDay)); } return(BadRequest(MessagesContainer.NotYourQuiz)); }
private void Check(TrainingWordSuiteModel answer, TrainingWordSuiteModel wordSuite) { foreach (var word in answer.WordTranslations) { word.OriginalWord = wordSuite.WordTranslations.First(x => x.Id == word.Id).OriginalWord; if (word.TranslationWord == word.OriginalWord) { word.Result = true; _progressService.IncrementProgress(answer.Id, word.Id); } } }
public IHttpActionResult CheckTask(TrainingWordSuiteModel answer) { TrainingWordSuiteModel wordSuite = _trainingMapper.Map(_service.GetWithNotStudiedWords(answer.Id)); DateTime endTime = wordSuite.QuizStartTime.Value. AddSeconds(wordSuite.QuizResponseTime * wordSuite.WordTranslations.Count + 20); if (endTime > DateTime.Now) { Check(answer, wordSuite); return(Ok(answer)); } return(BadRequest(MessagesContainer.TimeCheating)); }
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 IHttpActionResult Check(TrainingWordSuiteModel data) { TrainingWordSuiteModel wordSuite = _trainingMapper.Map(_service.GetWithNotStudiedWords(data.Id)); DateTime EndTime = wordSuite.QuizStartTime.Value.AddSeconds(wordSuite.QuizResponseTime * wordSuite.WordTranslations.Count + 20); if (EndTime > DateTime.Now) { for (int i = 0; i < data.WordTranslations.Count; i++) { data.WordTranslations[i].OriginalWord = wordSuite.WordTranslations.First(x => x.Id == data.WordTranslations[i].Id).OriginalWord; if (data.WordTranslations[i].TranslationWord == data.WordTranslations[i].OriginalWord) { data.WordTranslations[i].Result = true; _progressService.IncrementProgress(data.Id, data.WordTranslations[i].Id); } } return(Ok(data)); } return(BadRequest("Don`t cheat!")); }
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); }