Example #1
0
        public void ContentItemController_Post_Validation_Test()
        {
            // Arrange
            Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <ContentItem>()));
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem           item   = new ContentItem()
            {
                HasChildren = false,
                Id          = 0,
                SourceRef   = string.Empty,
                SourceURL   = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate <ContentItem>(item);
            IHttpActionResult result = target.Post(item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
            Assert.AreEqual(false, target.ModelState.IsValid);
            Assert.AreEqual(3, target.ModelState.Count);
        }
Example #2
0
        public void ContentItemController_Post_InvalidID_Test()
        {
            // Arrange
            Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <ContentItem>()));
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem           item   = new ContentItem()
            {
                BeginDate   = -1,
                EndDate     = -1,
                Title       = "test",
                ParentId    = 1,
                HasChildren = false,
                Id          = 0,
                SourceRef   = string.Empty,
                SourceURL   = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate <ContentItem>(item);
            IHttpActionResult result = target.Post(item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Example #3
0
        public void ContentItemController_Post_Test()
        {
            // Arrange
            Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Add(It.IsAny <ContentItem>())).Returns(new ContentItem()
            {
                Id = 123
            });
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem           item   = new ContentItem()
            {
                BeginDate   = -1,
                EndDate     = -1,
                Title       = "test",
                ParentId    = 1,
                HasChildren = false,
                SourceRef   = string.Empty,
                SourceURL   = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate <ContentItem>(item);
            IHttpActionResult result = target.Post(item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult <ContentItem>);
            Assert.AreEqual(123, (result as OkNegotiatedContentResult <ContentItem>).Content.Id);
            mock.Verify(verify => verify.Add(It.IsAny <ContentItem>()), Times.Once);
        }
Example #4
0
        public void ContentItemController_Post_BadRequest_Test()
        {
            // Arrange
            Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <ContentItem>())).Throws(new Exception());
            ContentItemController target = new ContentItemController(mock.Object);

            // Act
            IHttpActionResult result = target.Post(new ContentItem());

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }