コード例 #1
0
        public async Task DeleteAsync_WithSupplementId_ShouldDeleteSupplement()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            await managerSupplementService.DeleteAsync(firstNotDeletedSupplementId);

            // Assert
            Supplement supplement = database.Supplements.Find(firstNotDeletedSupplementId);

            supplement.IsDeleted.Should().Be(true);

            foreach (Review review in supplement.Reviews)
            {
                review.IsDeleted.Should().Be(true);
            }

            foreach (Comment comment in supplement.Comments)
            {
                comment.IsDeleted.Should().Be(true);
            }
        }
コード例 #2
0
        public async Task IsSupplementModified_ShouldReturnFalse()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            bool result = await managerSupplementService.IsSupplementModified(firstNotDeletedSupplementId, firstNotDeletedSupplementName, null, 1, 1, new byte[0], DateTime.UtcNow, subcategoryId, manufacturerId);

            // Assert
            result.Should().Be(false);
        }
コード例 #3
0
        public async Task GetEditModelAsync_WithSupplementId_ShouldReturnValidServiceModel()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            SupplementServiceModel result = await managerSupplementService.GetEditModelAsync(firstNotDeletedSupplementId);

            // Assert
            result.Name.Should().Be(firstNotDeletedSupplementName);
        }
コード例 #4
0
        public async Task CreateAsync_ShouldCreateNewSupplement()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            await managerSupplementService.CreateAsync(supplementName, null, 0, 0, new byte[0], DateTime.UtcNow, subcategoryId, manufacturerId);

            // Assert
            Supplement supplement = database.Supplements.Find(1);

            supplement.Id.Should().Be(1);
            supplement.Name.Should().Be(supplementName);
        }
コード例 #5
0
        public async Task EditAsync_WithSupplementId_ShouldEditSupplement()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            await managerSupplementService.EditAsync(firstNotDeletedSupplementId, supplementName, null, 0, 0, null, DateTime.UtcNow, subcategoryId, manufacturerId);

            // Assert
            Supplement supplement = database.Supplements.Find(firstNotDeletedSupplementId);

            supplement.Id.Should().Be(firstNotDeletedSupplementId);
            supplement.Name.Should().Be(supplementName);
        }
コード例 #6
0
        public async Task GetAllPagedListingAsync_WithSearchTokenAndIsDeletedTrue_ShouldReturnPagedDeletedSupplements()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            IEnumerable <SupplementAdvancedServiceModel> result = await managerSupplementService.GetAllPagedListingAsync(true, "supplement", page);

            // Assert
            result.Count().Should().Be(3);
            result.First().Id.Should().Be(firstDeletedSupplementId);
            result.First().Name.Should().Be(firstDeletedSupplementName);
            result.Last().Id.Should().Be(lastDeletedSupplementId);
            result.Last().Name.Should().Be(lastDeletedSupplementName);
        }
コード例 #7
0
        public async Task RestoreAsync_WithSupplementId_ShouldRestoreSupplement()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            Supplement supplement = database.Supplements.Find(firstDeletedSupplementId);

            supplement.Manufacturer.IsDeleted         = false;
            supplement.Subcategory.IsDeleted          = false;
            supplement.Subcategory.Category.IsDeleted = false;

            foreach (Review review in supplement.Reviews)
            {
                review.IsDeleted.Should().Be(true);
            }

            foreach (Comment comment in supplement.Comments)
            {
                comment.IsDeleted.Should().Be(true);
            }

            database.SaveChanges();

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            await managerSupplementService.RestoreAsync(firstDeletedSupplementId);

            // Assert
            supplement.IsDeleted.Should().Be(false);

            foreach (Review review in supplement.Reviews)
            {
                review.IsDeleted.Should().Be(false);
            }

            foreach (Comment comment in supplement.Comments)
            {
                comment.IsDeleted.Should().Be(false);
            }
        }
コード例 #8
0
        public async Task TotalCountAsync_WithSearchTokenAndIsDeletedFalse_ShouldReturnSupplementsCount()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            database.Supplements.Add(new Supplement {
                Id = 100, Name = otherName, SubcategoryId = subcategoryId, ManufacturerId = manufacturerId
            });
            database.SaveChanges();

            IManagerSupplementService managerSupplementService = new ManagerSupplementService(database);

            // Act
            int result = await managerSupplementService.TotalCountAsync(false, otherName);

            // Assert
            result.Should().Be(1);
        }