public void TestEditAuthorPositive()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            authorsController.Put("newUsr");
        }
        public void TestEditAuthorNegative()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            authorsController.Put("");
        }
        public void TestAddAuthorPositive()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            authorsController.Post("{'username': '******'}");
        }
        public async Task GetAuthor_ValidId_ReturnedOkObjectResultNotNullStatusCode200()
        {
            //Arrange
            var config = new MapperConfiguration(cfg => {
                cfg.AddProfile(new AutoMapperProfiles());
            });
            var repository = new Mock <ILibraryRepository>();
            var mapper     = config.CreateMapper();

            repository.Setup(r => r.GetAuthor(It.IsInRange <int>(1, 3, Range.Inclusive))).ReturnsAsync(new  Author()
            {
                Id = 1, Name = "Jan", Surname = "Kowalski"
            });
            var controller = new AuthorsController(repository.Object, mapper);

            //Act
            var result = await controller.GetAuthor(1);

            var okObjectResult = result as OkObjectResult;
            var model          = okObjectResult.Value as AuthorForDetailedDto;

            //Assert
            Assert.NotNull(okObjectResult);
            Assert.Equal(200, okObjectResult.StatusCode);
            Assert.NotNull(model);
        }
Esempio n. 5
0
        public void DetailsShouldHaveAuthorInfoAndListAuthorBooks()
        {
            var author = new Author()
            {
                Id         = 3,
                Name       = "Author",
                Biography  = "Biography",
                PictureUrl = "Pic.jpg"
            };
            var books = new List <Book> {
                new Book(), new Book(), new Book(), new Book()
            };
            var mockedRepo = new Mock <Repository>();

            mockedRepo.Setup(repo => repo.Get <Author>(3)).Returns(author);
            mockedRepo.Setup(r => r.Search(It.IsAny <Expression <Func <Book, bool> > >())).Returns(books);
            var controller = new AuthorsController(mockedRepo.Object);


            var result = controller.Details(3);
            var model  = (AuthorViewModel)result.Model;

            AuthorsContollerTestHelper.AssertEqual(author, model.Author);
            Assert.AreEqual(4, model.Books.Count());
        }
 /// <summary>
 /// Connect to WordPress site with REST API. Easily access Posts, Media, Authors and Comments.
 ///
 /// Requires WP-REST-API V2 plugin installed on your WordPress site (Below V4.7). For information see http://v2.wp-api.org/
 /// </summary>
 /// <param name="Url">Url of your WordPress site. For example http://ZiaNasir.com/</param>
 public WordPressConnector(string Url)
 {
     Posts    = new PostsController(Url);
     Media    = new MediaController(Url);
     Authors  = new AuthorsController(Url);
     Comments = new CommentsController(Url);
 }
        public async Task GetAuthors_ReturnedOkObjectResultNotNullStatusCode200()
        {
            //Arrange
            var config = new MapperConfiguration(cfg => {
                cfg.AddProfile(new AutoMapperProfiles());
            });
            var repository = new Mock <ILibraryRepository>();
            var mapper     = config.CreateMapper();

            repository.Setup(r => r.GetAuthors()).ReturnsAsync(new List <Author>()
            {
                new Author(), new Author()
            });
            var controller = new AuthorsController(repository.Object, mapper);

            //Act
            var result = await controller.GetAuthors();

            var okObjectResult = result as OkObjectResult;
            var list           = okObjectResult.Value as List <AuthorForListDto>;

            //Assert
            Assert.NotNull(okObjectResult);
            Assert.Equal(200, okObjectResult.StatusCode);
            Assert.Equal(2, list.Count);
        }
        public void TestDeleteAuthorNegative()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            authorsController.Delete(-1);
        }
