Exemplo n.º 1
0
        public async Task GetAllActiveAuthors_WithData_ShouldReturnAllActiveAuthors()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);


            List <AdminAuthorListingServiceModel> expectedData = GetTestData()
                                                                 .Where(c => c.IsDeleted == false)
                                                                 .To <AdminAuthorListingServiceModel>().ToList();

            List <AdminAuthorListingServiceModel> actualData = await this.authorService.GetAllActiveAuthors().ToListAsync();

            Assert.Equal(expectedData.Count, actualData.Count);


            for (int i = 0; i < expectedData.Count; i++)
            {
                var expectedEntry = expectedData[i];
                var actualEntry   = actualData[i];

                Assert.True(expectedEntry.FirstName == actualEntry.FirstName, "FirstName is not returned properly.");
                Assert.True(expectedEntry.LastName == actualEntry.LastName, "LastName is not returned properly.");
                Assert.True(expectedEntry.IsDeleted == actualEntry.IsDeleted, "IsDeleted is not returned properly.");
            }
        }
Exemplo n.º 2
0
        public async Task GetAllAuthors_WithoutData_ShouldReturnEmptyList()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            this.authorService = new AdminAuthorService(context);

            List <AdminAuthorListingServiceModel> actualData = await this.authorService.GetAllAuthors().ToListAsync();

            Assert.Empty(actualData);
        }
Exemplo n.º 3
0
        public async Task CreateAsync_ShouldCreateAuthor()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            bool actualResult = await this.authorService.CreateAsync("Николай", "Хайтов");

            Assert.True(actualResult);
        }
Exemplo n.º 4
0
        public async Task GetByIdAsync_WithNonExistentId_ShouldReturnNull()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            AdminAuthorListingServiceModel actualData = await this.authorService.GetByIdAsync(int.MinValue);

            Assert.True(actualData == null);
        }
Exemplo n.º 5
0
 public BooksController(IAdminBookService bookService,
                        IAdminAuthorService authorService,
                        IAdminPublisherService publisherService,
                        IAdminCategoryService categoryService,
                        ICloudinaryService cloudinaryService)
 {
     this.bookService       = bookService;
     this.authorService     = authorService;
     this.publisherService  = publisherService;
     this.categoryService   = categoryService;
     this.cloudinaryService = cloudinaryService;
 }
Exemplo n.º 6
0
        public async Task GetByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            AdminAuthorListingServiceModel expectedData = context.Authors.First().To <AdminAuthorListingServiceModel>();
            AdminAuthorListingServiceModel actualData   = await this.authorService.GetByIdAsync(expectedData.Id);

            Assert.True(expectedData.Id == actualData.Id, "Id is not returned properly.");
        }
Exemplo n.º 7
0
        public async Task HideAsync_WithNonExistentAuthorId_ShouldReturnFalse()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            bool actualResult = await this.authorService.HideAsync(int.MinValue);

            int expectedCount = 2;
            int actualCount   = context.Authors.Count();

            Assert.False(actualResult);
            Assert.True(expectedCount == actualCount);
        }
Exemplo n.º 8
0
        public async Task EditAsync_ShouldEditCategory()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            AdminAuthorListingServiceModel expectedData = context.Authors.First().To <AdminAuthorListingServiceModel>();

            expectedData.FirstName = "edited";

            await this.authorService.EditAsync(expectedData.Id, expectedData.FirstName, expectedData.LastName);

            AdminAuthorListingServiceModel actualData = context.Authors.First().To <AdminAuthorListingServiceModel>();

            Assert.True(actualData.FirstName == expectedData.FirstName, "FirstName not edited properly.");
        }
Exemplo n.º 9
0
        public async Task HideAsync_ShouldHideAuthor()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            int id = context.Authors.First().To <AdminAuthorListingServiceModel>().Id;

            bool actualResult = await this.authorService.HideAsync(id);

            int expectedCount = 1;
            int actualCount   = context.Authors.Where(c => c.IsDeleted == true).Count();


            Assert.True(actualResult);
            Assert.True(expectedCount == actualCount);
        }
Exemplo n.º 10
0
        public async Task ShowAsync_WithNonExistentAuthorId_ShouldReturnFalse()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            var author = context.Authors.First();

            author.IsDeleted = true;
            context.Authors.Update(author);
            await context.SaveChangesAsync();

            bool actualResult = await this.authorService.ShowAsync(-1);

            int expectedCount = 1;
            int actualCount   = context.Authors.Where(c => c.IsDeleted == true).Count();

            Assert.False(actualResult);
            Assert.True(expectedCount == actualCount);
        }
Exemplo n.º 11
0
        public async Task ShowAsync_WithCorrectData_ShouldShowAuthor()
        {
            var context = BookStoreDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.authorService = new AdminAuthorService(context);

            int id = context.Authors.First().Id;

            var author = context.Authors.First();

            author.IsDeleted = true;
            context.Authors.Update(author);
            await context.SaveChangesAsync();

            bool actualResult = await this.authorService.ShowAsync(id);

            int expectedCount = 2;
            int actualCount   = context.Authors.Where(a => a.IsDeleted == false).Count();

            Assert.True(actualResult);
            Assert.True(expectedCount == actualCount);
        }
Exemplo n.º 12
0
 public AuthorsController(IAdminAuthorService authorService, IAdminBookService bookService)
 {
     this.authorService = authorService;
     this.bookService   = bookService;
 }
Exemplo n.º 13
0
 public ProductController(IAdminProductService productService, IAdminAuthorService adminAuthorService)
 {
     this._productService     = productService;
     this._adminAuthorService = adminAuthorService;
 }