示例#1
0
        public void PutNewsItem_NoContent()
        {
            // Arrange
            var controller = new NewsItemsController();

            // Act
            var response = (StatusCodeResult)controller.PutNewsItem(1, new XsollaSummerSchoolTest.NewsItem {
                Headline = "Test put", Body = "Test put", Category = "Test"
            });

            // Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
示例#2
0
        public void PutNewsItem_NotFound()
        {
            // Arrange
            var controller = new NewsItemsController();

            // Act
            var response = controller.PutNewsItem(-4, new XsollaSummerSchoolTest.NewsItem {
                Headline = "Test put", Body = "Test put", Category = "Test"
            });
            var result = response as NotFoundResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void PutNewsItem_OK() // difficult to understand whether this test checks the scenario if a client behavior is correct
        {
            // Arrange
            var controller = new NewsItemsController();

            // Act
            var response = (StatusCodeResult)controller.PutNewsItem(1, new NewsItem
            {
                Headline = "Test put",
                Body     = "Test put",
                Category = "Test"
            });

            // Assert
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
            // might be a good idea to check whether the operation was successful or not
        }
        public void PutNewsItem_FailBadRequest()
        {
            // Arrange
            var controller = new NewsItemsController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            controller.ModelState.AddModelError("Body", "The Body field is required.");

            // Act
            var response = controller.PutNewsItem(1, new NewsItem {
                Headline = "Test put", Category = "Test"
            });
            var result = response as InvalidModelStateResult;

            // Assert
            Assert.IsNotNull(result);
        }