Example #1
0
        public RecipeDto GenerateRecipe(RecipeGenerationInfoDto recipeGenerationInfoDto)
        {
            _logger.LogInformation($"Entering {nameof(GenerateRecipe)}");
            var userId = GetUserId();

            return(_homebrewingDbService.GenerateRecipe(recipeGenerationInfoDto, userId));
        }
Example #2
0
        public async void GenerateRecipe_WithoutAuthHeader_ReturnsUnauthorized()
        {
            var recipeGenerationInfoDto = new RecipeGenerationInfoDto(5.0f, "987987987", 5.5f, 10, 15, "Pale", RecipeDefaultSettings.ExtractionEfficiency);
            var response = await Client.PostJsonAsync($"{RecipeBaseUrl}/GenerateRecipe", recipeGenerationInfoDto, userId : "1234");

            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
        private RecipeGenerationInfo GetRecipeGenerationInfo(RecipeGenerationInfoDto recipeGenerationInfoDto, Style style)
        {
            var recipeGenerationInfo = _mapper.Map <RecipeGenerationInfo>(recipeGenerationInfoDto);

            recipeGenerationInfo.Style = GetBeerRecipeCoreStyle(style);
            return(recipeGenerationInfo);
        }
Example #4
0
        public async void GenerateRecipe_WithInvalidRecipe_ReturnsBadRequest()
        {
            var accessToken             = AuthHelper.GetAccessToken();
            var recipeGenerationInfoDto = new RecipeGenerationInfoDto(5.0f, null, 5.5f, 10, 15, "ESB", RecipeDefaultSettings.ExtractionEfficiency);
            var response = await Client.PostJsonAsync($"{RecipeBaseUrl}/GenerateRecipe", recipeGenerationInfoDto, accessToken, "1234");

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        private Recipe GenerateRecipe(RecipeGenerationInfoDto recipeGenerationInfoDto, Style style)
        {
            var recipeGenerationInfo = GetRecipeGenerationInfo(recipeGenerationInfoDto, style);

            var generatedRecipe = _recipeService.GenerateRecipe(recipeGenerationInfo);
            var recipeToInsert  = ConvertRecipeToDbRecipe(recipeGenerationInfoDto, style, generatedRecipe);

            return(recipeToInsert);
        }
        public RecipeDto GenerateRecipe(RecipeGenerationInfoDto recipeGenerationInfoDto, string userId)
        {
            var style          = GetStyle(recipeGenerationInfoDto.StyleId);
            var recipeToInsert = GenerateRecipe(recipeGenerationInfoDto, style);

            recipeToInsert.UserId = userId;
            InsertRecipe(recipeToInsert);
            var recipeDto = GetRecipeDto(recipeToInsert, style.Name);

            return(recipeDto);
        }
        private Recipe ConvertRecipeToDbRecipe(RecipeGenerationInfoDto recipeGenerationInfoDto, Style style, IRecipe generatedRecipe)
        {
            var recipeToInsert = _mapper.Map <Recipe>(generatedRecipe);

            recipeToInsert.ProjectedOutcome = _mapper.Map <RecipeProjectedOutcome>(recipeGenerationInfoDto);
            recipeToInsert.StyleId          = recipeGenerationInfoDto.StyleId;
            recipeToInsert.YeastId          = style.CommonYeastId;
            for (var i = 0; i < recipeToInsert.FermentableIngredients.Count; i++)
            {
                recipeToInsert.FermentableIngredients[i].FermentableId = style.CommonGrains[i].FermentableId;
            }

            for (var i = 0; i < recipeToInsert.HopIngredients.Count; i++)
            {
                recipeToInsert.HopIngredients[i].HopId = style.CommonHops[i].HopId;
            }

            return(recipeToInsert);
        }
Example #8
0
        public async void GenerateRecipe_SuccessfullyCreatesRecipe()
        {
            var accessToken = AuthHelper.GetAccessToken();

            //create ingredients for beer style to use
            var fermentable = await HomebrewDataHelper.CreateFermentable(accessToken, Client);

            var hop = await HomebrewDataHelper.CreateHop(accessToken, Client);

            var yeast = await HomebrewDataHelper.CreateYeast(accessToken, Client);

            //create beer style
            var style = await HomebrewDataHelper.CreateStyle(fermentable, hop, yeast, accessToken, Client);

            style.Should().NotBeNull();

            var recipeGenerationInfoDto = new RecipeGenerationInfoDto(5.0f, style.Id, 5.5f, 10, 15, "Pale", RecipeDefaultSettings.ExtractionEfficiency);
            var response = await Client.PostJsonAsync($"{RecipeBaseUrl}/GenerateRecipe", recipeGenerationInfoDto, accessToken, "1234");

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var generatedRecipe = await response.Content.ReadFromJsonAsync <RecipeDto>();

            generatedRecipe.Should().NotBeNull();
            generatedRecipe.Name.Should().Be(recipeGenerationInfoDto.Name);
            generatedRecipe.Size.Should().Be(recipeGenerationInfoDto.Size);
            generatedRecipe.ProjectedOutcome.ColorSrm.Should().Be(recipeGenerationInfoDto.ColorSrm);
            generatedRecipe.ProjectedOutcome.Abv.Should().Be(recipeGenerationInfoDto.Abv);
            generatedRecipe.ProjectedOutcome.Ibu.Should().Be(recipeGenerationInfoDto.Ibu);

            generatedRecipe.FermentableIngredients.Should().ContainSingle();
            generatedRecipe.FermentableIngredients[0].FermentableId.Should().Be(fermentable.Id);
            generatedRecipe.HopIngredients.Should().ContainSingle();
            generatedRecipe.HopIngredients[0].HopId.Should().Be(hop.Id);
            generatedRecipe.YeastIngredient.Should().NotBeNull();
            generatedRecipe.YeastIngredient.Name.Should().Be(yeast.Name);
        }