public void ReturnAllCommentsForArticle_WhenParameterIsCorrect() { // Arrange var dbContextMock = new Mock <ApplicationDbContext>(); var articleId = 1; var comment = new Comment(); var comments = new List <Comment>() { comment }; var article = new Article() { Id = articleId, Comments = comments }; var articles = new List <Article>() { article }; var articlesSetMock = new Mock <DbSet <Article> >(); articlesSetMock.SetupData(articles); dbContextMock.Setup(m => m.Articles).Returns(articlesSetMock.Object); var service = new ArticleServices(dbContextMock.Object); // Act var result = service.AllComments(articleId).ToList(); // Assert CollectionAssert.AreEqual(comments, result); }
public void CreateCommentForTheCorrectArticle_WhenParametersAreCorrect() { //Arrange var dbContextMock = new Mock <ApplicationDbContext>(); List <Comment> comments = new List <Comment>(); int articleId = 1; string content = "content"; List <Article> articles = new List <Article>() { new Article() { Id = articleId, Comments = comments } }; var articlesSetMock = new Mock <DbSet <Article> >().SetupData(articles); dbContextMock.SetupGet(m => m.Articles).Returns(articlesSetMock.Object); ArticleServices service = new ArticleServices(dbContextMock.Object); //Act service.AddComment(articleId, content); //Assert var article = dbContextMock.Object.Articles.First(a => a.Id == articleId); var comment = article.Comments.Single(); Assert.AreEqual(articleId, comment.ArticleId); Assert.AreEqual(content, comment.Content); dbContextMock.Verify(m => m.SaveChanges(), Times.Once); }
public void ReturnCorrectArticle_WhenIdIsValid() { //Arrange var dbContextMock = new Mock <ApplicationDbContext>(); var articleSetMock = new Mock <DbSet <Article> >(); var article = new Article() { Id = 1 }; var articles = new List <Article>() { article }; articleSetMock.SetupData(articles); dbContextMock.Setup(m => m.Articles).Returns(articleSetMock.Object); ArticleServices service = new ArticleServices(dbContextMock.Object); //Act var result = service.FindArticle(1); //Assert Assert.AreSame(article, result); }
// // GET: /Advise/ /// <summary> /// 考试咨讯 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult News(int?id) { string categoryCode = string.IsNullOrEmpty(Request.QueryString["CategoryCode"]) ? SystemConst.CategoryCode.News : Request.QueryString["CategoryCode"]; string order = string.IsNullOrEmpty(Request.QueryString["order"]) ? "default" : Request.QueryString["order"]; string categoryName = EnterRepository.GetRepositoryEnter().CategoryRepository.LoadEntities(m => m.Code == categoryCode).FirstOrDefault().Name; Pagination pagination = new Pagination(); int page = 1; if (id != null) { page = int.Parse(id.ToString()); } int size = 10; int totalCount = 0; pagination.Size = size; pagination.CurrentPageIndex = page; var articles = ArticleServices.GetArticles(categoryCode, order, page, size, out totalCount); pagination.TotalCount = totalCount; ViewBag.Order = order; ViewBag.CategoryCode = categoryCode; ViewBag.CategoryName = categoryName; ViewBag.Articles = articles; ViewBag.Pagination = pagination; return(View()); }
public ActionResult About() { var about = ArticleServices.GetArticles(SystemConst.CategoryCode.About); ViewBag.About = about; return(View()); }
public void CreateArticleAndAddItToDb_WhenParametersAreCorrect() { // Arrange var dbContextMock = new Mock <ApplicationDbContext>(); List <Article> articles = new List <Article>(); string articlieAuthor = "author"; string articleTitle = "title"; string articleContent = "content"; var articlesSetMock = new Mock <DbSet <Article> >().SetupData(articles); dbContextMock.SetupGet(m => m.Articles).Returns(articlesSetMock.Object); ArticleServices service = new ArticleServices(dbContextMock.Object); // Act service.AddArticle(articlieAuthor, articleTitle, articleContent); // Assert var article = dbContextMock.Object.Articles.Single(); Assert.AreEqual(articleTitle, article.Title); Assert.AreEqual(articleContent, article.Content); Assert.AreEqual(articlieAuthor, article.Author); dbContextMock.Verify(m => m.SaveChanges(), Times.Once()); }
public void ThrowArgumentNullException_WhenParameterIsNull() { // Arrange var dbContextMock = new Mock <ApplicationDbContext>(); var service = new ArticleServices(dbContextMock.Object); // Act & Assert Assert.ThrowsException <ArgumentNullException>(() => service.DeleteArticle(null)); }
// GET: Home public ActionResult Index() { //获取数据 怎么 反思 请反思 有问题 //---------------------- //测试 List <Articles> lis = ArticleServices.GetArticles(); int a = 0;//更改必须推送? return(View(lis)); }
public void Setup() { _repository = new Mock <IRepository <Article> >(); _httpContextAccessor = new Mock <IHttpContextAccessor>(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(new PressfordMapper())); //Seeing Up AutoMapper Profile to easy setup and we don't have to mock all mappings _mapper = new AutoMapper.Mapper(configuration); _sut = new ArticleServices(_repository.Object, _mapper, _httpContextAccessor.Object); }
public FormDocumentView(List <string> datos, long idDocument, string tipoDocumento) { _idDocument = idDocument; _datos = datos; _tipoDocumento = tipoDocumento; _documentServices = new DocumentServices(); _tesisServices = new TesisServices(); _bookServices = new BookServices(); _articleServices = new ArticleServices(); InitializeComponent(); CreateForm(); }
/// <summary> /// 浏览文章 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult View(int id) { Models.Article article = new Models.Article(); article = ArticleServices.GetArticle(id); article.ViewCount++; EnterRepository.GetRepositoryEnter().ArticleRepository.EditEntity(article, new string[] { "ViewCount" }); EnterRepository.GetRepositoryEnter().SaveChange(); var next = EnterRepository.GetRepositoryEnter().ArticleRepository.LoadEntities(m => m.ModifyTime > article.ModifyTime).FirstOrDefault(); var pre = EnterRepository.GetRepositoryEnter().ArticleRepository.LoadEntities(m => m.ModifyTime < article.ModifyTime).OrderByDescending(m => m.ModifyTime).FirstOrDefault(); ViewBag.Next = next; ViewBag.Pre = pre; return(View(article)); }
public void TestArticleTypeCreation() { //Arrange var service = new ArticleServices(); string[] articleStuff = { "red shirt", "Shirt", "warm" }; ArticleType type = (ArticleType)Enum.Parse(typeof(ArticleType), articleStuff[1].ToString()); //Act service.CreateArticle(articleStuff[0], type, articleStuff[2]); articlesDictionary = service.GetArticles(); //Assert Assert.AreEqual(type, articlesDictionary.ElementAt(0).Value.Type); }
public ArticlesServicesTests() { var articleRepository = new Mock <IArticleRepository>(MockBehavior.Strict); articleRepository.Setup(repo => repo.AddArticleAsync(It.IsAny <Article>())) .ReturnsAsync(new Article()); var log = new Mock <ILog>(); log.Setup(l => l.WriteAsync(It.IsAny <string>())) .Callback(() => LogCalled = true) .Returns(Task.CompletedTask); _articleServices = new ArticleServices(articleRepository.Object, log.Object); }
// // GET: /Home/ public ActionResult Index() { int totalCount = 0; string order = "latest"; ViewBag.NewsGonggao = ArticleServices.GetArticles(SystemConst.CategoryCode.NewsGongGao, order, 1, 10, out totalCount); ViewBag.NewsExamData = ArticleServices.GetArticles(SystemConst.CategoryCode.NewsExamData, order, 1, 10, out totalCount); ViewBag.NewsReview = ArticleServices.GetArticles(SystemConst.CategoryCode.NewsReview, order, 1, 10, out totalCount); ViewBag.NewsScore = ArticleServices.GetArticles(SystemConst.CategoryCode.NewsScore, order, 1, 10, out totalCount); ViewBag.Book = BookServices.GetBooks(SystemConst.CategoryCode.Book, order, 1, 10, out totalCount); ViewBag.Train = TrainServices.GetTrains(SystemConst.CategoryCode.Train, order, 1, 8, out totalCount); ViewBag.Hotel = HotelServices.GetHotels(SystemConst.CategoryCode.Hotel, order, 1, 20, out totalCount); ViewBag.Blog = BlogServices.GetBlogs(null, 0, SystemConst.CategoryCode.Blog, order, 1, 10, out totalCount); return(View()); }
public FormInsert(List <string> datos, long idDocument, string tipoDocumento, List <Par> documentsParList) { _datos = datos; _idDocument = idDocument; _tipoDocumento = tipoDocumento; _updateForm = true; _urlPdfSelected = _datos[4]; _oldUrlPdfSelected = _datos[4]; _documentsParList = documentsParList; _documentServices = new DocumentServices(); _tesisServices = new TesisServices(); _bookServices = new BookServices(); _articleServices = new ArticleServices(); InitializeComponent(); FillFields(); }
public void RemoveArticleFromatabase_WhenParameterIsCorrect() { // Arrange var dbContextMock = new Mock <ApplicationDbContext>(); var article = new Article(); List <Article> articles = new List <Article>() { article }; var articlesSetMock = new Mock <DbSet <Article> >().SetupData(articles); dbContextMock.Setup(m => m.Articles).Returns(articlesSetMock.Object); var service = new ArticleServices(dbContextMock.Object); // Act service.DeleteArticle(article); // Assert Assert.AreEqual(0, dbContextMock.Object.Articles.Count()); }
public void TestGetColdArticles() { //Arrange var service = new ArticleServices(); ArticleType shirt = (ArticleType)Enum.Parse(typeof(ArticleType), "Shirt"); ArticleType pants = (ArticleType)Enum.Parse(typeof(ArticleType), "Pants"); //Act service.CreateArticle("red shirt", shirt, "warm"); service.CreateArticle("blue shirt", shirt, "cold"); service.CreateArticle("green pants", pants, "warm"); articlesDictionary = service.GetArticles(); List <string> articles = new List <string>(); articles.Add("red shirt"); articles.Add("blue shirt"); articles.Add("green pants"); //Assert Assert.AreEqual(service.getColdArticles(articles).ElementAt(0), articles.ElementAt(1)); }
public FormSearchingResult(Form parent, string text, int selectedTab, bool isForm = false) { _documentServices = new DocumentServices(); _tesisServices = new TesisServices(); _bookServices = new BookServices(); _articleServices = new ArticleServices(); _form = parent; isLoged = false; _textSearcher = text; _selectedTab = selectedTab; _isForm = isForm; InitializeComponent(); CreateForm(); metroTabControl2.TabPages.RemoveAt(4); if (isLoged) { loginPictureBox.Enabled = false; } }
public void ReturnAllArticles() { // Arrange var dbContextMock = new Mock <ApplicationDbContext>(); var article = new Article(); var articles = new List <Article>() { article }; var articlesSetMock = new Mock <DbSet <Article> >(); articlesSetMock.SetupData(articles); dbContextMock.Setup(m => m.Articles).Returns(articlesSetMock.Object); var service = new ArticleServices(dbContextMock.Object); // Act var result = service.ListAllArticles().ToList(); // Assert CollectionAssert.AreEqual(articles, result); }
//首页页面 public ActionResult Index(string type, string key, string tag) { List <Articles> Lis = ArticleServices.GetArticles(type, key, tag); return(View(Lis)); }
//文章详情页面 public ActionResult Detail(int Id) { Articles det = ArticleServices.GetArticleDetail(Id); return(View(det)); }
public Blog(int id) { this.Id = id; Articles = new Lazy <List <Article> >(() => ArticleServices.GetArticesByBlogID(id)); Console.WriteLine("BlogUser Initializer"); }