public void TestExistingDescriptorsReturnsInjectedDescriptors(){

			// Clear existing descriptors
			ExistingDescriptorsService.InjectDescriptors(new Dictionary<string, List<string>>());

			Dictionary<string, List<string>> existingDescriptors = ExistingDescriptorsService.ExistingDescriptors;

			Assert.Empty(existingDescriptors);

			// Now inject new dictionary

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

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

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

			ExistingDescriptorsService.InjectDescriptors(descriptorsToInject);

			Dictionary<string, List<string>> expectedDescriptors = new Dictionary<string, List<string>>(descriptorsToInject.ToList());

			existingDescriptors = ExistingDescriptorsService.ExistingDescriptors;

			Assert.Equal(expectedDescriptors, existingDescriptors);
		}
		public void TestExistingDescriptorsReturnsCopyOfExistingDescriptorsList(){

			// Clear existing descriptors
			ExistingDescriptorsService.InjectDescriptors(new Dictionary<string, List<string>>());

			Dictionary<string, List<string>> existingDescriptors = ExistingDescriptorsService.ExistingDescriptors;

			Assert.Empty(existingDescriptors);

			// Now inject new dictionary

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

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

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

			ExistingDescriptorsService.InjectDescriptors(descriptorsToInject);

			existingDescriptors = ExistingDescriptorsService.ExistingDescriptors;

			// Now add new descriptor to returned dictionary

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

			// Retrieve dictionary of service

			Dictionary<string,List<string>> updatedDescriptorsDictionary = ExistingDescriptorsService.ExistingDescriptors;

			Assert.NotEqual(existingDescriptors, updatedDescriptorsDictionary);
		}
		public void TestInjectDescriptorsWithNullDictionaryThrowsArgumentNullException(){

			Dictionary<string,List<string>> descriptors = null;

			Action inject = () => ExistingDescriptorsService.InjectDescriptors(descriptors);

			Assert.Throws<ArgumentNullException>(inject);
		}
		public void TestInjectDescriptorsWithDictionaryThatDoesNotContainNullOrDuplicatedElementsOnStringListsCompletesSuccessfuly(){

			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"}));

			ExistingDescriptorsService.InjectDescriptors(descriptors);
		}
Пример #5
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 TestInjectDescriptorsWithDuplicatedElementsOnStringListThrowsArgumentException(){

			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", "g"}));

			Action inject = () => ExistingDescriptorsService.InjectDescriptors(descriptors);

			Assert.Throws<ArgumentException>(inject);
		}
        // Inject existing descriptors before running tests
        public DescriptorUnitTest()
        {
            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);
        }
Пример #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);
        }