コード例 #1
0
        public async Task <string> GetRecipeAsJson(string recipeName)
        {
            var recipeXml = await _recipesApi.MakeHttpRequestForRecipe(recipeName);

            var doc = new XmlDocument();

            doc.LoadXml(recipeXml);
            var jsonResult = JsonConvert.SerializeXmlNode(doc);

            return(jsonResult);
        }
コード例 #2
0
        public async Task MakeHttpRequestForRecipe_Logs_Recipe()
        {
            var logger = new Mock <IApplicationLogger>();
            var api    = new RecipesApi(logger.Object);
            var result = await api.MakeHttpRequestForRecipe("mashed_potatoes");

            logger.Verify(mock
                          => mock.LogInfo(
                              It.IsAny <string>(),
                              It.IsAny <ConsoleColor>()),
                          Times.AtLeastOnce());
        }
コード例 #3
0
        public async Task MakeHttpRequestForRecipe_Gets_Value_From_Database_Given_Recipe()
        {
            var logger = new Mock <IApplicationLogger>();
            var api    = new RecipesApi(logger.Object);
            var result = await api.MakeHttpRequestForRecipe("mashed_potatoes");

            using var reader = new StringReader(result);
            var recipe = (Recipe)xml.Deserialize(reader);

            recipe.Should().NotBeNull();
            recipe.Name.Should().Be("Mashed Potatoes");
        }