public async Task RestoreAsync_WithCategoryId_ShouldRestoreCategory() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); Category category = database.Categories.Find(firstDeletedCategoryId); foreach (Subcategory subcategory in category.Subcategories) { foreach (Supplement supplement in subcategory.Supplements) { supplement.Manufacturer.IsDeleted = true; supplement.Manufacturer.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(); } IManagerCategoryService managerCategoryService = new ManagerCategoryService(database); // Act await managerCategoryService.RestoreAsync(firstDeletedCategoryId); // Assert category.IsDeleted.Should().Be(false); foreach (Subcategory subcategory in category.Subcategories) { subcategory.IsDeleted.Should().Be(false); foreach (Supplement supplement in subcategory.Supplements) { 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); } } } }
public async Task TotalCommentAsync_ShouldSeeDeletedCommentsTrue_ShouldReturnAllFalseComments() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Comments.Where(c => c.SupplementId == firstSupplementId).FirstOrDefault().IsDeleted = true; database.SaveChanges(); ISupplementService supplementService = new SupplementService(database); // Act int result = await supplementService.TotalCommentsAsync(firstSupplementId, false); // Assert result.Should().Be(1); }
public async Task AddSupplementToCartAsync_WithSupplementId_ShouldReturnFalseWithQuantityEqualsToZero() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Supplements.Find(supplementId).Quantity = 0; database.SaveChanges(); IOrderService orderService = new OrderService(database); // Act bool result = await orderService.AddSupplementToCartAsync(supplementId, null); // Assert result.Should().Be(false); }
public async Task RestoreAsync_WithReviewId_ShouldReturnSupplementNotExists() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Supplements.Find(10).IsDeleted = true; database.Reviews.Find(firstReviewId).IsDeleted = true; database.SaveChanges(); IModeratorReviewService moderatorReviewService = new ModeratorReviewService(database); // Act string result = await moderatorReviewService.RestoreAsync(firstReviewId); // Assert result.Should().Be(string.Format(EntityNotExists, SupplementEntity)); }
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); } }
public async Task TotalCountAsync_WithSearchTokenAndIsDeletedFalse_ShouldReturnCategoriesCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Categories.Add(new Category { Id = 100, Name = otherName }); database.SaveChanges(); IManagerCategoryService managerCategoryService = new ManagerCategoryService(database); // Act int result = await managerCategoryService.TotalCountAsync(false, otherName); // Assert result.Should().Be(1); }
public async Task TotalCountAsync_WithoutSearchTokenAndIsDeletedTrue_ShouldReturnSubcategoriesCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Subcategories.Add(new Subcategory { Id = 100, Name = otherName, CategoryId = categoryId, IsDeleted = true }); database.SaveChanges(); IManagerSubcategoryService managerSubcategoryService = new ManagerSubcategoryService(database); // Act int result = await managerSubcategoryService.TotalCountAsync(true, null); // Assert result.Should().Be(11); }
public async Task TotalCountAsync_WithSearchToken_ShouldReturnValidCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Supplements.Add(new Supplement { Id = 100, Name = "other" }); database.SaveChanges(); ISupplementService supplementService = new SupplementService(database); // Act int result = await supplementService.TotalCountAsync("supplement"); // Assert result.Should().Be(10); }
public async Task TotalCountAsync_WithSearchToken_ShouldReturnUsersCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Users.Add(new User { Id = "Id", UserName = "******" }); database.SaveChanges(); IAdminUserService adminUserService = new AdminUserService(database); // Act int result = await adminUserService.TotalCountAsync("user"); // Assert result.Should().Be(10); }
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); }
public async Task TotalCountAsync_WithSearchTokenAndIsDeletedTrue_ShouldReturnManufacturersCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Manufacturers.Add(new Manufacturer { Id = 100, Name = otherName, IsDeleted = true }); database.SaveChanges(); IManagerManufacturerService managerManufacturerService = new ManagerManufacturerService(database); // Act int result = await managerManufacturerService.TotalCountAsync(true, otherName); // Assert result.Should().Be(1); }
public async Task RestoreAsync_WithCommentId_ShouldRestoreComment() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Supplements.Find(10).IsDeleted = false; database.Comments.Find(commentId).IsDeleted = true; database.SaveChanges(); IModeratorCommentService moderatorCommentService = new ModeratorCommentService(database); // Act string result = await moderatorCommentService.RestoreAsync(commentId); // Assert result.Should().Be(string.Empty); database.Comments.Find(commentId).IsDeleted.Should().Be(false); }
public static void SeedData(FitStoreDbContext database) { for (int i = 1; i <= 10; i++) { database .Users .Add(new User { Id = $"User {i}", UserName = $"User_{i}", Address = $"Address {i}", Email = $"Email {i}", PhoneNumber = $"Phone {i}", IsRestricted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 10; i++) { database .Categories .Add(new Category { Id = i, Name = $"Category {i}", IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Subcategories .Add(new Subcategory { Id = i, Name = $"Subcategory {i}", CategoryId = i < 11 ? i : i - 10, IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Manufacturers .Add(new Manufacturer { Id = i, Name = $"Manufacturer {i}", Address = $"Address {i}", IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Supplements .Add(new Supplement { Id = i, Name = $"Supplement {i}", Price = i, Quantity = i, Picture = new byte[0], SubcategoryId = i < 11 ? i : i - 10, ManufacturerId = i < 11 ? i : i - 10, BestBeforeDate = DateTime.UtcNow, IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Comments .Add(new Comment { Id = i, Content = $"Content {i}", AuthorId = i < 11 ? $"User {i}" : $"User {i - 10}", SupplementId = i < 11 ? i : i - 10, PublishDate = DateTime.UtcNow, IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Reviews .Add(new Review { Id = i, Content = $"Content {i}", AuthorId = i < 11 ? $"User {i}" : $"User {i - 10}", SupplementId = i < 11 ? i : i - 10, Rating = i < 11 ? i : i - 10, PublishDate = DateTime.UtcNow, IsDeleted = i % 2 == 0 ? true : false }); } database.SaveChanges(); for (int i = 1; i <= 20; i++) { database .Orders .Add(new Order { Id = i, TotalPrice = i, UserId = i < 11 ? $"User {i}" : $"User {i - 10}", Supplements = new List <OrderSupplements>() { new OrderSupplements { SupplementId = i < 11 ? i : i - 10, Quantity = i } } }); } database.SaveChanges(); }