Example #1
0
        public async void GetRecipes_SuccessfullyGetsRecipe()
        {
            var accessToken = AuthHelper.GetAccessToken();

            var style = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            const string userId          = "1234";
            var          generatedRecipe = await GenerateRecipe(style, accessToken, userId);

            var getRecipesResponse = await Client.GetAsync($"{RecipeBaseUrl}/GetAll", accessToken, userId);

            getRecipesResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var recipes = await getRecipesResponse.Content.ReadFromJsonAsync <List <RecipeDto> >();

            recipes.Should().ContainSingle();
            var recipe = recipes[0];

            recipe.Id.Should().Be(generatedRecipe.Id);
            recipe.Name.Should().Be(generatedRecipe.Name);
            recipe.Size.Should().Be(generatedRecipe.Size);
            recipe.ProjectedOutcome.ColorSrm.Should().Be(generatedRecipe.ProjectedOutcome.ColorSrm);
            recipe.ProjectedOutcome.Abv.Should().Be(generatedRecipe.ProjectedOutcome.Abv);
            recipe.ProjectedOutcome.Ibu.Should().Be(generatedRecipe.ProjectedOutcome.Ibu);
            recipe.FermentableIngredients.Should().BeEquivalentTo(generatedRecipe.FermentableIngredients);
            recipe.HopIngredients.Should().BeEquivalentTo(generatedRecipe.HopIngredients);
            recipe.YeastIngredient.Should().Be(generatedRecipe.YeastIngredient);
        }
        public async void GetStyle_ReturnsOk()
        {
            var accessToken = AuthHelper.GetAccessToken();
            var style       = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            var getStylesResponse = await Client.GetAsync($"{StyleBaseUrl}/GetAll", accessToken);

            getStylesResponse.EnsureSuccessStatusCode();
            var styles = await getStylesResponse.Content.ReadFromJsonAsync <List <StyleDto> >();

            styles.Should().ContainSingle();
            var styleId = styles[0].Id;

            var getStyleResponse = await Client.GetAsync($"{StyleBaseUrl}/{styleId}", accessToken);

            getStyleResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var styleFromResponse = await getStyleResponse.Content.ReadFromJsonAsync <StyleAdminDto>();

            styleFromResponse.Should().NotBeNull();
            styleFromResponse.Id.Should().Be(styleId);
            styleFromResponse.Name.Should().Be(style.Name);
            styleFromResponse.Type.Should().Be(HomebrewDataHelper.TestType);
            styleFromResponse.Thresholds.Should().BeEquivalentTo(style.Thresholds);
            styleFromResponse.CommonGrains.Should().NotBeEmpty();
            styleFromResponse.CommonHops.Should().NotBeEmpty();
            styleFromResponse.CommonYeastId.Should().NotBeNull();
        }
Example #3
0
        public async void GetRecipes_GivenDifferentUserThanOneWhoCreatedRecipe_ReturnsNoRecipes()
        {
            var accessToken = AuthHelper.GetAccessToken();

            var style = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            await GenerateRecipe(style, accessToken, "1234");

            var getRecipesResponse = await Client.GetAsync($"{RecipeBaseUrl}/GetAll", accessToken, "5678");

            getRecipesResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var recipes = await getRecipesResponse.Content.ReadFromJsonAsync <List <RecipeDto> >();

            recipes.Should().HaveCount(0);
        }
Example #4
0
        public async void GetRecipe_GivenDifferentUserThanOneWhoCreatedRecipe_ReturnsForbidden()
        {
            var accessToken = AuthHelper.GetAccessToken();

            var style = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            var generatedRecipe = await GenerateRecipe(style, accessToken, "1234");

            var getRecipeResponse = await Client.GetAsync($"{RecipeBaseUrl}/{generatedRecipe.Id}", accessToken, "5678");

            getRecipeResponse.StatusCode.Should().Be(HttpStatusCode.Forbidden);
            var recipe = await getRecipeResponse.Content.ReadAsStringAsync();

            recipe.Should().Be(string.Empty);
        }
Example #5
0
        public async void GetRecipe_GivenRecipeId_SuccessfullyGetsRecipe()
        {
            var accessToken = AuthHelper.GetAccessToken();

            var style = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            const string userId          = "1234";
            var          generatedRecipe = await GenerateRecipe(style, accessToken, userId);

            var getRecipeResponse = await Client.GetAsync($"{RecipeBaseUrl}/{generatedRecipe.Id}", accessToken, userId);

            getRecipeResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            var recipe = await getRecipeResponse.Content.ReadFromJsonAsync <RecipeDto>();

            recipe.Should().NotBeNull();
            recipe.Id.Should().Be(generatedRecipe.Id);
        }
        public async void DeleteStyle_SuccessfullyDeletesStyle()
        {
            var accessToken = AuthHelper.GetAccessToken();
            var style       = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            var response = await Client.DeleteAsync($"{StyleBaseUrl}/{style.Id}", accessToken, isContentCreator : true);

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

            var getStylesResponse = await Client.GetAsync($"{StyleBaseUrl}/GetAll", accessToken);

            getStylesResponse.EnsureSuccessStatusCode();
            var styles = await getStylesResponse.Content.ReadFromJsonAsync <List <StyleDto> >();

            styles.Should().NotBeNull();
            styles.Count.Should().Be(0);
        }
Example #7
0
        public async void UpdateRecipe_SuccessfullyUpdatesRecipe()
        {
            var accessToken = AuthHelper.GetAccessToken();

            var style = await HomebrewDataHelper.CreateStyle(accessToken, Client);

            const string userId          = "1234";
            var          generatedRecipe = await GenerateRecipe(style, accessToken, userId);

            var         updatedRecipeName        = "Updated " + generatedRecipe.Name;
            const float updatedFermentableAmount = 50.0f;
            const float updatedHopAmount         = 20.6f;
            const int   updatedHopAdditionTime   = 55;
            var         originalFermentable      = generatedRecipe.FermentableIngredients[0];
            var         originalHop      = generatedRecipe.HopIngredients[0];
            var         recipeUpdateInfo = new RecipeUpdateInfoDto(updatedRecipeName, RecipeDefaultSettings.ExtractionEfficiency)
            {
                FermentableIngredients = new List <FermentableIngredientDto>
                {
                    new(updatedFermentableAmount, originalFermentable.Name, originalFermentable.FermentableId)
                },
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);
        }