Ejemplo n.º 1
0
        public static async Task <Unit> GetUnitAsync(CocktailsContext _context, int unitId)
        {
            var unit = await _context.Unit
                       .SingleOrDefaultAsync(m => m.Id == unitId);

            return(unit);
        }
Ejemplo n.º 2
0
        public static async Task <Recipe> GetRecipeAsync(CocktailsContext _context, Guid recipeId)
        {
            var recipe = await _context.Recipe
                         .SingleOrDefaultAsync(m => m.Id == recipeId);

            return(recipe);
        }
Ejemplo n.º 3
0
        public static async Task <Component> GetComponentAsync(CocktailsContext _context, Guid componentId)
        {
            var component = await _context.Component
                            .SingleOrDefaultAsync(m => m.Id == componentId);

            return(component);
        }
Ejemplo n.º 4
0
        public static async Task <List <MixType> > GetMixTypesAsync(CocktailsContext _context)
        {
            var mixTypes = await _context.MixType
                           .ToListAsync();

            return(mixTypes);
        }
Ejemplo n.º 5
0
        public static async Task <List <Library> > GetLibrariessAsync(CocktailsContext _context)
        {
            var libraries = await _context.Library
                            .ToListAsync();

            return(libraries);
        }
Ejemplo n.º 6
0
        public static async Task <MixType> GetMixTypeAsync(CocktailsContext _context, int mixTypeId)
        {
            var mixType = await _context.MixType
                          .SingleOrDefaultAsync(mbox => mbox.Id == mixTypeId);

            return(mixType);
        }
Ejemplo n.º 7
0
        public static async Task <Library> GetLibraryAsync(CocktailsContext _context, Guid libraryId)
        {
            var library = await _context.Library
                          .SingleOrDefaultAsync(m => m.Id == libraryId);

            return(library);
        }
Ejemplo n.º 8
0
        public static async Task <ComponentType> GetComponentTypeAsync(CocktailsContext _context, int componentTypeId)
        {
            var componentType = await _context.ComponentType
                                .SingleOrDefaultAsync(m => m.Id == componentTypeId);

            return(componentType);
        }
Ejemplo n.º 9
0
        public static async Task <Ingredient> GetIngredientAsync(CocktailsContext _context, Guid ingredientId)
        {
            var ingredient = await _context.Ingredient
                             .SingleOrDefaultAsync(m => m.Id == ingredientId);

            return(ingredient);
        }
Ejemplo n.º 10
0
        public static async Task <List <Unit> > GetUnitsAsync(CocktailsContext _context)
        {
            var units = await _context.Unit
                        .ToListAsync();

            return(units);
        }
Ejemplo n.º 11
0
 public RecipesController(CocktailsContext context, IRecipeService recipeService,
                          ILibraryService libraryService)
 {
     _context        = context;
     _recipeService  = recipeService;
     _libraryService = libraryService;
 }
Ejemplo n.º 12
0
        public static async Task <List <Recipe> > GetRecipesAsync(CocktailsContext _context)
        {
            var recipes = await _context.Recipe
                          .OrderBy(t => t.Name)
                          .ToListAsync();

            return(recipes);
        }
Ejemplo n.º 13
0
        public LibraryImporterTests()
        {
            var builder = new DbContextOptionsBuilder <CocktailsContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            _db  = new CocktailsContext(builder.Options);
            _sut = new LibraryImporter(_db);
        }
Ejemplo n.º 14
0
        public static async Task <List <Ingredient> > GetIngredientsAsync(CocktailsContext _context)
        {
            var ingredients = await _context.Ingredient
                              .OrderBy(t => t.Number)
                              .ToListAsync();

            return(ingredients);
        }
Ejemplo n.º 15
0
        public static async Task <List <ComponentType> > GetComponentTypesAsync(CocktailsContext _context)
        {
            var componentTypes = await _context.ComponentType
                                 .OrderBy(t => t.Name)
                                 .ToListAsync();

            return(componentTypes);
        }
Ejemplo n.º 16
0
        public static async Task <ComponentViewModel> GetComponentViewModelAsync(CocktailsContext _context, Guid id)
        {
            var component = await GetComponentAsync(_context, id);

            var componentType = await GetComponentTypeAsync(_context, component.ComponentTypeId);

            var model = new ComponentViewModel(component, componentType);

            return(model);
        }
Ejemplo n.º 17
0
        public static async Task <List <Ingredient> > GetIngredientsByRecipeAsync(CocktailsContext _context, Guid recipeId)
        {
            var recipe = GetRecipe(_context, recipeId);

            var ingredients = await _context.Ingredient
                              .Where(t => t.RecipeId == recipeId)
                              .OrderBy(t => t.Number)
                              .ToListAsync();

            return(ingredients);
        }
Ejemplo n.º 18
0
        public static List <SelectListItem> GetUnitSelectListItems(CocktailsContext _context)
        {
            var units = GetUnits(_context);

            var items = units.ConvertAll(t => new SelectListItem()
            {
                Text  = t.Name,
                Value = t.Id.ToString()
            });

            return(items);
        }
