public IHttpActionResult GetAuthorById(int authorId)
        {
            AuthorServices authorService = CreateAuthorService();
            var            author        = authorService.GetAuthorById(authorId);

            return(Ok(author));
        }
        private AuthorServices CreateAuthorService()
        {
            var userId        = Guid.Parse(User.Identity.GetUserId());
            var authorService = new AuthorServices(userId);

            return(authorService);
        }
        public IHttpActionResult Get()
        {
            AuthorServices authorService = CreateAuthorService();
            var            authors       = authorService.GetAuthors();

            return(Ok(authors));
        }
        public IHttpActionResult SortAuthorsByRating()
        {
            AuthorServices         service = CreateAuthorService();
            List <AuthorListItems> authors = service.SortAuthorsByRating();

            return(Ok(authors));
        }
Ejemplo n.º 5
0
        public void AddAuthor_WhenAuthorDontExist_ShouldAddToDatabase()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "AddAuthor").Options;

            var validationMock = new Mock <IValidations>();

            string author = "newAuthor";

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unit = new UnitOfWork(actContext);

                var service = new AuthorServices(unit, validationMock.Object);

                var result = service.AddAuthor(author);
            }

            // Assert
            using (var assertContex = new LibrarySystemContext(contexInMemory))
            {
                int cont = assertContex.Authors.Count();
                Assert.AreEqual(1, cont);
                Assert.AreEqual(author, assertContex.Authors.First().Name);
            }
        }
        public IHttpActionResult GetAuthorByFirstName(string firstName)
        {
            AuthorServices authorService = CreateAuthorService();
            AuthorDetail   author        = authorService.GetAuthorByFirstName(firstName);

            return(Ok(author));
        }
Ejemplo n.º 7
0
 //Create a PersonInfo constructor
 public AuthorController(AuthorServices author, UserManager <AppUser> userServices,
                         IAuthorizationService authService, ILogger <AuthorController> log)
 {
     _author       = author;
     _userServices = userServices;
     _authService  = authService;
     _log          = log;
 }
Ejemplo n.º 8
0
        public void Return_Proper_Collection_Type_When_Called()
        {
            // Assert
            IAuthorServices sut = new AuthorServices(repository);

            // Act & Assert
            Assert.IsInstanceOf <IQueryable <Author> >(sut.GetAllAuthors());
        }
Ejemplo n.º 9
0
        public void CreateInstanceOfAuthorServices_IfParametersAreValid()
        {
            // Arrange & Act
            var dbSetMock      = new Mock <ILibrarySystemEfWrapper <Author> >();
            var authorServices = new AuthorServices(dbSetMock.Object);

            // Assert
            Assert.That(authorServices, Is.Not.Null.And.InstanceOf <AuthorServices>());
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_get_author_books")
                      .Options;

            db = new FancyLibraryContext(options);

            authorServices = new AuthorServices(db);
        }
Ejemplo n.º 11
0
        public void Setup()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_find_author")
                      .Options;

            db = new FancyLibraryContext(options);

            authorServices = new AuthorServices(db);

            db.Authors.AddRange(CreateInMemoryDb());
            db.SaveChanges();
        }
Ejemplo n.º 12
0
        public void ReturnCorrectAuthor_WhenIdIsCorrect()
        {
            // Arrange
            var            dbSetMock      = new Mock <ILibrarySystemEfWrapper <Author> >();
            AuthorServices authorServices = new AuthorServices(dbSetMock.Object);
            var            authorWithId   = new Mock <Author>();

            // Act
            authorServices.GetById(authorWithId.Object.Id);

            // Assert
            dbSetMock.Verify(r => r.GetById(authorWithId.Object.Id), Times.Once);
        }
        public void Setup()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_get_author_books_count")
                      .Options;

            db = new FancyLibraryContext(options);

            authorServices = new AuthorServices(db);

            db.Authors.AddRange(FillAuthors());
            db.Books.AddRange(FillBooks());
            db.SaveChanges();
        }
Ejemplo n.º 14
0
        public IHttpActionResult UpdateAuthor(AuthorEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AuthorServices service = CreateAuthorService();

            if (!service.UpdateAuthor(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public void ReturnInstanceOfIQueryable_IfCalled()
        {
            // Arrange
            var            dbSetMock      = new Mock <ILibrarySystemEfWrapper <Author> >();
            AuthorServices authorServices = new AuthorServices(dbSetMock.Object);

            // Act
            IEnumerable <Author> expectedResult = new List <Author>()
            {
                new Author(), new Author(), new Author()
            };

            dbSetMock.Setup(r => r.All()).Returns(() => expectedResult.AsQueryable());

            // Assert
            Assert.IsInstanceOf <IQueryable <Author> >(authorServices.GetAllAuthors());
        }
Ejemplo n.º 16
0
        public void AddAuthor_WhenAuthorExist_ShouldReturnAddToDatabase()
        {
            // Arrange
            var contexInMemory = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "AddAuthorExist").Options;

            var validationMock = new Mock <IValidations>();

            string author = "newAuthor";

            Author existingAuthor = new Author()
            {
                Id   = 1,
                Name = author
            };
            int result;

            // Act
            using (var actContext = new LibrarySystemContext(contexInMemory))
            {
                var unit = new UnitOfWork(actContext);
                var test = actContext.Authors.Add(existingAuthor).Entity;
                actContext.SaveChanges();

                var service = new AuthorServices(unit, validationMock.Object);
                result = service.AddAuthor(author);
            }

            // Assert
            using (var assertContext = new LibrarySystemContext(contexInMemory))
            {
                var toAssert = assertContext.Authors
                               .SingleOrDefault(a => a.Name == author);

                int count = assertContext.Authors.Count();

                Assert.AreEqual(1, count);
                Assert.AreEqual(toAssert.Id, result);
            }
        }
 public BookController(AuthorServices authorServices)
 {
     _authorServices = authorServices;
 }
Ejemplo n.º 18
0
 public AuthorsController(AuthorServices authorServices)
 {
     _authorServices = authorServices;
 }
Ejemplo n.º 19
0
 public AuthorController(AuthorServices services)
 {
     AuthorServices = services;
 }
Ejemplo n.º 20
0
 public AuthorController(bookstoreContext context, IMapper mapper, AuthorServices authorServices)
 {
     _context        = context;
     _mapper         = mapper;
     _authorServices = authorServices;
 }