Пример #1
0
        public void TestExistingMealTypesReturnsCopyOfExistingMealTypesList()
        {
            // Clear existing meal types
            ExistingMealTypesService.InjectMealTypes(new List <string>());

            List <string> existingMealTypes = ExistingMealTypesService.ExistingMealTypes;

            Assert.Empty(existingMealTypes);

            // Now inject new list

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

            mealTypesToInject.Add("Soup");

            ExistingMealTypesService.InjectMealTypes(mealTypesToInject);

            existingMealTypes = ExistingMealTypesService.ExistingMealTypes;

            // Now add new meal type to returned list

            existingMealTypes.Add("Main Course");

            // Retrieve list of service

            List <string> updatedMealTypesList = ExistingMealTypesService.ExistingMealTypes;

            Assert.NotEqual(existingMealTypes, updatedMealTypesList);
        }
Пример #2
0
        public void TestInjectMealTypesWithNullStringListThrowsArgumentNullException()
        {
            List <string> mealTypes = null;

            Action inject = () => ExistingMealTypesService.InjectMealTypes(mealTypes);

            Assert.Throws <ArgumentNullException>(inject);
        }
Пример #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);
        }
Пример #4
0
        // Inject existing meal types before running tests
        public MealTypeUnitTest()
        {
            List <string> existingMealTypes = new List <string>();

            existingMealTypes.Add("Soup");

            existingMealTypes.Add("Main Course");

            existingMealTypes.Add("Dessert");

            ExistingMealTypesService.InjectMealTypes(existingMealTypes);
        }
Пример #5
0
        public void TestInjectMealTypesWithStringListThatDoesNotContainNullOrDuplicatedElementsCompletesSuccessfuly()
        {
            List <string> mealTypes = new List <string>();

            mealTypes.Add("Soup");

            mealTypes.Add("Main Course");

            mealTypes.Add("Dessert");

            ExistingMealTypesService.InjectMealTypes(mealTypes);
        }
Пример #6
0
        public void TestInjectMealTypesWithNullStringListElementsThrowsArgumentNullException()
        {
            List <string> mealTypes = new List <string>();

            mealTypes.Add("Soup");

            mealTypes.Add(null);

            Action inject = () => ExistingMealTypesService.InjectMealTypes(mealTypes);

            Assert.Throws <ArgumentNullException>(inject);
        }
Пример #7
0
        public void TestInjectMealTypesWithDuplicatedElementsOnStringListThrowsArgumentException()
        {
            List <string> mealTypes = new List <string>();

            mealTypes.Add("Soup");

            mealTypes.Add("Main Course");

            mealTypes.Add("soUp");

            Action inject = () => ExistingMealTypesService.InjectMealTypes(mealTypes);

            Assert.Throws <ArgumentException>(inject);
        }
Пример #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);
        }
Пример #9
0
        public void TestExistingMealTypesReturnsInjectedMealTypes()
        {
            // Clear existing meal types
            ExistingMealTypesService.InjectMealTypes(new List <string>());

            List <string> existingMealTypes = ExistingMealTypesService.ExistingMealTypes;

            Assert.Empty(existingMealTypes);

            // Now inject new list

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

            mealTypesToInject.Add("Soup");

            ExistingMealTypesService.InjectMealTypes(mealTypesToInject);

            List <string> expectedMealTypes = new List <string>(mealTypesToInject);

            existingMealTypes = ExistingMealTypesService.ExistingMealTypes;

            Assert.Equal(expectedMealTypes, existingMealTypes);
        }