コード例 #1
0
ファイル: AuthorTest.cs プロジェクト: DayanePeres/BookStore
        public async Task ShouldPutAuthorById()
        {
            //Arrange
            var author = CreateAuthor();

            //Act
            var postResponse = (ObjectResult)await _controller.Post(author);

            var authorResponse = (AuthorEntity)postResponse.Value;

            author.Name = "JoaoAtualizado";

            var putResponse = (ObjectResult)await _controller.Put(author, authorResponse.Id);

            var respPut = (AuthorEntity)putResponse.Value;

            var getAllResponse = (ObjectResult)await _controller.GetAll();

            var authorList = (IEnumerable <AuthorEntity>)getAllResponse.Value;

            //Assert
            Assert.AreEqual(200, (int)((OkObjectResult)postResponse).StatusCode);
            Assert.AreEqual(200, (int)((OkObjectResult)putResponse).StatusCode);
            Assert.AreEqual(respPut.Name, author.Name);
            Assert.AreEqual(2, authorList.Count());
        }
コード例 #2
0
        public async void UpdateAuthorTest()
        {
            AuthorController authorController = new AuthorController(new AuthorRepository(_dataContext));

            var author = (Author)((OkObjectResult)await authorController.GetAuthorByName("TesteController")).Value;

            author.Name = "Daniel";
            await authorController.Put(author);

            var result = (OkObjectResult)await authorController.Get("Daniel");

            Assert.NotNull(result.Value);
        }
コード例 #3
0
        public async Task PutReturnAcceptedResult()
        {
            //Arrange

            _authorRepositoryMock.Setup(x => x.GetAsync(1)).Returns(Task.FromResult <Author>(Builder <Author> .CreateNew().With(x => x.Name = "teste")
                                                                                             .With(x => x.Id = 1).Build()));


            //Act
            var result = await _authorController.Put(1, Builder <AuthorModel> .CreateNew().Build());


            //Assert
            Assert.NotNull(result);

            Assert.IsType <AcceptedResult>(result);
            var objResult = result as AcceptedResult;


            var contentResult = objResult.Value as AuthorModel;

            Assert.NotNull(contentResult);
            Assert.Equal(1, contentResult.Id);
        }
コード例 #4
0
        public async Task ShouldPutAuthorById()
        {
            Author author = new Author
            {
                Name = "Comedy"
            };

            ObjectResult responsePost = (ObjectResult)await _controller.Post(author);

            Author respPost = (Author)responsePost.Value;

            author.Name = "Action";

            ObjectResult responsePut = (ObjectResult)await _controller.Put(author, respPost.Id);

            Author respPut = (Author)responsePost.Value;

            Assert.AreEqual(200, (int)responsePost.StatusCode);
            Assert.AreEqual(200, (int)responsePut.StatusCode);
            Assert.AreEqual(respPut.Name, author.Name);
        }
コード例 #5
0
        public async void Task_Update_Author_Return_NotFound()
        {
            //Arrange
            var controller = new AuthorController(context);
            var AuthorId   = 21;

            var author = new Author()
            {
                AuthorId          = 1,
                AuthorName        = "Kate Bowler",
                AuthorDescription = "Kate Bowler is an assistant professor of the history of Christianity in North America at Duke Divinity School. She is the author of Blessed: A History of the American Prosperity Gospel and Everything Happens for a Reason, which was a New York Times hardcover nonfiction best seller.",
                AuthorImage       = "https://katebowler.com/wp-content/uploads/2017/09/kate-sidebar.jpg"
            };

            //Act

            var data = await controller.Put(AuthorId, author);

            //Assert

            Assert.IsType <NotFoundResult>(data);
        }
コード例 #6
0
        public async void Task_Update_Author_Return_NotFound()
        {
            //Arrange
            var controller = new AuthorController(context);
            var AuthorId   = 21;

            var author = new Author()
            {
                AuthorId          = 1,
                AuthorName        = "Delhi Publisher",
                AuthorDescription = "New Delhi Publishers is an International repute publisher with an orientation towards research, practical and Technical Applications.",
                AuthorImage       = "123"
            };

            //Act

            var data = await controller.Put(AuthorId, author);

            //Assert

            Assert.IsType <NotFoundResult>(data);
        }
コード例 #7
0
        public async void Task_Update_Author_Return_OkResult()
        {
            //Arrange
            var controller = new AuthorController(context);
            int id         = 2;


            var author = new Author()
            {
                AuthorId          = 2,
                AuthorName        = "Kate Bowler",
                AuthorDescription = "Professor",
                AuthorImage       = "123"
            };

            //Act

            var updateData = await controller.Put(id, author);

            //Assert
            Assert.IsType <OkObjectResult>(updateData);
        }