public async Task UpdateAsyncCorrectlyUpdatesInformation()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.DocumentCategories.AddRangeAsync(this.SeedData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);

            var model = new EditViewModel
            {
                Name      = "NewName",
                IsDeleted = true,
            };

            var result = await service.UpdateAsync(1, model);

            Assert.NotEqual(-1, result);

            var dbRecord = await context.DocumentCategories.FindAsync(1);

            Assert.NotEqual("First", dbRecord.Name);
            Assert.NotNull(dbRecord.DeletedOn);
            Assert.True(dbRecord.IsDeleted);
        }
        public async Task DeleteFailsWhenIdNotInDatabase()
        {
            AutoMapperInitializer.InitializeMapper();
            var context    = InMemoryDbContextInitializer.InitializeContext();
            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);
            var result  = await service.DeleteAsync(100);

            Assert.False(result);
        }
        public async Task GetAllReturnsCorrectNumberOfRecords()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.DocumentCategories.AddRangeAsync(this.SeedData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);
            var result  = service.GetAll <EditViewModel>();

            Assert.Equal(2, result.Count());
        }
        public async Task UpdateAsyncFailsWhenIdNotInDb()
        {
            AutoMapperInitializer.InitializeMapper();
            var context    = InMemoryDbContextInitializer.InitializeContext();
            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);

            var model = new EditViewModel
            {
                Name      = "NewName",
                IsDeleted = true,
            };

            var result = await service.UpdateAsync(100, model);

            Assert.Equal(-1, result);
        }
        public async Task GetDetailsReturnsCorrectInformation()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.DocumentCategories.AddRangeAsync(this.SeedData());

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);

            var result = service.GetDetails <EditViewModel>(1);

            Assert.NotNull(result);
            Assert.Equal(1, result.Id);
            Assert.Equal("First", result.Name);
            Assert.False(result.IsDeleted);
        }
        public async Task CreateSuccessfullyAddsNewCategory()
        {
            AutoMapperInitializer.InitializeMapper();
            var context    = InMemoryDbContextInitializer.InitializeContext();
            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);

            var model = new CreateViewModel
            {
                Name      = "New Category",
                IsDeleted = true,
            };

            var id = await service.CreateAsync(model);

            Assert.NotEqual(-1, id);
            Assert.Equal(1, context.DocumentCategories.IgnoreQueryFilters().Count());
        }
        public async Task DeleteMarksRecordAsDeleted()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.DocumentCategories.AddAsync(new DocumentCategory { Id = 1, Name = "Category", IsDeleted = false });

            await context.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <DocumentCategory>(context);

            var service = new DocumentCategoriesService(repository);

            var result = await service.DeleteAsync(1);

            var dbRecord = await context.DocumentCategories.FindAsync(1);

            Assert.True(result);
            Assert.True(dbRecord.IsDeleted);
            Assert.NotNull(dbRecord.DeletedOn);
            Assert.Equal(1, context.DocumentCategories.IgnoreQueryFilters().Count());
        }