Ejemplo n.º 1
0
        public void GetById_NonExistingIdPassed_ReturnsNotFoundResult()
        {
            // Act
            var notFoundResult = _controller.GetById(8);

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
        public void TestGetById()
        {
            List <Post> posts = new List <Post>();

            posts.Add(post);
            IEnumerable <Post> iEnumerablePost = posts;

            mockPostService.Setup(x => x.GetById(It.IsAny <string>())).Returns(post);
            var           _postController = new PostController(mockPostService.Object);
            IActionResult getPost         = _postController.GetById("asd6dssds5dasfdaf5f");
            var           type            = getPost.GetType();

            Assert.AreEqual(type.Name, "OkObjectResult");
        }
Ejemplo n.º 3
0
        public async Task GetById_ShouldReturn_NotFound_ForAbsentItem(int id)
        {
            var mock = new Mock <IPostRepository>();

            mock.Setup(repo => repo.Find(id)).Returns(Task.FromResult((Post)null));
            var controller = new PostController(mock.Object);

            var actionResult = await controller.GetById(id);

            Assert.IsNotNull(actionResult);

            NotFoundResult result = actionResult as NotFoundResult;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 4
0
        public async Task GetById_ShouldReturn_Success_ForSinglePost()
        {
            var dbPost = DbInitializer.GenerateListOfPost()[0];

            var mock = new Mock <IPostRepository>();

            mock.Setup(repo => repo.Find(dbPost.Id)).Returns(Task.FromResult(dbPost));
            var controller = new PostController(mock.Object);

            var actionResult = await controller.GetById(dbPost.Id);

            Assert.IsNotNull(actionResult);

            OkObjectResult result = actionResult as OkObjectResult;

            Assert.IsNotNull(result);

            var resultValue = result.Value as PostEnhanceDTO;

            Assert.AreEqual(dbPost.Text, resultValue.Text);
        }
        public void Post_GetById_ExistingId_ReturnsPost()
        {
            var result = _postController.GetById(_post1.PostId);

            Assert.Equal(_post1, result.Value);
        }