Esempio n. 9
0
        public void ShouldNotCreateExistingAuthor()
        {
            var model = new Author()
            {
                Name       = "Author",
                Biography  = "Biography",
                PictureUrl = "myPicture.jpg"
            };

            UsingSession((session) =>
            {
                var controller = new AuthorsController(new Repository(session));
                controller.Create(model);
            });

            UsingSession((session) =>
            {
                WaitForTheLastWrite <Author>(session);
                var controller = new AuthorsController(new Repository(session));
                var viewResult = (System.Web.Mvc.ViewResult)(controller.Create(model));

                Assert.AreEqual("An author with this name already exists", controller.TempData["flashError"]);

                Assert.AreEqual("", viewResult.MasterName);
            });
        }
Esempio n. 10
0
        public async Task GetAuthorsAsync_Test()
        {
            // Arrange
            var parameters = new AuthorsResourceParameters();
            var authors    = GetTestAuthorsData();

            authors.OrderBy(a => a.FirstName).ThenBy(a => a.LastName);
            var pagedAuthors = PagedList <Author> .Create(authors.AsQueryable(), parameters.PageNumber, parameters.PageSize);

            var mockRepo          = new Mock <ILibraryRepository>();
            var mockLinkGenerator = new Mock <LinkGenerator>();

            mockRepo.Setup(repo => repo.GetAuthorsAsync(parameters))
            .ReturnsAsync(pagedAuthors);
            var mapper     = new MapperConfiguration(cfg => cfg.AddProfile(new AuthorProfile())).CreateMapper();
            var controller = new AuthorsController(mockRepo.Object, mockLinkGenerator.Object, mapper);

            /// How to mock an HttpContext, ASP.NET Core provide a "fake" HttpContext named DefaultHttpContext.
            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            // Act
            var result = await controller.GetAuthorsAsync(parameters);

            // Assert
            var actionResult     = Assert.IsType <ActionResult <IEnumerable <AuthorDto> > >(result);
            var okResult         = Assert.IsType <OkObjectResult>(actionResult.Result);
            var returnAuthorDtos = Assert.IsAssignableFrom <IEnumerable <AuthorDto> >(okResult.Value);
        }
Esempio n. 11
0
        public void ShouldCreateNewAuthor()
        {
            var model = new Author()
            {
                Name       = "Author",
                Biography  = "Biography",
                PictureUrl = "myPicture.jpg"
            };
            RedirectToRouteResult actionResult = null;

            UsingSession((session) =>
            {
                var controller = new AuthorsController(new Repository(session));

                actionResult = (RedirectToRouteResult)(controller.Create(model));
                Assert.AreEqual("Authors", actionResult.RouteValues["controller"]);
                Assert.AreEqual("Details", actionResult.RouteValues["action"]);
            });

            UsingSession((session) =>
            {
                var author = WaitForTheLastWrite <Author>(session);
                Assert.AreEqual(author.Id, actionResult.RouteValues["id"]);
                AuthorsContollerTestHelper.AssertEqual(model, author);
            });
        }
Esempio n. 12
0
        public void ShouldOnlyListAuthorFirst4BooksInAuthorDetailPage()
        {
            var author1 = new Author()
            {
                Name       = "Author1",
                Biography  = "Biography1",
                PictureUrl = "myPicture1.jpg",
                CreatedAt  = DateTime.UtcNow
            };

            UsingSession((session) =>
            {
                var repository = new Repository(session);
                var controller = new AuthorsController(repository);
                controller.Create(author1);
                Enumerable.Range(1, 9)
                .ToList()
                .ForEach(i => repository.Create(new Book()
                {
                    Title = "Book " + i, Author = author1.Name, CreatedAt = DateTime.UtcNow.AddDays(-i)
                }));
            });

            UsingSession((session) =>
            {
                var author          = WaitForTheLastWrite <Author>(session);
                var controller      = new AuthorsController(new Repository(session));
                var viewResult      = controller.Details(author.Id);
                var authorViewModel = (AuthorViewModel)(viewResult.Model);
                Assert.AreEqual(4, authorViewModel.Books.Count);
                Assert.IsTrue(authorViewModel.HasMoreBooks);
            });
        }
