public void TestListAll()
        {
            newsRepo.All().Delete();
            newsRepo.SaveChanges();
            CollectionAssert.AreEquivalent(new List <News>(), newsRepo.All().ToList());
            Assert.AreEqual(0, newsRepo.All().Count());

            var news1 = new News {
                Title = "Zaglavie", Content = "dadadada"
            };
            var news2 = new News {
                Title = "Teadsad", Content = "koko6ki"
            };
            var news3 = new News {
                Title = "Asdjoqwe", Content = "asodojk"
            };

            newsRepo.Add(news1);
            newsRepo.Add(news2);
            newsRepo.Add(news3);
            newsRepo.SaveChanges();

            CollectionAssert.AreEquivalent(new[] { news1, news2, news3 }, newsRepo.All().ToList());
            Assert.AreEqual(3, newsRepo.All().Count());
        }
        public void CreateNews_WhenNewsIsAddedToDbWithCorrectData_ShouldReturnNews()
        {
            // Arrange -> prapare the objects

            var repo = new NewsRepository(new NewsContext());
            var news = new Models.News()
            {
                Title = "Sample New News",
                PublishDate = DateTime.Now,
                Content = "Sample New News Content"
            };

            // Act -> perform some logic
            repo.Add(news);
            repo.SaveChanges();

            // Assert -> validate the results
            var newsFromDb = repo.Find(news.Id);

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate);
            Assert.IsTrue(newsFromDb.Id != 0);
        }
Ejemplo n.º 3
0
        public IActionResult Post([FromForm] NewsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                BadRequest(ModelState);
            }

            News news = new News
            {
                ContentDe     = model.ContentDe,
                ContentFr     = model.ContentFr,
                Date          = model.Date,
                PreviewDe     = model.PreviewDe,
                PreviewFr     = model.PreviewFr,
                TitleDe       = model.TitleDe,
                TitleFr       = model.TitleFr,
                LinkFacebook  = model.LinkFacebook,
                LinkInstagram = model.LinkInstagram,
                DateCreated   = DateTime.Now
            };

            _newsRepository.Add(news);

            SafeNewsImages(model, news);

            _newsRepository.Update(news);

            return(CreatedAtRoute(GetNewsRoutName, new { id = news.Id }, news));
        }
Ejemplo n.º 4
0
 public ActionResult AddNews([Bind(Prefix = "Item1")] News item, HttpPostedFileBase resim, HttpPostedFileBase video)
 {
     item.CreatedBy = (Session["admin"] as AppUser).UserName;
     item.ImagePath = ImageUploader.UploadImage("~/Pictures", resim);
     item.VideoPath = VideoUploader.UploadVideo("~/Videos", video);
     news_repo.Add(item);
     return(RedirectToAction("ListNews"));
 }
        public void CreateAndAddInvalidNewsToDbShouldReturnError()
        {
            var repo = new NewsRepository(new NewsContext());

            var news = new News { Title = null };
            repo.Add(news);
            repo.SaveChanges();
        }
Ejemplo n.º 6
0
 public async Task <IActionResult> Index([FromBody] object obj)
 {
     if (ModelState.IsValid)
     {
         var item = Validation.Validate(obj);
         if (item != null)
         {
             _repo.Add(item);
             if (await _repo.SaveChangesAsync())
             {
                 return new JsonResult(item)
                        {
                            StatusCode = 201
                        }
             }
             ;
         }
     }
     _logger.LogError($"Error saving item to database");
     return(BadRequest("Posting data failed!"));
 }
        public void AddNews_WhenNewsIsInvalid_ShouldThrowException()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = new News.Models.News()
            {
                Content     = "TestNewsContent",
                PublishDate = new DateTime(2015, 05, 10)
            };

            repo.Add(news);
            repo.SaveChanges();
        }
        public IActionResult Seed()
        {
            _newsRepository.RecreateDatabase();

            News news1 = new News
            {
                Header       = "worst place",
                CreatDatTime = DateTime.Now,
                UpdatedDate  = DateTime.Now
            };
            News news2 = new News
            {
                Header       = "Grizzly restored",
                CreatDatTime = DateTime.Now,
                UpdatedDate  = DateTime.Now
            };

            _newsRepository.Add(news1);
            _newsRepository.Add(news2);


            return(Ok());
        }
