Beispiel #1
0
    public void GenerateComponents()
    {
        var vegetables = new ArticleGroup("Vegetables");
        var tomato     = new Article {
            Name = "Tomato", ArticleGroup = vegetables, IsInventory = false
        };
        var salad = new Article {
            Name = "Salad", ArticleGroup = vegetables, IsInventory = false
        };
        var bag         = new Unit("Bag");
        var piece       = new Unit("Piece");
        var ingredient1 = new Ingredient(tomato, 2, bag);
        var ingredient2 = new Ingredient(salad, 3, bag);
        var ingredient3 = new Ingredient(tomato, 1, piece);
        var ingredient4 = new Ingredient(salad, 5, bag);
        var recipe1     = new Recipe("Blub", 3, new[] { ingredient1, ingredient2 });
        var recipe2     = new Recipe("Blub", 3, new[] { ingredient3, ingredient4 });
        var testee      = new GeneratePurchaseItemsForRecipesAction();

        var results = testee.GeneratePurchaseItems(new[] { recipe1, recipe2 }).ToList();

        results.Should().HaveCount(3);
        results.Should().Contain(x => x.Article == tomato && x.Quantity == 2 && x.Unit == bag);
        results.Should().Contain(x => x.Article == tomato && x.Quantity == 1 && x.Unit == piece);
        results.Should().Contain(x => x.Article == salad && x.Quantity == 8 && x.Unit == bag);
    }
Beispiel #2
0
    /// <inheritdoc />
    public IEnumerable <NewPurchaseItemDto> GetOrderedPurchaseItems(IEnumerable <ExistingRecipeDto> existingRecipeDtos,
                                                                    ExistingStoreDto existingStoreDto)
    {
        var recipes = SimpleCrudHelper.FindMany <Recipe>(existingRecipeDtos.Select(x => x.RecipeId));
        var store   = SimpleCrudHelper.Find <Store>(existingStoreDto.StoreId);

        var orderedPurchaseItemsByStore =
            OrderPurchaseItemsByStoreAction.OrderPurchaseItemsByStore(store,
                                                                      GeneratePurchaseItemsForRecipesAction
                                                                      .GeneratePurchaseItems(recipes));

        return(Mapper.Map <IEnumerable <NewPurchaseItemDto> >(orderedPurchaseItemsByStore));
    }
Beispiel #3
0
    /// <inheritdoc />
    public IEnumerable <NewPurchaseItemDto> GetOrderedPurchaseItems(ExistingStoreDto existingStoreDto)
    {
        var meals   = Context.Meals.Where(x => !x.HasBeenShopped);
        var recipes = GetRecipesForMealsAction.GetRecipesForMeals(meals);
        var store   = SimpleCrudHelper.Find <Store>(existingStoreDto.StoreId);

        var orderedPurchaseItemsByStore =
            OrderPurchaseItemsByStoreAction.OrderPurchaseItemsByStore(store,
                                                                      GeneratePurchaseItemsForRecipesAction
                                                                      .GeneratePurchaseItems(recipes));

        foreach (var meal in meals)
        {
            meal.HasBeenShopped = true;
        }

        var newPurchaseItemDtos = Mapper.Map <IEnumerable <NewPurchaseItemDto> >(orderedPurchaseItemsByStore);

        // TODO MUL: Investigate why conversion has to be done before calling SaveChanges()
        Context.SaveChanges();

        return(newPurchaseItemDtos);
    }