public async Task SeededWater_InsertOrUpdate_IngredientUpdated() { //Arrange var ingredient = new IngredientDetailModel ( Name: IngredientSeeds.Water.Name, Description: IngredientSeeds.Water.Description ) { Id = IngredientSeeds.Water.Id }; ingredient.Name += "updated"; ingredient.Description += "updated"; //Act await _ingredientFacadeSUT.SaveAsync(ingredient); //Assert await using var dbxAssert = await DbContextFactory.CreateDbContextAsync(); var ingredientFromDb = await dbxAssert.Ingredients.SingleAsync(i => i.Id == ingredient.Id); DeepAssert.Equal(ingredient, Mapper.Map <IngredientDetailModel>(ingredientFromDb)); }
public async Task SeededWater_DeleteById_Deleted() { await _ingredientFacadeSUT.DeleteAsync(IngredientSeeds.Water.Id); await using var dbxAssert = await DbContextFactory.CreateDbContextAsync(); Assert.False(await dbxAssert.Ingredients.AnyAsync(i => i.Id == IngredientSeeds.Water.Id)); }
public async Task NewIngredient_InsertOrUpdate_IngredientAdded() { //Arrange var ingredient = new IngredientDetailModel( Name: "Water", Description: "Mineral water" ); //Act ingredient = await _ingredientFacadeSUT.SaveAsync(ingredient); //Assert await using var dbxAssert = await DbContextFactory.CreateDbContextAsync(); var ingredientFromDb = await dbxAssert.Ingredients.SingleAsync(i => i.Id == ingredient.Id); DeepAssert.Equal(ingredient, Mapper.Map <IngredientDetailModel>(ingredientFromDb)); }
public async Task AddNew_RecipeWithoutIngredients_Persisted() { //Arrange var entity = RecipeSeeds.EmptyRecipeEntity with { Name = "Chicken soup", Description = "Grandma's delicious chicken soup." }; //Act CookBookDbContextSUT.Recipes.Add(entity); await CookBookDbContextSUT.SaveChangesAsync(); //Assert await using var dbx = await DbContextFactory.CreateDbContextAsync(); var actualEntity = await dbx.Recipes .SingleAsync(i => i.Id == entity.Id); DeepAssert.Equal(entity, actualEntity); }
public async Task AddNew_Ingredient_Persisted() { //Arrange IngredientEntity entity = new( Guid.Parse("C5DE45D7-64A0-4E8D-AC7F-BF5CFDFB0EFC"), Name : "Salt", Description : "Mountain salt", ImageUrl : "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/Salt_shaker_on_white_background.jpg/800px-Salt_shaker_on_white_background.jpg" ); //Act CookBookDbContextSUT.Ingredients.Add(entity); await CookBookDbContextSUT.SaveChangesAsync(); //Assert await using var dbx = await DbContextFactory.CreateDbContextAsync(); var actualEntities = await dbx.Ingredients.SingleAsync(i => i.Id == entity.Id); Assert.Equal(entity, actualEntities); }
public async Task Update_IngredientAmount_Persisted() { //Arrange var baseEntity = IngredientAmountSeeds.IngredientAmountEntityUpdate; var entity = baseEntity with { Amount = baseEntity.Amount + 1, Unit = Unit.None }; //Act CookBookDbContextSUT.IngredientAmountEntities.Update(entity); await CookBookDbContextSUT.SaveChangesAsync(); //Assert await using var dbx = await DbContextFactory.CreateDbContextAsync(); var actualEntity = await dbx.IngredientAmountEntities.SingleAsync(i => i.Id == entity.Id); Assert.Equal(entity, actualEntity); }
public async Task Update_Ingredient_Persisted() { //Arrange var baseEntity = IngredientSeeds.WaterUpdate; var entity = baseEntity with { Name = baseEntity + "Updated", Description = baseEntity + "Updated", }; //Act CookBookDbContextSUT.Ingredients.Update(entity); await CookBookDbContextSUT.SaveChangesAsync(); //Assert await using var dbx = await DbContextFactory.CreateDbContextAsync(); var actualEntity = await dbx.Ingredients.SingleAsync(i => i.Id == entity.Id); Assert.Equal(entity, actualEntity); }
public async Task DisposeAsync() { await using var dbx = await DbContextFactory.CreateDbContextAsync(); await dbx.Database.EnsureDeletedAsync(); }
public async Task InitializeAsync() { await using var dbx = await DbContextFactory.CreateDbContextAsync(); await dbx.Database.EnsureCreatedAsync(); }