Ejemplo n.º 9
0
 public ActionResult Create(News news)
 {
     try
     {
         // TODO: Add insert logic here
         news.PublisherID    = User.Identity.GetUserId();
         news.PublishingDate = DateTime.Now;
         nRepo.Add(news);
         return(RedirectToAction("AdminIndex"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 10
0
 public bool SaveNews(NewsDTO <string> news)
 {
     try
     {
         var newsEntity = new News()
         {
             Image = null, Title = news.Title, Content = news.Resume, DateNews = DateTime.Now
         };
         _newsRepository.Add(newsEntity);
         _newsRepository.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
 public IActionResult Add([FromBody] News news)
 {
     if (string.IsNullOrEmpty(news.Header) || string.IsNullOrEmpty(news.Intro) || string.IsNullOrEmpty(news.Body))
     {
         return(BadRequest("Du måste fylla i alla fält!"));
     }
     else if (news.Header.Length < 5 || news.Header.Length > 20)
     {
         return(BadRequest("Måste vara mellan 5-20 tecken"));
     }
     else
     {
         news.Created = DateTime.Now;
         _newsRepository.Add(news);
         return(Ok(news.Id));
     }
 }
Ejemplo n.º 12
0
        public void GetAllNewsReturnNewsShouldReturnCorrectly()
        {
            var repo = new NewsRepository(new NewsContext());

            var news = new News
            {
                Title = "Test Title",
                Content = "Some test content.",
                PublishedDate = DateTime.Now
            };
            repo.Add(news);
            repo.SaveChanges();

            var newsDb = repo.Find(news.Id);

            Assert.IsNotNull(newsDb);
            Assert.AreEqual(news.Title, newsDb.Title);
            Assert.AreEqual(news.Content, newsDb.Content);
            Assert.AreEqual(news.PublishedDate, newsDb.PublishedDate);
        }
        public void InsertNews_WhenInsertedCorrectly_ShouldReturnNews()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = new News.Models.News()
            {
                Title       = "TestNews",
                Content     = "TestNewsContent",
                PublishDate = new DateTime(2015, 05, 10)
            };

            repo.Add(news);
            repo.SaveChanges();

            var newsFromDb = repo.Find(news.Id);

            Assert.AreEqual(4, repo.All().Count());
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishDate.ToShortDateString(),
                            newsFromDb.PublishDate.ToShortDateString());
            Assert.AreNotEqual(0, newsFromDb.Id);
        }
Ejemplo n.º 14
0
        public ActionResult AddNews(NewsViewModel hbr, HttpPostedFileBase file)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("News", "News"));
            }
            var newsEntity = new HaberTbl();


            newsEntity.Id      = hbr.Id;
            newsEntity.spot    = hbr.spot;
            newsEntity.title   = hbr.title;
            newsEntity.content = hbr.content;
            newsEntity.ImageId = AddNewsImage(file);

            ProjeHaberDbEntities db = new ProjeHaberDbEntities();
            var ktg = db.Editor.Where(m => m.Id == hbr.EditorId).FirstOrDefault();

            newsEntity.EditorId = ktg.Id;

            _rep.Add(newsEntity);

            return(RedirectToAction("News"));
        }
Ejemplo n.º 15
0
        public ActionResult Add(AddNewsViewModel model, HttpPostedFileBase file)
        {
            var entity = model.ToNewsResult()
                         .Update(x =>
            {
                x.CreatedBy = UserName;
                x.IsDeleted = !model.IsDeleted;
                x.UrlImage  = file.FileName;
            });

            var result = NewsRepository.Add(entity);

            if (result == SaveResult.SUCCESS)
            {
                SaveFile(entity.Id, file);

                return(RedirectToRoute(UrlLink.NEWS_EDIT, new { id = entity.Id }));
            }
            ViewBag.HasError = true;
            var newsCategory = NewsCategoryRepository.GetAll().Select(x => x.ToDataViewModel());

            model.NewsCategory = newsCategory;
            return(View());
        }
        public void Add_NewsRecord_Should_Add_NewsRecord_to_DB()
        {
            //Arrange
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "HardShit",
                Content = "Hard Shit in the mix",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            //Act
            repo.Add(news);
            repo.SaveChanges();

            //Assert
            var newsFromDb = repo.FindById(news.Id);

            Assert.IsNotNull(newsFromDb, "NewsRecord is not added to database");
            Assert.IsTrue(newsFromDb.Id != 0, "NewsRecord must have id !=0");
            Assert.AreEqual(news.Title, newsFromDb.Title, "Title is not corect");
            Assert.AreEqual(news.Content, newsFromDb.Content, "Content is not corect");
            Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate, "Date is not corect");
        }
        public void List_NewsRecords_Should_Return_Correct_List()
        {
            //Arrange
            NewsRepository repo = new NewsRepository(new NewsContext());
            var countBeforeAdding = repo.GetAll().Count();

            var news = new NewsRecord()
            {
                Title = "HardShit",
                Content = "Hard Shit in the mix",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };
            var news2 = new NewsRecord()
            {
                Title = "SmokeShit",
                Content = "Smoke Shit in the mix",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            var listNews = new List<NewsRecord>();
            listNews.Add(news);
            listNews.Add(news2);

            var newsBeforeAdd = repo.GetAll()
               .Select(n => n.Title)
               .ToList();

            var fakeNewsTitles = listNews
                .Select(n => n.Title)
                .ToList();

            fakeNewsTitles.AddRange(newsBeforeAdd);
            fakeNewsTitles.Sort();

            var fakeNewsTitlesOrd = fakeNewsTitles;
                 

            //Act
            repo.Add(news);
            repo.Add(news2);
            repo.SaveChanges();

            var allNews = repo.GetAll()
                .OrderBy(n => n.Title)
                .Select(n => n.Title)
                .ToList();

            //Assert
            Assert.AreEqual(2 + countBeforeAdding, repo.GetAll().Count());
            CollectionAssert.AreEqual(fakeNewsTitlesOrd, allNews);
        }
        public void Delete_Existing_Data_Should_Delete_The_Data()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            repo.Add(news);
            repo.SaveChanges();

            var countBeforeDeletion = repo.GetAll().Count();

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            repo.Delete(newsFromDB);
            repo.SaveChanges();

            Assert.AreEqual(countBeforeDeletion - 1, repo.GetAll().Count());
        }
        public void Modify_Existing_Data_With_Incorrect_Data_Should_Throw_Exception()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            repo.Add(news);
            repo.SaveChanges();

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            newsFromDB.Title = "";

            repo.Update(news);
            repo.SaveChanges();
        }
        public void Modify_Existing_Data_Should_Update_The_Data()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            repo.Add(news);
            repo.SaveChanges();

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            newsFromDB.Title = "ModifiedShit";

            repo.Update(news);
            repo.SaveChanges();

            var changedNews = repo.GetAll().FirstOrDefault(n => n.Title == "ModifiedShit");

            Assert.AreEqual("ModifiedShit", changedNews.Title);
        }
        public void Add_Empty_Sting_Title_News_Record_Should_Throw_Exception()
        {
            // Arrange -> prapare the objects
            NewsRepository repo = new NewsRepository(new NewsContext());
            var invalidNewsRecord = new NewsRecord()
            {
                Title = "",
                Content = "Oh big Shit"
            };

            // Act -> perform some logic
            repo.Add(invalidNewsRecord);
            repo.SaveChanges();

            // Assert -> expect an exception
        }
