Ejemplo n.º 1
0
        public void TimelineService_Add_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.Add(It.IsAny<Timeline>()))
                .Callback((Timeline Timeline) => Timeline.Id = 123)
                .Returns((Timeline Timeline) => { return Timeline; });
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            Timeline result = target.Add(new Timeline()
            {
                Title = "1ste wereld oorlog",
                BeginDate = 1914M,
                EndDate = 1918M
            });

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(123, result.Id);
            Assert.AreEqual("1ste wereld oorlog", result.Title);
            Assert.AreEqual(1914M, result.BeginDate);
            Assert.AreEqual(1918M, result.EndDate);
            mock.Verify(verify => verify.Add(It.IsAny<Timeline>()), Times.Once);
        }
Ejemplo n.º 2
0
        public void TimelineService_GetAllPublicTimelinesWithoutContentItems_Exception_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.FindAllPublicTimelines()).Throws(new Exception());
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.GetAllPublicTimelinesWithoutContentItems();
        }
Ejemplo n.º 3
0
        public void TimelineService_Add_DontCatchException_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.Add(It.IsAny<Timeline>())).Throws(new Exception());
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.Add(new Timeline());
        }
Ejemplo n.º 4
0
        public void TimelineService_GetAllPublicTimelinesWithoutContentItems_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.FindAllPublicTimelines()).Returns(new List<Timeline>()
            {
                new Timeline()
                {
                    Id = 1,
                    Title = "1ste wereld oorlog",
                    BeginDate = 1914M,
                    EndDate = 1918M,
                    IsPublic = true
                },
                new Timeline()
            });
            TimelineService target = new TimelineService(mock.Object, null);

            // Act
            IEnumerable<Timeline> result = target.GetAllPublicTimelinesWithoutContentItems();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
            Timeline firstResult = result.First();
            Assert.AreEqual((long)1, firstResult.Id);
            Assert.AreEqual("1ste wereld oorlog", firstResult.Title);
            Assert.AreEqual(1914M, firstResult.BeginDate);
            Assert.AreEqual(1918M, firstResult.EndDate);
            Assert.AreEqual(null, firstResult.RootContentItem);
            mock.Verify(verify => verify.FindAllPublicTimelines(), Times.Once);
        }
Ejemplo n.º 5
0
        public void TimelineService_Update_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.Update(It.IsAny<Timeline>()));
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);
            Timeline timeline = new Timeline();

            // Act
            target.Update(timeline);
            mock.Verify(verify => verify.Update(timeline), Times.Once);
        }
Ejemplo n.º 6
0
        public void TimelineService_Get_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.Find(It.IsAny<long>())).Returns(new Timeline()
            {
                Id = 1,
                RootContentItemId = 123,
                Title = "1ste wereld oorlog",
                BeginDate = 1914M,
                EndDate = 1918M
            });
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            contentItemMock.Setup(setup => setup.Find(It.IsAny<long>(), It.IsAny<int>())).Returns(new ContentItem()
            {
                Children = new ContentItem[2]
            });
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

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

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual((long)1, result.Id);
            Assert.AreEqual("1ste wereld oorlog", result.Title);
            Assert.AreEqual(1914M, result.BeginDate);
            Assert.AreEqual(1918M, result.EndDate);
            Assert.IsNotNull(result.RootContentItem);
            Assert.AreEqual(2, result.RootContentItem.Children.Count());
            mock.Verify(verify => verify.Find(It.IsAny<long>()), Times.Once);
            contentItemMock.Verify(verify => verify.Find(result.RootContentItemId, It.IsAny<int>()), Times.Once);
        }
Ejemplo n.º 7
0
        public void TimelineService_Get_NotFoundException_Test()
        {
            // Arrange
            Mock<ITimelineDao> mock = new Mock<ITimelineDao>(MockBehavior.Strict);
            Mock<IContentItemDao> contentItemMock = new Mock<IContentItemDao>(MockBehavior.Strict);
            mock.Setup(setup => setup.Find(It.IsAny<long>())).Throws(new TimelineNotFoundException());
            TimelineService target = new TimelineService(mock.Object, contentItemMock.Object);

            // Act
            target.Get(-1);
        }