public void GetPostById_ReturnCorrectPost()
        {
            // Arrange
            var mockManager = new Mock <IPostManager>();

            mockManager.Setup(x => x.GetPostById(It.IsAny <Guid>()))
            .Returns <Guid>(id => GetTestPostById(id));

            var testPostController = new PostsController(mockManager.Object);

            // Act
            var post = testPostController.GetPostById(TestPost1.Id);

            //Assert
            TestPost1.AssertAreEqual(post);
        }
Пример #2
0
        public void SavePost_SavesPost()
        {
            TestAuthor = new Authors()
            {
                Id        = Guid.NewGuid(),
                FirstName = "Jan",
                LastName  = "Podskalicky",
                Email     = "*****@*****.**",
                Password  = "******",
                Phone     = "0",
                Username  = "******"
            };

            testDBContext.Authors.Add(TestAuthor);

            TestCategory = new Categories
            {
                Id   = Guid.NewGuid(),
                Name = "Test category"
            };

            testDBContext.Categories.Add(TestCategory);

            testDBContext.SaveChanges();

            var testPostDto = new PostDto()
            {
                Id         = Guid.NewGuid(),
                Title      = "Test Post 1",
                Perex      = "This is a test post 1",
                Content    = "This is a text of test post 1",
                Author     = testAutoMapper.Map <AuthorDto>(TestAuthor),
                Categories = new List <CategoryDto>()
                {
                    testAutoMapper.Map <CategoryDto>(TestCategory),
                }
            };

            TestPostsCategories = new PostsCategories
            {
                Id         = Guid.NewGuid(),
                CategoryId = TestCategory.Id,
                PostId     = testPostDto.Id
            };

            TestPostsCategoriesDto = testAutoMapper.Map <PostCategoryDto>(TestPostsCategories);

            var testPostManager = new PostManager(testDBContext, testAutoMapper);

            testPostManager.SavePost(testPostDto, new List <PostCategoryDto> {
                TestPostsCategoriesDto
            });

            var retrievedPost = testPostManager.GetPostById(testPostDto.Id);

            testPostDto.AssertAreEqual(retrievedPost);
        }
Пример #3
0
        public void GetPostById_ReturnCorrectPost()
        {
            AddTestPostsToDB();

            var testPostManager = new PostManager(testDBContext, testAutoMapper);

            var post = testPostManager.GetPostById(TestPost1.Id);

            TestPostDto1.AssertAreEqual(post);
        }