Esempio 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);
        }
Esempio n. 2
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());
        }