Esempio n. 13
0
        void TestGettingAllAuthors()
        {
            var authors = new List <Author>
            {
                new Author()
                {
                    FirstName = "A", LastName = "B", DateOfBirth = new DateTime(1990, 11, 11)
                },
                new Author()
                {
                    FirstName = "D", LastName = "Q", DateOfBirth = new DateTime(1977, 01, 21)
                },
                new Author()
                {
                    FirstName = "C", LastName = "W", DateOfBirth = new DateTime(1960, 11, 13)
                },
            }.AsQueryable();
            var context = new Mock <IApplicationDbContext>();

            context.Setup(x => x.Authors).Returns(authors);

            _author = new AuthorsController(context.Object);

            var result = _author.Index("") as ViewResult;

            Assert.Equal(typeof(List <Author>), result.Model.GetType());
        }
Esempio n. 14
0
        public void ShouldRetrieveTheAuthorToEdit()
        {
            var author1 = new Author()
            {
                Name       = "Author1",
                Biography  = "Biography1",
                PictureUrl = "myPicture1.jpg",
                CreatedAt  = DateTime.UtcNow
            };

            UsingSession((session) =>
            {
                var controller = new AuthorsController(new Repository(session));
                controller.Create(author1);
            });

            UsingSession((session) =>
            {
                var author       = WaitForTheLastWrite <Author>(session);
                var controller   = new AuthorsController(new Repository(session));
                var viewResult   = controller.Edit(author.Id);
                var authorInView = (Author)(viewResult.Model);

                AuthorsContollerTestHelper.AssertEqual(author1, authorInView);
            });
        }
Esempio n. 15
0
        void TestCreatingAuthorsController()
        {
            var context = new Mock <IApplicationDbContext>();

            _author = new AuthorsController(context.Object);
            Assert.NotNull(_author);
        }
Esempio n. 16
0
        public void DeleteAuthor()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteAuthorDatabase")
                          .Options;
            var context = new ApplicationDbContext(options);

            var controller = new AuthorsController(context);



            using (var ctx = new ApplicationDbContext(options))
            {
                var author = new Author {
                    Firstname = "test", Lastname = "test"
                };
                ctx.Author.Add(author);
                ctx.SaveChanges();
            }

            var result = controller.DeleteConfirmed(1).Result;

            Assert.IsType <RedirectToActionResult>(result);
            using (var ctx = new ApplicationDbContext(options))
            {
                Assert.Equal(0, ctx.Author.Count());
                ctx.SaveChanges();
            }
        }
Esempio n. 17
0
        public void EditAuthor()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditAuthorDatabase")
                          .Options;
            var context = new ApplicationDbContext(options);

            var controller = new AuthorsController(context);



            using (var ctx = new ApplicationDbContext(options))
            {
                var author = new Author {
                    Firstname = "test", Lastname = "test"
                };
                ctx.Author.Add(author);
                ctx.SaveChanges();
            }

            var result = controller.Edit(1, new Author {
                Firstname = "edited", Lastname = "edited", BirthYear = 2000, Id = 1
            }).Result;

            Assert.IsType <RedirectToActionResult>(result);
            using (var ctx = new ApplicationDbContext(options))
            {
                var author = ctx.Author.Find(1);
                Assert.Equal("edited", author.Firstname);
                ctx.SaveChanges();
            }
        }
