public void ExistNameOfTopic() { var t1 = new Topic { TopicId = 1, NameOfTopic = "Topic1", Description = "Topic1" }; var t2 = new Topic { TopicId = 2, NameOfTopic = "Topic2", Description = "Topic2" }; Mock <IRepositoryFactory> mock = new Mock <IRepositoryFactory>(); mock.Setup(a => a.TopicRepository.Get()).Returns(new List <Topic> { t1, t2 }); bool result = TopicService.ExistNameOfTopic(mock.Object, "БудМайстер"); Assert.AreEqual(false, result); }
public ActionResult Create(TopicViewModel topicViewModel) { try { if (ModelState.IsValid) { ViewBag.Name = ""; if (TopicService.ExistNameOfTopic(_factory, topicViewModel.NameOfTopic)) { ViewBag.Name = "Тема с таким названием уже существует"; return(View(topicViewModel)); } var topicObj = new Topic { NameOfTopic = topicViewModel.NameOfTopic, Description = topicViewModel.Description }; _factory.TopicRepository.Add(topicObj); logger.Info("Тема изданий {0} добавлена", topicObj.NameOfTopic); TempData["SuccessMessage"] = "Тема изданий добавлена."; return(RedirectToAction("Index1")); } return(View(topicViewModel)); } catch (Exception ex) { logger.Error(ex, ex.Message); return(View("Error", new HandleErrorInfo(ex, "Topics", "Create"))); } }