コード例 #1
0
 /// <summary>
 /// Modifies an existing word
 /// </summary>
 /// <param name="word">The word to modify</param>
 /// <returns>The modified word</returns>
 public Word Edit(Word word)
 {
     var existingWord = Find(word.WordId);
     wordList.Remove(existingWord);
     wordList.Add(word);
     return word;
 }
コード例 #2
0
ファイル: WordTest.cs プロジェクト: mkorman/CzechLearningTool
        public void Model_Word_Creation()
        {
            // Arrange
            var word = new Word();

            // Assert
            Assert.IsNotNull(word);
        }
コード例 #3
0
        public ActionResult CreateMore(Word word)
        {
            if (ModelState.IsValid)
            {
                db.Create(word);
                return RedirectToAction("Create");
            }

            return View(word);
        }
コード例 #4
0
        public void Model_MockRepo_TestRemove()
        {
            // Arrange
            var word = new Word();
            repo.Create(word);
            Assert.AreEqual(repo.Words.Count(), 1, "Expected repo with 1 word");

            // Act
            repo.Remove(word);
            Assert.AreEqual(repo.Words.Count(), 0, "Expected empty repo");
        }
コード例 #5
0
        public void Model_MockRepo_TestRetrieve()
        {
            // Arrange
            var word = new Word() { English = "Day", Czech = "Day" };
            repo.Create(word);

            // Act
            var newWord = repo.Find(word.WordId);

            // Assert
            Assert.AreEqual(word, newWord, "Word retrieved from repo was different to the word added to it");
        }
コード例 #6
0
        public void Model_MockRepo_TestCount()
        {
            // Arrange
            for (int i = 0; i < 10; i++)
            {
                var word = new Word() { English = i.ToString(), Czech = "" };
                repo.Create(word);
            }

            // Assert
            Assert.AreEqual(repo.Words.Count(), 10, "Unexpected number of words in repo");
        }
コード例 #7
0
ファイル: WordTest.cs プロジェクト: mkorman/CzechLearningTool
        public void Model_Word_Properties()
        {
            // Arrange
            var word = new Word();

            // Act
            word.English = "Two";
            word.Czech = "Dva";

            // Assert
            Assert.AreEqual(word.English, "Two");
            Assert.AreEqual(word.Czech, "Dva");
        }
コード例 #8
0
        public void Model_MockRepo_TestRepeatedInsert()
        {
            // Arrange
            var word = new Word() { English = "Day", Czech = "Den" };

            // Act
            for (int i = 0; i <10 ; i++)
            {
                repo.Create(word);
            }

            // Assert
            Assert.AreEqual(repo.Words.Count(), 1, "Expected just 1 word after inserting same word repeatedly");
        }
コード例 #9
0
        public void Model_WordQuiz_Constructor()
        {
            //Arrange
            var word = new Word();
            word.English = ENGLISH;
            word.Czech = CZECH;
            var quiz = new WordQuiz(word);

            //Act

            //Assert: ensure that the properties map to the word object
            Assert.IsNotNull(quiz, "WordQuiz created by constructor is supposed to be non-null");
            Assert.AreEqual(quiz.English, word.English, "Word and Test Word English property do not match");
            Assert.AreEqual(quiz.Czech, word.Czech, "Word and Test Word Czech property do not match");
            Assert.IsTrue(quiz.hintLevel == 0, "Initial hint level is not 0");
        }
コード例 #10
0
        /// <summary>
        /// Adds a word to the repository
        /// </summary>
        /// <param name="word">The word to add</param>
        /// <returns>The word, with an updated ID</returns>
        public Word Create(Word word)
        {
            // Bypass if we already hold the word
            if (wordList.Contains (word))
            {
                return word;
            }

            // Add word to repo
            var ids = from w in wordList select w.WordId;

            // Set word id
            var id = (ids.Count() == 0) ? 0 : ids.Max() + 1;
            wordList.Add(word);
            return word;
        }
コード例 #11
0
 public ActionResult Edit(Word word)
 {
     if (ModelState.IsValid)
     {
         db.Edit(word);
         return RedirectToAction("Index");
     }
     return View(word);
 }
コード例 #12
0
 /// <summary>
 /// Removes a word from a repository
 /// </summary>
 /// <param name="word">The word to remove</param>
 /// <returns>An IDbSet representing the repository, without the word</returns>
 public IDbSet<Word> Remove(Word word)
 {
     wordList.Remove(word);
     return Words;
 }
コード例 #13
0
 public Word Edit(Word word)
 {
     context.Entry(word).State = EntityState.Modified;
     context.SaveChanges();
     return word;
 }
コード例 #14
0
 public Word Create(Word word)
 {
     context.Words.Add(word);
      context.SaveChanges();
      return word;
 }
コード例 #15
0
ファイル: WordQuiz.cs プロジェクト: mkorman/CzechLearningTool
 public WordQuiz(Word word)
 {
     this.word = word;
     this.userTranslation = String.Empty;
     this.hintLevel = 0;
 }
コード例 #16
0
 public IDbSet<Word> Remove(Word word)
 {
     context.Words.Remove(word);
     context.SaveChanges();
     return context.Words;
 }
コード例 #17
0
ファイル: WordQuiz.cs プロジェクト: mkorman/CzechLearningTool
 public WordQuiz(Word word)
 {
     this.word            = word;
     this.userTranslation = String.Empty;
     this.hintLevel       = 0;
 }