コード例 #1
0
        public async Task ShouldPostAuthors()
        {
            Author author = new Author
            {
                Name = "Comedy"
            };

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

            Author respPost = (Author)responsePost.Value;

            ObjectResult responseGet = (ObjectResult)await _controller.Get(respPost.Id);

            Author respGet = (Author)responsePost.Value;

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

            var respGetAll = responseGetAll.Value.GetType()
                             .GetProperty("Count")
                             .GetValue(responseGetAll.Value);


            Assert.AreEqual(200, (int)responsePost.StatusCode);
            Assert.AreEqual(200, (int)responseGet.StatusCode);
            Assert.AreEqual(respGet.Id, respPost.Id);
            Assert.AreEqual(1, respGetAll);
        }
コード例 #2
0
        public async Task PostCreateNewAuthor()
        {
            ///Arrange
            var authorDbSetMock = Builder <AuthorModel> .CreateNew().Build();


            ///Act
            var result = await _authorController.Post(authorDbSetMock);

            ///Assert
            Assert.NotNull(result);

            var objectResult = Assert.IsType <CreatedResult>(result);
            var model        = Assert.IsAssignableFrom <Author>(objectResult.Value);
            var name         = model.Name;

            Assert.Equal("Name1", name);
        }
コード例 #3
0
        public async void CreateAuthorTest()
        {
            AuthorController authorController = new AuthorController(new AuthorRepository(_dataContext));

            await authorController.Post(_author);

            var result = (OkObjectResult)await authorController.GetAuthorByName("TesteController");

            Assert.NotNull(result.Value);
        }
コード例 #4
0
        private async Task <AuthorEntity> PostAuthor()
        {
            var author = new AuthorEntity
            {
                Name = "J.K Rowling"
            };
            var postResponse = (ObjectResult)await _authorController.Post(author);

            var authorResponse = (AuthorEntity)postResponse.Value;

            return(authorResponse);
        }
コード例 #5
0
        public void AuthorController_Post()
        {
            var mock = new Mock <IAuthorRepository>();

            mock.Setup(m => m.Create(It.IsAny <Author>())).Returns(1);

            var authorController = new AuthorController(mock.Object);
            var result           = authorController.Post(_testAuthor) as OkNegotiatedContentResult <int>;

            Assert.IsNotNull(result);
            mock.Verify(m => m.Create(It.IsAny <Author>()));
            Assert.AreEqual(result.Content, 1);
        }
コード例 #6
0
        public void Test7()
        {
            var    service = new AuthorController(null, _logger);
            Author author  = new Author()
            {
                Name = "A1"
            };

            var result = service.Post(author);

            Assert.AreEqual(500, result.StatusCode);
            Assert.AreEqual("Problem with database while adding", result.Value);
        }
コード例 #7
0
ファイル: AuthorTest.cs プロジェクト: DayanePeres/BookStore
        public async Task ShouldPostAuthors()
        {
            //Arrange
            var author = CreateAuthor();

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

            author = (AuthorEntity)postResponse.Value;

            var getResponse = (ObjectResult)await _controller.Get(author.Id);

            var authorResponse = (AuthorEntity)getResponse.Value;

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

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

            //Assert
            Assert.AreEqual(200, postResponse.StatusCode);
            Assert.AreEqual(200, getResponse.StatusCode);
            Assert.AreEqual(author.Id, authorResponse.Id);
            Assert.AreEqual(1, authorList.Count());
        }
コード例 #8
0
        public async void Task_Add_Author_Return_BadRequest()
        {
            //Arrange
            var controller = new AuthorController(context);
            var author     = new Author()
            {
                AuthorName        = "Kate Bowler just to check max length here!!!!!!!!!!",
                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       = "123"
            };

            //Act

            var data = await controller.Post(author);

            //Assert
            Assert.IsType <BadRequestResult>(data);
        }
コード例 #9
0
        public async void Task_Add_Author_Return_OkResult()
        {
            //Arrange
            var controller = new AuthorController(context);
            var author     = new Author()
            {
                AuthorName        = "Kate Bowler",
                AuthorDescription = "Wrote Autobiography",
                AuthorImage       = "123"
            };

            //Act

            var data = await controller.Post(author);

            //Assert
            Assert.IsType <CreatedAtActionResult>(data);
        }
コード例 #10
0
        public async void Task_Add_Author_Return_BadRequest()
        {
            //Arrange
            var controller = new AuthorController(context);
            var author     = new Author()
            {
                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.Post(author);

            //Assert
            Assert.IsType <BadRequestResult>(data);
        }
コード例 #11
0
        public async void Task_Add_Author_Return_OkResult()
        {
            //Arrange
            var controller = new AuthorController(context);
            var author     = new Author()
            {
                //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 = "123"

                AuthorName        = "Paulo Coelho",
                AuthorDescription = "Paulo Coelho de Souza is a Brazilian lyricist and novelist. He is best known for his novel The Alchemist.In 2014, he uploaded his personal papers online to create a virtual Paulo Coelho Foundation.",
                AuthorImage       = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Paulo_Coelho_nrkbeta.jpg/330px-Paulo_Coelho_nrkbeta.jpg"
            };

            //Act

            var data = await controller.Post(author);

            //Assert
            Assert.IsType <CreatedAtActionResult>(data);
        }
コード例 #12
0
        public void Test8()
        {
            List <Author> authorsNew = new List <Author>()
            {
                new Author()
                {
                    Name = "A1"
                },
                new Author()
                {
                    Name = "B2"
                },
                new Author()
                {
                    Name = "B3"
                }
            };
            List <Author> authors = new List <Author>();

            database = GetDatabase(authors);
            var service = new AuthorController(database, _logger);

            foreach (var author in authorsNew)
            {
                var code = service.Post(author);
                Assert.AreEqual(200, code.StatusCode);
                Assert.AreEqual("Succesful adding", code.Value);
            }

            var result = service.Get();

            Assert.AreEqual(200, result.StatusCode);
            Assert.AreEqual(authorsNew.Count, authors.Count);
            for (int i = 0; i < authorsNew.Count; i++)
            {
                Assert.AreEqual(authorsNew[i].Name, authors[i].Name);
            }
        }
コード例 #13
0
 public async Task Test3()
 {
     ac = new AuthorController(_loggerA, authorService);
     var result = await ac.Post(new Author());
 }