Exemple #1
0
        public void GetNumberOfIngredientAppearancesTest()
        {
            var testData = new List <Tuple <IList <string>, IList <string>, int> >()
            {
                new Tuple <IList <string>, IList <string>, int>(
                    new List <string>()
                {
                    "mxmxvkd kfcds sqjhc nhms (contains dairy, fish)",
                    "trh fvjkl sbzzf mxmxvkd (contains dairy)",
                    "sqjhc fvjkl (contains soy)",
                    "sqjhc mxmxvkd sbzzf (contains fish)",
                },
                    new List <string>()
                {
                    "kfcds", "nhms", "sbzzf", "trh"
                },
                    5)
            };

            foreach (var testExample in testData)
            {
                var ingredientLists = IngredientHelper.ParseInputLines(testExample.Item1);
                _ = IngredientHelper.TryGetIngredientAllergens(
                    ingredientLists,
                    out IList <IList <Tuple <string, string> > > ingredientAllergenConfigurations,
                    out IList <string> ingredientsWithNoAllergens);
                var actual = IngredientHelper.GetNumberOfIngredientAppearances(
                    ingredientLists,
                    ingredientsWithNoAllergens);
                Assert.Equal(testExample.Item3, actual);
            }
        }
Exemple #2
0
 public Stock()
 {
     _iHelper = new IngredientHelper();
     RefreshIngredients();
     InitializeComponent();
     DataContext = this;
 }
Exemple #3
0
        public void ParseInputLinesTest()
        {
            var testData = new List <Tuple <IList <string>, IList <Tuple <IList <string>, IList <string> > > > >()
            {
                new Tuple <IList <string>, IList <Tuple <IList <string>, IList <string> > > >(
                    new List <string>()
                {
                    "mxmxvkd kfcds sqjhc nhms (contains dairy, fish)",
                    "trh fvjkl sbzzf mxmxvkd (contains dairy)",
                    "sqjhc fvjkl (contains soy)",
                    "sqjhc mxmxvkd sbzzf (contains fish)"
                },
                    new List <Tuple <IList <string>, IList <string> > >()
                {
                    new Tuple <IList <string>, IList <string> >(
                        new List <string>()
                    {
                        "mxmxvkd", "kfcds", "sqjhc", "nhms"
                    },
                        new List <string>()
                    {
                        "dairy", "fish"
                    }),
                    new Tuple <IList <string>, IList <string> >(
                        new List <string>()
                    {
                        "trh", "fvjkl", "sbzzf", "mxmxvkd"
                    },
                        new List <string>()
                    {
                        "dairy"
                    }),
                    new Tuple <IList <string>, IList <string> >(
                        new List <string>()
                    {
                        "sqjhc", "fvjkl"
                    },
                        new List <string>()
                    {
                        "soy"
                    }),
                    new Tuple <IList <string>, IList <string> >(
                        new List <string>()
                    {
                        "sqjhc", "mxmxvkd", "sbzzf"
                    },
                        new List <string>()
                    {
                        "fish"
                    })
                })
            };

            foreach (var testExample in testData)
            {
                var actual = IngredientHelper.ParseInputLines(testExample.Item1);
                Assert.Equal(testExample.Item2, actual);
            }
        }
        public void AddIngredientFromViewModelTest()
        {
            var service = new Mock <IIngredientService>(MockBehavior.Strict);

            service.Setup(s => s.AddNewIngredient(new Ingredient {
                IngredientID = 1, Calories = 100, Carbohydrates = 1, Protein = 1, Fat = 1, Name = "Test", NumberInStock = 1, Salt = 1, Sugar = 1
            }));
            var helper = new IngredientHelper(service.Object);

            helper.AddIngredientFromViewModel(new IngredientViewModel {
                IngredientID = 1, Calories = 100, Carbohydrates = 1, Protein = 1, Fat = 1, Name = "Test", NumberInStock = 1, Salt = 1, Sugar = 1
            });
        }
