Пример #1
0
        public void TimelineController_GetAll_Test()
        {
            // Arrange
            Mock<ITimelineService> mock = new Mock<ITimelineService>(MockBehavior.Strict);
            mock.Setup(setup => setup.GetAllPublicTimelinesWithoutContentItems()).Returns(new List<Entities.Timeline>()
            {
                new Timeline()
                {
                    Id = 1,
                    BeginDate = 1000,
                    EndDate = 1500,
                    Title = "Test 1"
                },
                new Timeline()
                {
                    Id = 2,
                    BeginDate = 1555,
                    EndDate = 1666,
                    Title = "Test 2"
                }
            });
            TimelineController target = new TimelineController(mock.Object);

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult<IEnumerable<Timeline>>);
            Assert.AreEqual(2, ((OkNegotiatedContentResult<IEnumerable<Timeline>>) result).Content.Count());
            mock.Verify(verify => verify.GetAllPublicTimelinesWithoutContentItems(), Times.Once);
        }
Пример #2
0
        public void TimelineController_Get_BadRequest_Test()
        {
            // Arrange
            Mock<ITimelineService> mock = new Mock<ITimelineService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Get(It.IsAny<int>())).Throws(new Exception());
            TimelineController target = new TimelineController(mock.Object);

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Пример #3
0
        public void TimelineController_Get_Test()
        {
            // Arrange
            Mock<ITimelineService> mock = new Mock<ITimelineService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Get(It.IsAny<int>())).Returns(new Entities.Timeline()
            {
                Id =12
            });
            TimelineController target = new TimelineController(mock.Object);

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

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult<Timeline>);
            Assert.AreEqual(12, (result as OkNegotiatedContentResult<Timeline>).Content.Id);
            mock.Verify(verify => verify.Get(It.IsAny<int>()), Times.Once);
        }