Example #1
0
        public void ContentItemService_Add_Test()
        {
            // Arrange
            Mock <IContentItemDao> mock = new Mock <IContentItemDao>(MockBehavior.Strict);

            mock.Setup(setup => setup.Add(It.IsAny <ContentItem>()))
            .Callback((ContentItem contentItem) => contentItem.Id = 123)
            .Returns((ContentItem contentItem) => { return(contentItem); });
            ContentItemService target = new ContentItemService(mock.Object);

            // Act
            ContentItem result = target.Add(new ContentItem()
            {
                Title       = "Bevrijding",
                BeginDate   = 1945M,
                EndDate     = 1945M,
                SourceURL   = "UrlNaSource",
                HasChildren = false,
            });

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(123, result.Id);
            Assert.AreEqual("Bevrijding", result.Title);
            Assert.AreEqual(1945M, result.BeginDate);
            Assert.AreEqual(1945M, result.EndDate);
            Assert.AreEqual("UrlNaSource", result.SourceURL);
            Assert.AreEqual(false, result.HasChildren);
            mock.Verify(verify => verify.Add(It.IsAny <ContentItem>()), Times.Once);
        }
Example #2
0
        public void ContentItemService_Add_DontCatchException_Test()
        {
            // Arrange
            Mock <IContentItemDao> mock = new Mock <IContentItemDao>(MockBehavior.Strict);

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

            // Act
            target.Add(new ContentItem());
        }