Summary description for New
Esempio n. 1
0
        public static bool CreatePost(string PostTitle, string Post, int AuthorID, DateTime DatePosted)
        {
            //context should be hidden behind an interface probably
            string uname = HttpContext.Current.User.Identity.Name;
            NewsItem item = new NewsItem()
            {
                Title = PostTitle,
                Content = Post,
                UserId = AuthorID,
                CreatedOn = DatePosted,
                ModifiedOn = DatePosted,
                CreatedBy = uname,
                ModifiedBy = uname
            };

            var ctx = new Models.ICCData();

            ctx.NewsItems.InsertOnSubmit(item);

            ctx.SubmitChanges();
            return true;
        }
		private void detach_NewsItems(NewsItem entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
		private void attach_NewsItems(NewsItem entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
 partial void DeleteNewsItem(NewsItem instance);
 partial void UpdateNewsItem(NewsItem instance);
 partial void InsertNewsItem(NewsItem instance);
        public void PostNewsItem_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Title = "ThirdNews",
                Content = "ThirdNewsContent",
                PublishDate = DateTime.Now.AddDays(8)
            };

            // Act
            var httpResponse = controller.PostNewsItem(newNewsItem).ExecuteAsync(new CancellationToken()).Result;
            var content = httpResponse.Content.ReadAsStringAsync().Result;
            var resultNews = JsonConvert.DeserializeObject<NewsItem>(content);

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);

            Assert.IsNotNull(resultNews.PublishDate);
            Assert.AreEqual(newNewsItem.Title, resultNews.Title);
            Assert.AreEqual(newNewsItem.Content, resultNews.Content);
        }
        public void PostNewsItem_WithInvalidData_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Title = "Bad Item",
                PublishDate = DateTime.Now.AddDays(8)
            };

            // Act
            var httpResponseMessage = controller.PostNewsItem(newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseMessage.StatusCode);
        }
        public void ModifyNonExistingNewsItem_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Id = 4,
                Title = "fourt",
                Content = "fourt",
                PublishDate = DateTime.Now
            };

            // Act
            var resultPostAction = controller.PutNewsItem(4, newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, resultPostAction.StatusCode);
        }
        public void ModifyNewsItem_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Id = 2,
                Title = "fourt",
                Content = "fourt",
                PublishDate = DateTime.Now
            };

            // Act
            var resultPostAction = controller.PutNewsItem(2, newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, resultPostAction.StatusCode);

            // Update retern only HttpStatusCode.OK
            //var content = resultPostAction.Content.ReadAsStringAsync().Result;
            //var resultNews = JsonConvert.DeserializeObject<NewsItem>(content);

            //Assert.IsNotNull(resultNews.PublishDate);
            //Assert.AreEqual(newNewsItem.Title, resultNews.Title);
            //Assert.AreEqual(newNewsItem.Content, resultNews.Content);
        }