public void CreateTest_Get_ReturnsView() { // Act var result = controller.Create(); // Assert var viewResult = Assert.IsType <ViewResult>(result); }
public void CreateArticle_Short_Valid() { using (TransactionScope transaction = new TransactionScope()) { articleRepository = new ArticlesRepository(); int count = articleRepository.GetAllArticles().Count(); //Count articles pre-creation of new article SMCC.Models.Article newArticle = new SMCC.Models.Article(); SMCC.Models.Article createdArticle = new SMCC.Models.Article(); List <SMCC.Models.Article> existArticles = new List <SMCC.Models.Article>(); try { //Set your controller ControllerContext with fake context articleController.ControllerContext = MockContext().Object; newArticle.Title = "A"; newArticle.Text = "A"; articleController.Create(newArticle); } finally { articleRepository = new ArticlesRepository(); existArticles = articleRepository.GetAllArticles().ToList(); createdArticle = articleRepository.GetArticle(newArticle.ArticleId); Assert.AreEqual(count + 1, existArticles.Count()); CollectionAssert.Contains(existArticles, createdArticle); } } }
public void Create_Always_CallsRepositoryWithData() { // arrange const string ARTICLE_TITLE = "article title"; var incomingSaveData = new ArticleSaveData { Title = ARTICLE_TITLE }; var createdSummary = new ArticleSummary(); _mockArticleRepository.Setup(r => r.Create(It.IsAny <ArticleSaveData>())).Returns(createdSummary); // act _articlesController.Create(incomingSaveData); // assert _mockArticleRepository.Verify(r => r.Create(It.Is <ArticleSaveData>(sd => sd.Title == ARTICLE_TITLE))); }
public void CreateArticlesViewShouldPassed() { // Arrange var articleService = new Mock <IArticleService>().Object; var htmlService = new Mock <IHtmlService>().Object; var userManager = this.GetUserManagerMock().Object; string successMsg = null; var tempData = new Mock <ITempDataDictionary>(); tempData.SetupSet(t => t[TempDataSuccessMessageKey] = It.IsAny <string>()) .Callback((string key, object message) => successMsg = message as string); // mock indexer var controller = new ArticlesController(articleService, userManager, htmlService) { TempData = tempData.Object }; var publishArticleFormViewModel = new PublishArticleFormViewModel() { Title = ArticleTitle, Content = ArticleContent }; // Act var resultCreateGet = controller.Create() as ViewResult; var resultCreatePost = controller.Create(publishArticleFormViewModel); // Assert resultCreateGet .Should() .NotBeNull(); resultCreatePost.Should().BeOfType <RedirectToActionResult>(); resultCreatePost.As <RedirectToActionResult>().ActionName.Should().Be(nameof(ArticlesController.Index)); successMsg .Should() .Be(SuccessPublishedArticle); }
public void AddMakoNews(string url, Category cat, User user) { int counter = 0; int k = 0; //string url = "http://rcs.mako.co.il/rss/31750a2610f26110VgnVCM1000005201000aRCRD.xml"; bool flag = false; string[,] arrayNews = new string[25, 11]; XmlTextReader reader = new XmlTextReader(url); while (reader.Read()) { if (flag == false) { if (reader.Name != "item") { continue; } else { flag = true; } } switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. //Console.Write("<" + reader.Name); //Console.WriteLine(">"); break; case XmlNodeType.Text: //Display the text in each element. //Console.WriteLine(reader.Value); arrayNews[k, counter] = reader.Value; break; case XmlNodeType.EndElement: //Display the end of the element. //Console.Write("</" + reader.Name); //Console.WriteLine(">"); counter++; break; } if (counter == 12) { k++; counter = 0; } } //Console.WriteLine(arrayNews[3, 2]); //Console.ReadKey(); //return arrayNews; for (int i = 0; i < 18; i++) { Article a = new Article(); a.Title = arrayNews[i, 0]; a.Description = arrayNews[i, 1]; a.Date = arrayNews[i, 3]; a.NumOfLikes = 0; a.ImageLink = arrayNews[i, 9]; a.ArticleLink = arrayNews[i, 2]; a.Category = cat; a.CategoryId = cat.CategoryId; a.User = user; a.UserId = user.UserId; ArticlesController ac = new ArticlesController(); ac.Create(a); } }