public FlashcardDbModel ReCalculate(FlashcardPracticeModel input)
        {
            if (input.FlashcardKnowledge == FlashcardKnowledge.DontKnow)
            {
                input.CorreactAnsInRow = 0;
                input.NextPracticeDate = DateTime.Now.Date;

                return(input.CloneFlashcardDbModel());
            }
            else if (input.FlashcardKnowledge == FlashcardKnowledge.AlmostKnow)
            {
                input.CorreactAnsInRow = input.CorreactAnsInRow;
                input.NextPracticeDate = DateTime.Now.Date.AddDays(1);

                return(input.CloneFlashcardDbModel());
            }
            else
            {
                if (input.CorreactAnsInRow == null)
                {
                    input.CorreactAnsInRow = 1;
                }
                else
                {
                    input.CorreactAnsInRow++;
                }

                input.NextPracticeDate = _calculateNextPracticeDate.Calculate(input.CorreactAnsInRow.Value);

                return(input.CloneFlashcardDbModel());
            }
        }
        public void ReCalculateFlashcardPracticePropsTestsD()
        {
            FlashcardPracticeModel model = new FlashcardPracticeModel()
            {
                Id = Guid.Parse("ef12bd07-ed68-46da-93ff-f7083ca16880"),
                CorreactAnsInRow   = 2,
                NextPracticeDate   = DateTime.Now.Date,
                FlashcardKnowledge = FlashcardKnowledge.Know
            };

            IReCalculateFlashcardPracticeProps _processor = new ReCalculateFlashcardPracticeProps(
                new CalculateNextPracticeDate());

            FlashcardDbModel answer = _processor.ReCalculate(model);

            Assert.IsType(typeof(FlashcardDbModel), answer);
            Assert.Equal(model.Id, answer.Id);
            Assert.Equal(3, answer.CorreactAnsInRow);
            Assert.Equal(DateTime.Now.Date.AddDays(3), answer.NextPracticeDate);
        }
Beispiel #3
0
        public void ReCalculateAndUpdatePracticePropertiesListTestC()
        {
            ResetTestDatabasev5.Reset();

            FlashcardDbModel       flashcard;
            FlashcardPracticeModel flashcardPractice;

            using (var db = new FlashcardsDbContext())
            {
                flashcard = db.FlashcardsDbModels.FirstOrDefault(e => e.Id == Guid.Parse("32aee329-6675-4ae8-898a-95bb94ea0143") && e.PracticeDirection == PracticeDirection.FromForeignToNative);

                flashcardPractice = new FlashcardPracticeModel()
                {
                    Id = flashcard.Id,
                    PracticeDirection     = flashcard.PracticeDirection,
                    FlashcardKnowledgeInt = 3,
                    CorreactAnsInRow      = flashcard.CorreactAnsInRow
                };
            }

            ReCalculateAndUpdatePracticePropertiesList _processor = new ReCalculateAndUpdatePracticePropertiesList(new ReCalculateFlashcardPracticeProps(
                                                                                                                       new CalculateNextPracticeDate()),
                                                                                                                   new UpdateFlashcardsListPracticeProperties(
                                                                                                                       new UpdateFlashcardPracticeProperties()));

            _processor.ReCauculate(new List <FlashcardPracticeModel>()
            {
                flashcardPractice
            });

            using (var db = new FlashcardsDbContext())
            {
                Assert.NotNull(db.FlashcardsDbModels
                               .FirstOrDefault(e => e.Id == Guid.Parse("32aee329-6675-4ae8-898a-95bb94ea0143") &&
                                               e.PracticeDirection == PracticeDirection.FromForeignToNative &&
                                               e.CorreactAnsInRow == 4 &&
                                               e.NextPracticeDate == DateTime.Now.Date.AddDays(7)));
            }
        }