Ejemplo n.º 22
0
 public Newspaper AddNewspaper(Newspaper newspaper)
 {
     return(repository.Add(newspaper));
 }
Ejemplo n.º 23
0
 public Account AddAccount(Account account)
 {
     return(repository.Add(account));
 }
Ejemplo n.º 24
0
 public Feedback AddFeedback(Feedback feedback)
 {
     return(repository.Add(feedback));
 }
Ejemplo n.º 25
0
 public Comment AddComment(Comment comment)
 {
     return(repository.Add(comment));
 }
        public void CreateNews_WhenNewsIsInvalid_ShouldThrowException()
        {
            var repo = new NewsRepository(new NewsContext());
            var invalidNews = new Models.News()
            {
                Title = null,
                Content = "bla bla",
                PublishDate = DateTime.Now
            };

            repo.Add(invalidNews);
            repo.SaveChanges();

            // Assert -> expect an exception
        }
Ejemplo n.º 27
0
 public Topic AddTopic(Topic topic)
 {
     return(repository.Add(topic));
 }
Ejemplo n.º 28
0
 public Mapping AddMapping(Mapping mapping)
 {
     return(repository.Add(mapping));
 }
Ejemplo n.º 29
0
 public User AddUser(User user)
 {
     return(repository.Add(user));
 }
Ejemplo n.º 30
0
 public IActionResult Add([FromBody] News news)
 {
     _newsRepository.Add(news);
     return(Ok(news.Id));
 }