Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        public void ContentItemController_Get_Test()
        {
            // Arrange
            Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Find(It.IsAny<long>(), It.IsAny<int>())).Returns(new ContentItem()
            {
                Children = new ContentItem[2]
            });
            ContentItemController target = new ContentItemController(mock.Object);

            // Act
            IHttpActionResult result = target.Get(1);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult<ContentItem>);
            Assert.AreEqual(2, (result as OkNegotiatedContentResult<ContentItem>).Content.Children.Length);
            mock.Verify(verify => verify.Find(It.IsAny<long>(), It.IsAny<int>()), Times.Once);
        }
Пример #4
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);
        }
Пример #5
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);
        }