Пример #1
0
        public void ContentItemController_Put_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          = 1,
                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 OkResult);
            mock.Verify(verify => verify.Update(It.IsAny <ContentItem>()), Times.Once);
        }
Пример #2
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);
        }
Пример #3
0
        public void ContentItemController_Put_BadRequest_Test()
        {
            // Arrange
            Mock <IContentItemService> mock = new Mock <IContentItemService>(MockBehavior.Strict);

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

            // Act
            IHttpActionResult result = target.Put(0, new ContentItem());

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