Ejemplo n.º 1
0
        public void ContentItemController_Put_Validation_Test()
        {
            // Arrange
            Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Add(It.IsAny<ContentItem>()));
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem item = new ContentItem()
            {
                HasChildren = false,
                SourceRef = string.Empty,
                SourceURL = string.Empty
            };

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
            Assert.AreEqual(false, target.ModelState.IsValid);
            Assert.AreEqual(3, target.ModelState.Count);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }