Exemple #1
0
        public void CreateNews_WithCorrectData_ShouldCreateNewsAndReturn201Created()
        {
            // Arrange
            var news = new CreateNewInputModel()
            {
                Title   = "Test news #1",
                Content = "Test content #1",
            };

            this.dataLayerMocked.IsChangeSaved = false;

            var controller = new NewsController(this.dataLayerMocked);

            this.SetupController(controller, "news");

            // Act
            var httpResponse    = controller.CreateNew(news).ExecuteAsync(new CancellationToken()).Result;
            var newsFromService = httpResponse.Content.ReadAsAsync <News>().Result;

            // Arrange
            Assert.IsTrue(this.dataLayerMocked.IsChangeSaved);
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.AreEqual(news.Title, newsFromService.Title);
            Assert.AreEqual(news.Content, newsFromService.Content);
        }
Exemple #2
0
        public void CreateNews_WithIncorrectData_ShouldReturnBadRequestWithOutAddingTheNews()
        {
            // Arrange
            var controller = new NewsController(this.dataLayerMocked);

            this.SetupController(controller, "news");

            // Act
            var httpResponse    = controller.CreateNew(null).ExecuteAsync(new CancellationToken()).Result;
            var httpGetResponse = controller.GetAllNews().ExecuteAsync(new CancellationToken()).Result;
            var newsFromService = httpGetResponse.Content.ReadAsAsync <News[]>().Result;

            // Arrange
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
            Assert.AreEqual(0, newsFromService.Count());
        }