Пример #1
0
        public void TimelineController_Post_Test()
        {
            // Arrange
            Mock <ITimelineService> mock = new Mock <ITimelineService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Add(It.IsAny <Timeline>())).Returns(new Timeline()
            {
                Id = 123
            });
            TimelineController target   = new TimelineController(mock.Object);
            Timeline           timeline = new Timeline()
            {
                BeginDate       = -1,
                EndDate         = -1,
                Title           = "test",
                RootContentItem = null
            };

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult <long>);
            Assert.AreEqual((long)123, (result as OkNegotiatedContentResult <long>).Content);
            mock.Verify(verify => verify.Add(It.IsAny <Timeline>()), Times.Once);
        }
Пример #2
0
        public void TimelineController_Post_BadRequest_Test()
        {
            // Arrange
            Mock <ITimelineService> mock = new Mock <ITimelineService>(MockBehavior.Strict);

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

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Пример #3
0
        public void TimelineController_Post_InvalidID_Test()
        {
            // Arrange
            Mock <ITimelineService> mock = new Mock <ITimelineService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <Timeline>()));
            TimelineController target   = new TimelineController(mock.Object);
            Timeline           timeline = new Timeline()
            {
                BeginDate = -1,
                EndDate   = -1,
                Title     = "test"
            };

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Пример #4
0
        public void TimelineController_Post_Validation_Test()
        {
            // Arrange
            Mock <ITimelineService> mock = new Mock <ITimelineService>(MockBehavior.Strict);

            mock.Setup(setup => setup.Update(It.IsAny <Timeline>()));
            TimelineController target   = new TimelineController(mock.Object);
            Timeline           timeline = new Timeline()
            {
                RootContentItem = null
            };

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
            Assert.AreEqual(false, target.ModelState.IsValid);
            Assert.AreEqual(3, target.ModelState.Count);
        }