Exemple #1
0
    private static ArticleService CreateTestee(Mock <IArticleAction> articleActionMock, InMemoryDbContext context)
    {
        var mapper = TestMapper.Create();
        var testee = new ArticleService(articleActionMock.Object, context, mapper, new SimpleCrudHelper(context, mapper));

        return(testee);
    }
    private static ArticleService CreateTestee(EfCoreContext context)
    {
        var mapper = TestMapper.Create();
        var testee = new ArticleService(new ArticleAction(new ArticleDbAccess(context), mapper), context, mapper, new SimpleCrudHelper(context, mapper));

        return(testee);
    }
    public void GetAllArticles()
    {
        var articleDbAccessMock = new Mock <IArticleDbAccess>();
        var testee = new ArticleAction(articleDbAccessMock.Object, TestMapper.Create());

        testee.GetAllArticles();

        articleDbAccessMock.Verify(x => x.GetArticles(), Times.Once);
    }
Exemple #4
0
    public void GetAllIngredients()
    {
        var ingredientDbAccessMock = new Mock <IIngredientDbAccess>();
        var testee = new IngredientAction(ingredientDbAccessMock.Object, TestMapper.Create());

        testee.GetAllIngredients();

        ingredientDbAccessMock.Verify(x => x.GetIngredients(), Times.Once);
    }
Exemple #5
0
    public void CreateMealType()
    {
        using var context = new InMemoryDbContext();
        var testee         = new MealTypeService(new SimpleCrudHelper(context, TestMapper.Create()));
        var newMealTypeDto = new NewMealTypeDto("Lunch");

        testee.CreateMealType(newMealTypeDto);

        context.MealTypes.Should().Contain(x => x.Name == "Lunch");
    }
    public void CreateArticle()
    {
        var newArticleDto       = new NewArticleDto("Cheese", new ExistingArticleGroupDto(3, "Diary"), true);
        var articleDbAccessMock = new Mock <IArticleDbAccess>();
        var testee = new ArticleAction(articleDbAccessMock.Object, TestMapper.Create());

        testee.CreateArticle(newArticleDto);

        articleDbAccessMock.Verify(x => x.AddArticle(It.Is <Article>(a => a.Name == "Cheese")), Times.Once);
    }
Exemple #7
0
    public void CreateUnit()
    {
        using var context = new InMemoryDbContext();
        var testee     = new UnitService(new SimpleCrudHelper(context, TestMapper.Create()));
        var newUnitDto = new NewUnitDto("Piece");

        testee.CreateUnit(newUnitDto);

        context.Units.Should().Contain(x => x.Name == "Piece");
    }
Exemple #8
0
    public void GetAllArticleGroups()
    {
        using var context = new InMemoryDbContext();
        context.ArticleGroups.Add(new ArticleGroup("Vegetables"));
        context.ArticleGroups.Add(new ArticleGroup("Dairy"));
        context.SaveChanges();
        var testee = new ArticleGroupService(new SimpleCrudHelper(context, TestMapper.Create()));

        var results = testee.GetAllArticleGroups();

        results.Should().Contain(x => x.Name == "Vegetables").And.Contain(x => x.Name == "Dairy");
    }
Exemple #9
0
    public void GetAllMealTypes()
    {
        using var context = new InMemoryDbContext();
        context.MealTypes.Add(new MealType("Lunch", 1));
        context.MealTypes.Add(new MealType("Breakfast", 2));
        context.SaveChanges();
        var testee = new MealTypeService(new SimpleCrudHelper(context, TestMapper.Create()));

        var results = testee.GetAllMealTypes();

        results.Should().Contain(x => x.Name == "Lunch").And.Contain(x => x.Name == "Breakfast");
    }
Exemple #10
0
    public void GetAllUnits()
    {
        using var context = new InMemoryDbContext();
        context.Units.Add(new Unit("Piece"));
        context.Units.Add(new Unit("Bag"));
        context.SaveChanges();
        var testee = new UnitService(new SimpleCrudHelper(context, TestMapper.Create()));

        var results = testee.GetAllUnits();

        results.Should().Contain(x => x.Name == "Piece").And.Contain(x => x.Name == "Bag");
    }
Exemple #11
0
    public void CreatePurchaseItem()
    {
        var newPurchaseItemDto =
            new NewPurchaseItemDto(new ExistingArticleDto(1, "Tomato", new ExistingArticleGroupDto(1, "Vegetables"), false),
                                   new ExistingUnitDto(1, "Piece"),
                                   2);
        var purchaseItemDbAccessMock = new Mock <IPurchaseItemDbAccess>();
        var testee = new PurchaseItemAction(purchaseItemDbAccessMock.Object, TestMapper.Create());

        testee.CreatePurchaseItem(newPurchaseItemDto);

        purchaseItemDbAccessMock.Verify(x => x.AddPurchaseItem(It.Is <PurchaseItem>(a => a.Article.Name == "Tomato")), Times.Once);
    }
