Example #1
0
        public void CreateOrUpdateArticleTest()
        {
            // Arrage
            var id       = new Guid("5d3e7d9f-66c2-4d3d-084e-08d8aa7ba44c");
            var expected = new ArticleDTO()
            {
                Id              = id,
                Title           = "ArticleTest",
                Summary         = "SummeryTest",
                HtmlContent     = "<H1>Hello world</H1>",
                MarkdownContent = "MarkdownContentTest",
                CategoryId      = new Guid("ac6b1480-47c8-41b9-843c-9979340d3715"),
                IsPublished     = true,
                CreationTime    = new DateTime(),
                PageName        = "PagenameTest",
                Cover           = "CoverTest",
                ContentLanguage = "en",
                Views           = 0,
                Likes           = 0,
            };

            var mockArticleRepo = new Mock <IArticleRepository>();

            var mockArticleTagRepo = new Mock <IArticleTagRepository>();

            var mockArticleSEO = new Mock <IArticleSEORepository>();

            var mockTagRepo = new Mock <ITagRepository>();

            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(repo => repo.ArticleRepository)
            .Returns(mockArticleRepo.Object);

            mockUow.Setup(repo => repo.ArticleTagRepository)
            .Returns(mockArticleTagRepo.Object);

            mockUow.Setup(repo => repo.TagRepository)
            .Returns(mockTagRepo.Object);

            mockUow.Setup(repo => repo.ArticleSEORepository)
            .Returns(mockArticleSEO.Object);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperProfile()); //your automapperprofile
            });

            IMapper mapper = mockMapper.CreateMapper();

            var manager = new ArticleManager(mockUow.Object, mapper);

            // Act

            var actual = manager.CreateOrUpdate(expected);

            // Assert

            mockArticleRepo.Verify(x => x.InsertOrUpdate(It.IsAny <Article>()));
            // To Do
            //mockArticleTagRepo.Verify(x => x.Insert(It.IsAny<Article>()));
            mockUow.Verify(x => x.Save());
        }