public void Post_AddPost_ExistingOwner_AddsPost()
        {
            var newpost = new PostDTO()
            {
                Title = "Test", Body = "Test", OwnerId = _jarne.UserId
            };
            var result = _postController.AddPost(newpost);

            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
        public async void Task_Add_ValidData_Return_OkResult()
        {
            var post = new Post()
            {
                Title = "Test Title 3", Description = "Test Description 3", CategoryId = 2, CreatedDate = DateTime.Now
            };

            //Act
            var data = await _controller.AddPost(post);

            //Assert
            Assert.IsType <OkObjectResult>(data);
        }
Exemplo n.º 3
0
        public async void Task_Add_InvalidData_Return_BadRequest()
        {
            //Arrange
            var  controller = new PostController(repository);
            Post post       = new Post()
            {
                Title = "Test Title More Than 20 Characteres", Description = "Test Description 3", CategoryId = 3, CreatedDate = DateTime.Now
            };

            //Act
            var data = await controller.AddPost(post);

            //Assert
            Assert.IsType <BadRequestResult>(data);
        }
Exemplo n.º 4
0
        public void AddPost_Test()
        {
            // arrange
            mockRepo.Setup(repo => repo.Posts.FindByCondition(u => u.ID == It.IsAny <int>())).Returns(GetPosts());
            mockRepo.Setup(repo => repo.Users.FindByCondition(u => u.ID == It.IsAny <int>())).Returns(GetUsers());


            AddPost potentialPost = new AddPost()
            {
                Type = "Looking for player", Platform = "PS5", PlayerRating = "87", Position = "RW", Description = "test description"
            };
            // act
            var controllerJsonResult = postController.AddPost(potentialPost, 2);

            // assert
            Assert.NotNull(controllerJsonResult);
            Assert.IsType <JsonResult>(controllerJsonResult);
        }
Exemplo n.º 5
0
        public async void Task_Add_ValidData_MatchResult()
        {
            //Arrange
            var controller = new PostController(repository);
            var post       = new Post()
            {
                Title = "Test Title 4", Description = "Test Description 4", CategoryId = 2, CreatedDate = DateTime.Now
            };

            //Act
            var data = await controller.AddPost(post);

            //Assert
            Assert.IsType <OkObjectResult>(data);

            var okResult = data.Should().BeOfType <OkObjectResult>().Subject;

            // var result = okResult.Value.Should().BeAssignableTo<PostViewModel>().Subject;

            Assert.Equal(3, okResult.Value);
        }