public async Task GetRecipesByUserId_WithExistentUserId_ShouldReturnCorrectResult() { var errorMessagePrefix = "UserCookedRecipeService GetRecipesByUserId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var userId = context.Users.First(x => x.FullName == "User 1").Id; // Act var actualResult = userCookedRecipeService .GetRecipesByUserId(userId) .ToList(); var expectedResult = userCookedRecipeRepository .All() .Where(x => x.UserId == userId) .OrderByDescending(x => x.AddedOn) .Select(x => x.Recipe) .To <RecipeServiceModel>() .ToList(); // Assert Assert.True(expectedResult.Count() == actualResult.Count(), errorMessagePrefix + " " + "Collections count mismatch."); for (int i = 0; i < actualResult.Count(); i++) { Assert.True(expectedResult[i].Id == actualResult[i].Id, errorMessagePrefix + " " + "Recipe is not returned properly."); } }
public async Task DeleteByUserIdAndRecipeIdAsync_WithExistentUserIdAndRecipeId_ShouldSuccessfullyDelete() { var errorMessagePrefix = "UserCookedRecipeService DeleteByUserIdAndRecipeIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var userId = context.Users.First(x => x.FullName == "User 1").Id; var recipeId = context.Recipes.First(x => x.Title == "Recipe 1").Id; // Act var userCookedRecipesCount = userCookedRecipeRepository.All().Count(); await userCookedRecipeService .DeleteByUserIdAndRecipeIdAsync(userId, recipeId); var actualResult = userCookedRecipeRepository.All().Count(); var expectedResult = userCookedRecipesCount - 1; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Count is not reduced properly."); }
public async Task DeleteByRecipeIdAsync_WithNonExistentRecipeId_ShouldReturnCorrectResult() { var errorMessagePrefix = "UserCookedRecipeService DeleteByRecipeIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var nonExistentRecipeId = Guid.NewGuid().ToString(); // Act var result = await userCookedRecipeService.DeleteByRecipeIdAsync(nonExistentRecipeId); // Assert Assert.False(result, errorMessagePrefix + " " + "Returns true."); }
public async Task DeleteByRecipeIdAsync_WithExistentRecipeId_ShouldReturnCorrectResult() { var errorMessagePrefix = "UserCookedRecipeService DeleteByRecipeIdAsync() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var recipeId = context.Recipes.First(x => x.Title == "Recipe 1").Id; // Act var result = await userCookedRecipeService.DeleteByRecipeIdAsync(recipeId); // Assert Assert.True(result, errorMessagePrefix + " " + "Returns false."); }
public async Task DeleteByUserIdAndRecipeIdAsync_WithNonExistentUserIdAndRecipeId_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var nonExistentUserId = Guid.NewGuid().ToString(); var nonExistentRecipeId = Guid.NewGuid().ToString(); // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await userCookedRecipeService .DeleteByUserIdAndRecipeIdAsync(nonExistentUserId, nonExistentRecipeId); }); }
public async Task GetRecipesByUserId_WithNonExistentUserId_ShouldReturnEmptyCollection() { var errorMessagePrefix = "UserCookedRecipeService GetRecipesByUserId() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var userCookedRecipeRepository = new EfRepository <UserCookedRecipe>(context); var userCookedRecipeService = new UserCookedRecipeService(userCookedRecipeRepository); await this.SeedDataAsync(context); var nonExistentUserId = Guid.NewGuid().ToString(); // Act var actualResult = userCookedRecipeService .GetRecipesByUserId(nonExistentUserId) .ToList() .Count; var expectedResult = 0; // Assert Assert.True(expectedResult == actualResult, errorMessagePrefix + " " + "Collection is not empty."); }