Ejemplo n.º 19
0
        private void InitContext()
        {
            var rand = new Random();

            CocktailsContext = new CocktailsContext(CreateContextOptions());

            var flavors = Enumerable.Range(1, 100)
                          .Select(i => new Flavor
            {
                Id           = Guid.NewGuid(),
                Name         = $"Flavor{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            var categories = Enumerable.Range(1, 100)
                             .Select(i => new Category
            {
                Id           = Guid.NewGuid(),
                Name         = $"Category{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Flavors.AddRange(flavors);
            CocktailsContext.Categories.AddRange(categories);

            CocktailsContext.SaveChanges();

            var ingredients = Enumerable.Range(1, 100)
                              .Select(i => new Ingredient
            {
                Id           = Guid.NewGuid(),
                Name         = $"Ingredient{i}",
                FlavorId     = CocktailsContext.Flavors.ToArray()[i - 1].Id,
                CategoryId   = CocktailsContext.Categories.ToArray()[i - 1].Id,
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Ingredients.AddRange(ingredients);

            CocktailsContext.SaveChanges();

            var cocktails = Enumerable.Range(1, 100)
                            .Select(i => new Cocktail
            {
                Id           = Guid.NewGuid(),
                Name         = $"Cocktail{i}",
                ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next())
            });

            CocktailsContext.Cocktails.AddRange(cocktails);

            CocktailsContext.SaveChanges();
        }
Ejemplo n.º 20
0
        public static List <SelectListItem> GetComponentTypeSelectListItems(CocktailsContext _context)
        {
            var componentTypes = GetComponentTypes(_context);

            var items = componentTypes.ConvertAll(t => new SelectListItem()
            {
                Text  = t.Name,
                Value = t.Id.ToString()
            });

            return(items);
        }
Ejemplo n.º 21
0
        public static async Task <IngredientViewModel> GetIngredientViewModelAsync(CocktailsContext _context, Guid id)
        {
            var ingredient = await GetIngredientAsync(_context, id);

            var recipe = await GetRecipeAsync(_context, ingredient.RecipeId);

            var component = await GetComponentAsync(_context, ingredient.ComponentId);

            var unit = await GetUnitAsync(_context, ingredient.UnitId);

            var model = new IngredientViewModel(ingredient, recipe, component, unit);

            return(model);
        }
Ejemplo n.º 22
0
        public RecipeImporterTests()
        {
            var builder = new DbContextOptionsBuilder <CocktailsContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            _db  = new CocktailsContext(builder.Options);
            _sut = new RecipeImporter(_db);

            _db.Library.Add(new Library
            {
                Id   = LibraryId,
                Name = LibraryName
            });
            _db.SaveChanges();
        }
Ejemplo n.º 23
0
        public async Task GetFlavorWithCorrectId()
        {
            var id     = Guid.NewGuid();
            var flavor = new Flavor {
                Id = id, Name = "flavor"
            };

            CocktailsContext.Add(flavor);
            CocktailsContext.SaveChanges();

            var result = await _repository.GetSingleAsync(x => x.Where(y => y.Id == id), _token);

            Assert.IsNotNull(result);
            Assert.AreEqual(flavor.Id, result.Id);
            Assert.AreEqual(flavor.Name, result.Name);
        }
Ejemplo n.º 24
0
        public static async Task <RecipeViewModel> GetRecipeViewModelAsync(CocktailsContext _context, Guid id, bool includeIngredients = false)
        {
            var recipe = await GetRecipeAsync(_context, id);

            var library = await GetLibraryAsync(_context, recipe.LibraryId);

            var mixType = await GetMixTypeAsync(_context, recipe.MixTypeId);

            var model = new RecipeViewModel(recipe, library, mixType);

            if (includeIngredients)
            {
                model.IngredientViewModels = await GetIngredientViewModelsByRecipeAsync(_context, id);
            }

            return(model);
        }
Ejemplo n.º 25
0
        public void GetCocktailsByNameTest()
        {
            const string nameKeyword = "Name ";

            var item1 = CocktailsContext.Cocktails.ToArray()[0];
            var item2 = CocktailsContext.Cocktails.ToArray()[1];

            item1.Name = nameKeyword + 1;
            item2.Name = nameKeyword + 2;

            CocktailsContext.SaveChanges();

            var result = QueryFunctions.CocktailsByNameFunction(CocktailsContext.Cocktails, nameKeyword).ToArray();

            Assert.AreEqual(2, result.Length);
            Assert.Contains(item1, result);
            Assert.Contains(item2, result);
        }
Ejemplo n.º 26
0
        public static List <SelectListItem> GetIngredientSelectListItems(CocktailsContext _context)
        {
            var ingredients = GetIngredients(_context);

            var items = new List <SelectListItem>();

            foreach (var ingredient in ingredients)
            {
                var component = GetComponent(_context, ingredient.ComponentId);

                items.Add(new SelectListItem()
                {
                    Text  = ingredient.Number.ToString() + " " + component.Name,
                    Value = ingredient.Number.ToString()
                });
            }

            return(items);
        }
Ejemplo n.º 27
0
 public IngredientsController(CocktailsContext context)
 {
     _context = context;
 }
Ejemplo n.º 28
0
 public ComponentTypesController(CocktailsContext context)
 {
     _context = context;
 }
Ejemplo n.º 29
0
 public UnitImporter(CocktailsContext context)
 {
     _context = context;
 }
Ejemplo n.º 30
0
 public ComponentImporter(CocktailsContext context)
 {
     _context = context;
 }