public void TestExistingIngredientsReturnsCopyOfExistingIngredientsList()
        {
            // Clear existing ingredients
            ExistingIngredientsService.InjectIngredients(new List <string>());

            List <string> existingIngredients = ExistingIngredientsService.ExistingIngredients;

            Assert.Empty(existingIngredients);

            // Now inject new list

            List <string> ingredientsToInject = new List <string>();

            ingredientsToInject.Add("Red Lentils");

            ExistingIngredientsService.InjectIngredients(ingredientsToInject);

            existingIngredients = ExistingIngredientsService.ExistingIngredients;

            // Now add new ingredient to returned list

            existingIngredients.Add("Olive Oil");

            // Retrieve list of service

            List <string> updatedIngredientsList = ExistingIngredientsService.ExistingIngredients;

            Assert.NotEqual(existingIngredients, updatedIngredientsList);
        }
        public void TestInjectIngredientsWithNullStringListThrowsArgumentNullException()
        {
            List <string> ingredients = null;

            Action inject = () => ExistingIngredientsService.InjectIngredients(ingredients);

            Assert.Throws <ArgumentNullException>(inject);
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
                });
            });


            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.InvalidModelStateResponseFactory = context =>
                {
                    return(new BadRequestObjectResult(new ErrorModelView("request body not formatted")));
                };
            });

            // services.AddDbContext<SQLite3DbContext>(
            //   options => options.UseSqlite(Configuration.GetConnectionString("sqlite3"))
            // );

            services.AddDbContext <InMemoryDbContext>(
                options => options.UseInMemoryDatabase("inmemory")
                );

            services.AddScoped <RepositoryFactory, InMemoryRepositoryFactoryImpl>();


            // Load existing allergens, ingredients, meal types and descriptors

            var jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,

                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var jsonString = File.ReadAllText("existingdata.json");

            ExistingDataModelView modelview = JsonSerializer.Deserialize <ExistingDataModelView>(jsonString, jsonOptions);

            ExistingAllergensService.InjectAllergens(modelview.Allergens);

            ExistingIngredientsService.InjectIngredients(modelview.Ingredients);

            ExistingMealTypesService.InjectMealTypes(modelview.MealTypes);

            ExistingDescriptorsService.InjectDescriptors(modelview.Descriptors);
        }
        public void TestInjectIngredientsWithStringListThatDoesNotContainNullOrDuplicatedElementsCompletesSuccessfuly()
        {
            List <string> ingredients = new List <string>();

            ingredients.Add("Olive Oil");

            ingredients.Add("Red Lentils");

            ingredients.Add("Milk");

            ExistingIngredientsService.InjectIngredients(ingredients);
        }
        public void TestInjectIngredientsWithNullStringListElementsThrowsArgumentNullException()
        {
            List <string> ingredients = new List <string>();

            ingredients.Add("Red Lentils");

            ingredients.Add(null);

            Action inject = () => ExistingIngredientsService.InjectIngredients(ingredients);

            Assert.Throws <ArgumentNullException>(inject);
        }
Exemplo n.º 6
0
        // Inject existing ingredients before running tests
        public IngredientUnitTest()
        {
            List <string> existingIngredients = new List <string>();

            existingIngredients.Add("Olive Oil");

            existingIngredients.Add("Red Lentils");

            existingIngredients.Add("Milk");

            ExistingIngredientsService.InjectIngredients(existingIngredients);
        }
        public void TestInjectIngredientsWithDuplicatedElementsOnStringListThrowsArgumentException()
        {
            List <string> ingredients = new List <string>();

            ingredients.Add("Red Lentils");

            ingredients.Add("Olive Oil");

            ingredients.Add("red Lentils");

            Action inject = () => ExistingIngredientsService.InjectIngredients(ingredients);

            Assert.Throws <ArgumentException>(inject);
        }
Exemplo n.º 8
0
        // Inject existing meal types, ingredients, descriptors and allergens
        // before tests

        public MealUnitTest()
        {
            List <string> existingMealTypes = new List <string>();

            existingMealTypes.Add("Soup");

            existingMealTypes.Add("Main Course");

            existingMealTypes.Add("Dessert");

            ExistingMealTypesService.InjectMealTypes(existingMealTypes);


            List <string> existingIngredients = new List <string>();

            existingIngredients.Add("Olive Oil");

            existingIngredients.Add("Red Lentils");

            existingIngredients.Add("Milk");

            ExistingIngredientsService.InjectIngredients(existingIngredients);


            Dictionary <string, List <string> > descriptors = new Dictionary <string, List <string> >();

            descriptors.Add("Salt", new List <string>(new string[] { "g", "mg" }));

            descriptors.Add("Fibre", new List <string>(new string[] { "g", "mg" }));

            descriptors.Add("Fat", new List <string>(new string[] { "g", "mg" }));

            descriptors.Add("Calorie", new List <string>(new string[] { "cal", "kcal" }));

            ExistingDescriptorsService.InjectDescriptors(descriptors);


            List <string> existingAllergens = new List <string>();

            existingAllergens.Add("Celery");

            existingAllergens.Add("Nuts");

            existingAllergens.Add("Oat");

            ExistingAllergensService.InjectAllergens(existingAllergens);
        }
        public void TestExistingIngredientsReturnsInjectedIngredients()
        {
            // Clear existing ingredients
            ExistingIngredientsService.InjectIngredients(new List <string>());

            List <string> existingIngredients = ExistingIngredientsService.ExistingIngredients;

            Assert.Empty(existingIngredients);

            // Now inject new list

            List <string> ingredientsToInject = new List <string>();

            ingredientsToInject.Add("Red Lentils");

            ExistingIngredientsService.InjectIngredients(ingredientsToInject);

            List <string> expectedIngredients = new List <string>(ingredientsToInject);

            existingIngredients = ExistingIngredientsService.ExistingIngredients;

            Assert.Equal(expectedIngredients, existingIngredients);
        }