Exemple #12
0
    public void CreateIngredient()
    {
        var newIngredientDto =
            new NewIngredientDto(new ExistingArticleDto(1, "Tomato", new ExistingArticleGroupDto(1, "Vegetables"), false),
                                 2,
                                 new ExistingUnitDto(1, "Piece"));
        var ingredientDbAccessMock = new Mock <IIngredientDbAccess>();
        var testee = new IngredientAction(ingredientDbAccessMock.Object, TestMapper.Create());

        testee.CreateIngredient(newIngredientDto);

        ingredientDbAccessMock.Verify(x => x.AddIngredient(It.Is <Ingredient>(a => a.Article.Name == "Tomato")), Times.Once);
    }
Exemple #13
0
    public void DeleteArticleGroup()
    {
        using var context = new InMemoryDbContext();
        var existingArticleGroup = context.ArticleGroups.Add(new ArticleGroup("Vegetables"));

        context.SaveChanges();
        var testee = new ArticleGroupService(new SimpleCrudHelper(context, TestMapper.Create()));
        var deleteArticleGroupDto = new DeleteArticleGroupDto(existingArticleGroup.Entity.ArticleGroupId);

        testee.DeleteArticleGroup(deleteArticleGroupDto);

        context.ArticleGroups.Should().NotContain(x => x.Name == "Vegetables");
    }
Exemple #14
0
    public void DeleteMealType()
    {
        using var context = new InMemoryDbContext();
        var existingMealType = context.MealTypes.Add(new MealType("Lunch", 1));

        context.SaveChanges();
        var testee            = new MealTypeService(new SimpleCrudHelper(context, TestMapper.Create()));
        var deleteMealTypeDto = new DeleteMealTypeDto(existingMealType.Entity.MealTypeId);

        testee.DeleteMealType(deleteMealTypeDto);

        context.MealTypes.Should().NotContain(x => x.Name == "Lunch");
    }
Exemple #15
0
    public void DeleteUnit()
    {
        using var context = new InMemoryDbContext();
        var existingUnit = context.Units.Add(new Unit("Piece"));

        context.SaveChanges();
        var testee        = new UnitService(new SimpleCrudHelper(context, TestMapper.Create()));
        var deleteUnitDto = new DeleteUnitDto(existingUnit.Entity.UnitId);

        testee.DeleteUnit(deleteUnitDto);

        context.Units.Should().NotContain(x => x.Name == "Piece");
    }
Exemple #16
0
    public void DeleteArticle()
    {
        var deleteArticleGroupDto = new DeleteArticleDto(3);
        var articleDbAccessMock   = new Mock <IArticleDbAccess>();

        articleDbAccessMock.Setup(x => x.GetArticle(3)).Returns(new Article {
            Name = "Cheese", ArticleGroup = new ArticleGroup("Diary"), IsInventory = false
        });
        var testee = new ArticleAction(articleDbAccessMock.Object, TestMapper.Create());

        testee.DeleteArticle(deleteArticleGroupDto);

        articleDbAccessMock.Verify(x => x.DeleteArticle(It.Is <Article>(a => a.Name == "Cheese")), Times.Once);
    }
Exemple #17
0
    public void DeletePurchaseItem()
    {
        var deletePurchaseItemGroupDto = new DeletePurchaseItemDto(3);
        var purchaseItemDbAccessMock   = new Mock <IPurchaseItemDbAccess>();

        purchaseItemDbAccessMock.Setup(x => x.GetPurchaseItem(3))
        .Returns(new PurchaseItem(new Article {
            Name = "Tomato", ArticleGroup = new ArticleGroup("Vegetables"), IsInventory = false
        },
                                  2,
                                  new Unit("Piece")));
        var testee = new PurchaseItemAction(purchaseItemDbAccessMock.Object, TestMapper.Create());

        testee.DeletePurchaseItem(deletePurchaseItemGroupDto);

        purchaseItemDbAccessMock.Verify(x => x.DeletePurchaseItem(It.Is <PurchaseItem>(a => a.Article.Name == "Tomato")), Times.Once);
    }
Exemple #18
0
    public void DeleteIngredient()
    {
        var deleteIngredientGroupDto = new DeleteIngredientDto(3);
        var ingredientDbAccessMock   = new Mock <IIngredientDbAccess>();

        ingredientDbAccessMock.Setup(x => x.GetIngredient(3))
        .Returns(new Ingredient(new Article {
            Name = "Tomato", ArticleGroup = new ArticleGroup("Vegetables"), IsInventory = false
        },
                                2,
                                new Unit("Piece")));
        var testee = new IngredientAction(ingredientDbAccessMock.Object, TestMapper.Create());

        testee.DeleteIngredient(deleteIngredientGroupDto);

        ingredientDbAccessMock.Verify(x => x.DeleteIngredient(It.Is <Ingredient>(a => a.Article.Name == "Tomato")), Times.Once);
    }
Exemple #19
0
    public void CreateArticleGroup()
    {
        using var context = new InMemoryDbContext();
        var testee             = new ArticleGroupService(new SimpleCrudHelper(context, TestMapper.Create()));
        var newArticleGroupDto = new NewArticleGroupDto("Vegetables");

        testee.CreateArticleGroup(newArticleGroupDto);

        context.ArticleGroups.Should().Contain(x => x.Name == "Vegetables");
    }