Пример #1
0
        public void _Call_PostRepository_Update(int id, string title, string description, CategoryEnum categoryEnum)
        {
            //Arrange
            var Post                 = new Post();
            var category             = new Category();
            var mockedPostRepository = new Mock <IRepository <Post> >();

            mockedPostRepository.Setup(r => r.GetById(It.IsAny <int>())).Returns(Post);

            var mockedUserService = new Mock <IUserService>();
            var mockedUnitOfWork  = new Mock <IUnitOfWork>();
            var mockedPostFactory = new Mock <IPostFactory>();

            var mockedCategoryService = new Mock <ICategoryService>();

            mockedCategoryService.Setup(m => m.GetCategoryByName(It.IsAny <CategoryEnum>())).Returns(category);

            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var postService = new PostsService(
                mockedPostRepository.Object,
                mockedUserService.Object,
                mockedUnitOfWork.Object,
                mockedPostFactory.Object,
                mockedCategoryService.Object,
                mockedDateTimeProvider.Object);

            //Act
            postService.EditPost(id, title, description, categoryEnum);

            //Assert
            mockedPostRepository.Verify(r => r.Update(Post), Times.Once);
        }
Пример #2
0
        public void _Should_Set_description_Correctly(int id, string title, string description, CategoryEnum categoryEnum)
        {
            //Arrange
            var Post     = new Post();
            var category = new Category();

            var mockedPostRepository = new Mock <IRepository <Post> >();

            mockedPostRepository.Setup(r => r.GetById(It.IsAny <int>())).Returns(Post);

            var mockedUserService = new Mock <IUserService>();
            var mockedUnitOfWork  = new Mock <IUnitOfWork>();
            var mockedPostFactory = new Mock <IPostFactory>();

            var mockedCategoryService = new Mock <ICategoryService>();

            mockedCategoryService.Setup(m => m.GetCategoryByName(It.IsAny <CategoryEnum>())).Returns(category);

            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var postService = new PostsService(
                mockedPostRepository.Object,
                mockedUserService.Object,
                mockedUnitOfWork.Object,
                mockedPostFactory.Object,
                mockedCategoryService.Object,
                mockedDateTimeProvider.Object);

            //Act
            postService.EditPost(id, title, description, categoryEnum);

            //Assert
            Assert.AreEqual(Post.Description, description);
        }
Пример #3
0
        public void _Call_CategporyService_GetCategoryByName(int id, string title, string description, CategoryEnum categoryEnum)
        {
            //Arrange
            var mockedPostRepository   = new Mock <IRepository <Post> >();
            var mockedUserService      = new Mock <IUserService>();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedPostFactory      = new Mock <IPostFactory>();
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var postService = new PostsService(
                mockedPostRepository.Object,
                mockedUserService.Object,
                mockedUnitOfWork.Object,
                mockedPostFactory.Object,
                mockedCategoryService.Object,
                mockedDateTimeProvider.Object);

            //Act
            postService.EditPost(id, title, description, categoryEnum);

            //Assert
            mockedCategoryService.Verify(r => r.GetCategoryByName(categoryEnum), Times.Once);
        }