Esempio n. 18
0
        public void GetAllAuthors_ReturnsOkResultWithAuthors()
        {
            //with real manager, you are not doing a real unit test
            //test may fail because of controller or manager or repository

            //var repository=//create some repository
            //var manager = new SimpleAuthorManager(rep);

            //Soution-1 We should be using a Mock object to handle this

            var mock = new Mock <IAuthorManager>();

            mock
            .Setup(m => m.GetAllAuthors())
            .Returns(dummyAuthors);

            var authorManager = mock.Object;

            var controller = new AuthorsController(authorManager);

            var result = controller.GetAllAuthors();

            Assert.IsType <OkObjectResult>(result);

            var data = (result as OkObjectResult).Value;



            var list = data as IList <Author>;

            Assert.NotNull(list);
            Assert.Equal(2, list.Count);
            Assert.Equal(dummyAuthors, list);
        }
Esempio n. 19
0
        public void TestAuthorsGet()
        {
            //Arrange

            var           AuthorRepoMockClass = new Mock <IAuthorRepo>();
            List <Author> getAuthorsObj       = new List <Author>()
            {
                new Author {
                    Id = 1, FirstName = "Huma", LastName = "shadu", DOB = DateTime.Now, Email = "*****@*****.**", Book = null, Created = DateTime.Now
                },
                new Author {
                    Id = 2, FirstName = "John", LastName = "Doe", DOB = DateTime.Now, Email = "*****@*****.**", Book = null, Created = DateTime.Now
                }
            };

            AuthorRepoMockClass.Setup(x => x.GetAllAuthor()).Returns(getAuthorsObj);
            var authorsController = new AuthorsController(AuthorRepoMockClass.Object);

            ////Act
            List <Author> result = authorsController.Get();

            ////Assert
            Assert.AreEqual(result[0].FirstName, "Huma");
            Assert.AreEqual(result[1].Email, "*****@*****.**");
        }
        public async Task remove_book()
        {
            var controller = new AuthorsController(authorsRepository);

            var response = await controller.Delete("0") as ObjectResult;

            Assert.AreEqual(200, response.StatusCode);
        }
        public void TestDeleteAuthorPositive()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            //id of existing author
            authorsController.Delete(1);
        }
Esempio n. 22
0
        public void GetAuthor_ShouldNotFindAuthor()
        {
            var controller = new AuthorsController(GetTestAuthors());
            var result     = controller.GetAuthor(999);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
        }
Esempio n. 23
0
        public void GetAllAuthors_ShouldReturnAllAuthors()
        {
            var controller = new AuthorsController(GetTestAuthors());
            var result     = controller.GetAuthors() as TestAuthorDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }
        public void TestGetAuthors()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            IEnumerable <string> result = authorsController.Get();

            Assert.IsNotNull(result);
        }
        public void TestGetAuthorNegative()
        {
            AuthorsService    service           = new AuthorsService();
            AuthorsController authorsController = new AuthorsController(service);

            string result = authorsController.Get(-1);

            Assert.IsTrue(result.Length == 0);
        }
Esempio n. 26
0
        /* *******
         * AUTHORS
         * *******
         */
        #region authors
        private async void PopulateAuthors()
        {
            bool result = await AuthorsController.LoadData();

            if (result)
            {
                BindCollectionToAuthorsView();
            }
        }
Esempio n. 27
0
        public void IndexTests()
        {
            AuthorsController controller = new AuthorsController();

            IActionResult result    = controller.Index();
            ViewResult    vewResult = (ViewResult)result;

            Assert.NotNull(vewResult);
        }
Esempio n. 28
0
        public void Authors_Controller_Return_Values()
        {
            var controller = new AuthorsController();
            IHttpActionResult actionResult = controller.Get();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <AuthorDto> >;

            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
        }
        private void authorButton_Click(object sender, EventArgs e)
        {
            Hide();
            AuthorsForm    authorsForm = new AuthorsForm();
            StorageContext context     = new StorageContext();

            _ = new AuthorsController(authorsForm, context);
            authorsForm.ShowDialog();
            Show();
        }
        public async void DeleteAuthorWithIncorrectIdReturnsNotFound()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new AuthorsController(context, _mapper))
                {
                    var result = await controller.DeleteAuthor(99);

                    Assert.IsType <NotFoundResult>(result);
                }
        }