Exemple #5
0
        public void TryGetIngredientAllergensTest()
        {
            var testData = new List <Tuple <IList <string>, IList <IList <Tuple <string, string> > >, IList <string> > >()
            {
                new Tuple <IList <string>, IList <IList <Tuple <string, string> > >, IList <string> >(
                    new List <string>()
                {
                    "mxmxvkd kfcds sqjhc nhms (contains dairy, fish)",
                    "trh fvjkl sbzzf mxmxvkd (contains dairy)",
                    "sqjhc fvjkl (contains soy)",
                    "sqjhc mxmxvkd sbzzf (contains fish)",
                },
                    new List <IList <Tuple <string, string> > >()
                {
                    new List <Tuple <string, string> >()
                    {
                        new Tuple <string, string>("mxmxvkd", "dairy"),
                        new Tuple <string, string>("sqjhc", "fish"),
                        new Tuple <string, string>("fvjkl", "soy")
                    }
                },
                    new List <string>()
                {
                    "kfcds", "nhms", "sbzzf", "trh"
                })
            };

            foreach (var testExample in testData)
            {
                var ingredientLists = IngredientHelper.ParseInputLines(testExample.Item1);
                var success         = IngredientHelper.TryGetIngredientAllergens(
                    ingredientLists,
                    out IList <IList <Tuple <string, string> > > ingredientAllergenConfigurations,
                    out IList <string> ingredientsWithNoAllergens);
                Assert.True(success);
                var areEqualIngredientAllergenConfigurations =
                    (testExample.Item2.Count == ingredientAllergenConfigurations.Count) &&
                    !ingredientAllergenConfigurations
                    .Where(c => !testExample.Item2
                           .Where(exc => c.Count == exc.Count &&
                                  c.All(t => exc.Contains(t)))
                           .Any())
                    .Any();
                Assert.True(areEqualIngredientAllergenConfigurations);
                var areEqualIngredientsWithNoAllergens = (ingredientsWithNoAllergens.Count == testExample.Item3.Count) &&
                                                         !ingredientsWithNoAllergens.Where(i => !testExample.Item3.Contains(i)).Any();
                Assert.True(areEqualIngredientsWithNoAllergens);
            }
        }
Exemple #6
0
        public void GetCanonicalDangerousIngredientListTest()
        {
            var testData = new List <Tuple <IList <Tuple <string, string> >, string> >()
            {
                new Tuple <IList <Tuple <string, string> >, string>(
                    new List <Tuple <string, string> >()
                {
                    new Tuple <string, string>("sqjhc", "fish"),
                    new Tuple <string, string>("mxmxvkd", "dairy"),
                    new Tuple <string, string>("fvjkl", "soy")
                },
                    "mxmxvkd,sqjhc,fvjkl")
            };

            foreach (var testExample in testData)
            {
                var actual = IngredientHelper.GetCanonicalDangerousIngredientList(testExample.Item1);
                Assert.Equal(testExample.Item2, actual);
            }
        }
        public void GetAllIngredientViewModelsTest()
        {
            var service = new Mock <IIngredientService>();

            service.Setup(s => s.GetAllIngredients()).Returns(new List <Ingredient> {
                new Ingredient {
                    IngredientID = 1, Calories = 100, Carbohydrates = 1, Protein = 1, Fat = 1, Name = "Test", NumberInStock = 1, Salt = 1, Sugar = 1
                }
            });
            var helper = new IngredientHelper(service.Object);
            var sut    = helper.GetAllIngredientViewModels();

            Assert.That(sut[0].IngredientID, Is.EqualTo(1));
            Assert.That(sut[0].Calories, Is.EqualTo(100));
            Assert.That(sut[0].Carbohydrates, Is.EqualTo(1));
            Assert.That(sut[0].Protein, Is.EqualTo(1));
            Assert.That(sut[0].Fat, Is.EqualTo(1));
            Assert.That(sut[0].Name, Is.EqualTo("Test"));
            Assert.That(sut[0].NumberInStock, Is.EqualTo(1));
            Assert.That(sut[0].Salt, Is.EqualTo(1));
            Assert.That(sut[0].Sugar, Is.EqualTo(1));
        }
 public ItemsController(SuperServiceContext db)
 {
     _itemHelper = new ItemHelper(new ItemService(db), new IngredientService(db));
     _ingHelper  = new IngredientHelper(new IngredientService(db));
 }
 public IngredientsController(SuperServiceContext context)
 {
     _context = context;
     _helper  = new IngredientHelper(new IngredientService(_context));
 }