/// <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; }
public void Model_Word_Creation() { // Arrange var word = new Word(); // Assert Assert.IsNotNull(word); }
public ActionResult CreateMore(Word word) { if (ModelState.IsValid) { db.Create(word); return RedirectToAction("Create"); } return View(word); }
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"); }
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"); }
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"); }
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"); }
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"); }
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"); }
/// <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; }
public ActionResult Edit(Word word) { if (ModelState.IsValid) { db.Edit(word); return RedirectToAction("Index"); } return View(word); }
/// <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; }
public Word Edit(Word word) { context.Entry(word).State = EntityState.Modified; context.SaveChanges(); return word; }
public Word Create(Word word) { context.Words.Add(word); context.SaveChanges(); return word; }
public WordQuiz(Word word) { this.word = word; this.userTranslation = String.Empty; this.hintLevel = 0; }
public IDbSet<Word> Remove(Word word) { context.Words.Remove(word); context.SaveChanges(); return context.Words; }