public void TestExistingAllergensReturnsCopyOfExistingAllergensList() { // Clear existing allergens ExistingAllergensService.InjectAllergens(new List <string>()); List <string> existingAllergens = ExistingAllergensService.ExistingAllergens; Assert.Empty(existingAllergens); // Now inject new list List <string> allergensToInject = new List <string>(); allergensToInject.Add("Nut"); ExistingAllergensService.InjectAllergens(allergensToInject); existingAllergens = ExistingAllergensService.ExistingAllergens; // Now add new allergen to returned list existingAllergens.Add("Milk"); // Retrieve list of service List <string> updatedAllergensList = ExistingAllergensService.ExistingAllergens; Assert.NotEqual(existingAllergens, updatedAllergensList); }
public void TestInjectAllergensWithNullStringListThrowsArgumentNullException() { List <string> allergens = null; Action inject = () => ExistingAllergensService.InjectAllergens(allergens); Assert.Throws <ArgumentNullException>(inject); }
// 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 TestInjectAllergensWithStringListThatDoesNotContainNullOrDuplicatedElementsCompletesSuccessfuly() { List <string> allergens = new List <string>(); allergens.Add("Nut"); allergens.Add("Soy"); allergens.Add("Milk"); ExistingAllergensService.InjectAllergens(allergens); }
public void TestInjectAllergensWithNullStringListElementsThrowsArgumentNullException() { List <string> allergens = new List <string>(); allergens.Add("Nut"); allergens.Add(null); Action inject = () => ExistingAllergensService.InjectAllergens(allergens); Assert.Throws <ArgumentNullException>(inject); }
// Inject existing allergens before running tests public AllergenUnitTest() { List <string> existingAllergens = new List <string>(); existingAllergens.Add("Celery"); existingAllergens.Add("Nuts"); existingAllergens.Add("Oat"); ExistingAllergensService.InjectAllergens(existingAllergens); }
public void TestInjectAllergensWithDuplicatedElementsOnStringListThrowsArgumentException() { List <string> allergens = new List <string>(); allergens.Add("Nut"); allergens.Add("Soy"); allergens.Add("nut"); Action inject = () => ExistingAllergensService.InjectAllergens(allergens); Assert.Throws <ArgumentException>(inject); }
// 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 TestExistingAllergensReturnsInjectedAllergens() { // Clear existing allergens ExistingAllergensService.InjectAllergens(new List <string>()); List <string> existingAllergens = ExistingAllergensService.ExistingAllergens; Assert.Empty(existingAllergens); // Now inject new list List <string> allergensToInject = new List <string>(); allergensToInject.Add("Nut"); ExistingAllergensService.InjectAllergens(allergensToInject); List <string> expectedAllergens = new List <string>(allergensToInject); existingAllergens = ExistingAllergensService.ExistingAllergens; Assert.Equal(expectedAllergens, existingAllergens); }