This object describe recipes. Labels system should connect to similar recipes. The RecipeSuspicousState is responsible for "beSure" state
Наследование: IEntity
Пример #1
0
        public static string Download(MongoEntityRepositoryBase<RecipeBasicData> mongoRepository, int recipeIndex)
        {
            string recipeId = recipeIdPrefix + recipeIndex;
            RecipeBasicData existingRecipe = mongoRepository.GetSingle(recipeId);
            if (existingRecipe != null)
                return recipeId;

            string url = string.Format(absUrlTemplate, recipeIndex);
            StringBuilder output = new StringBuilder();
            HtmlWeb webGet = new HtmlWeb();
            webGet.UserAgent = "Wget/1.4.0";
            HtmlDocument htmlDoc = webGet.Load(url);
            //webGet.StatusCode == System.Net.HttpStatusCode.OK
            log.InfoFormat("Fetching html at {0}...", url);
            string html = htmlDoc.DocumentNode.InnerHtml;

            RecipeBasicData recipe = new RecipeBasicData()
            {
                Id = recipeId,
                SourceUrl = url,
                RawHtmlResponse = html,
                RippedAt = DateTime.UtcNow
            };

            mongoRepository.Add(recipe);

            return recipeId;
        }
Пример #2
0
        public void AddAndGetTest()
        {
            MongoEntityRepositoryBase<RecipeBasicData> mongoRepository = new MongoEntityRepositoryBase<RecipeBasicData>(m_Testdb);

            //arrange
            RecipeBasicData entity = new RecipeBasicData()
            {
                Id = "RecipeId",
                Name = "RecipeName",
                Description = "Description",
                Directions = "Directions",
                Ingredients = new List<Ingredient>(),
                //Images = Image Object,
                Author = "Author",
                SourceUrl = "SourceUrl",
                RawHtmlResponse = "RawHtmlResponse",
                Labels = new List<string> { "Label1", "Label 2" },
                RippedAt = DateTime.UtcNow
            };
            entity.Ingredients.Add(new Ingredient() { Name = "Ingredient 1", Amount = new IncredientAmount() { Amount = 3.0 / 2 } } );
            entity.Ingredients.Add(new Ingredient() { Name = "Ingredient 2", Amount = new IncredientAmount() { Amount = 2 } } );

            //act
            mongoRepository.Add(entity);
            RecipeBasicData fetchedEntity = mongoRepository.GetSingle(entity.Id);

            //assert
            Assert.IsNotNull(fetchedEntity);
            Assert.AreEqual(fetchedEntity.Id, entity.Id);
            Assert.AreEqual(fetchedEntity.Name, entity.Name);
            Assert.AreEqual(fetchedEntity.Description, entity.Description);
            Assert.AreEqual(fetchedEntity.Directions, entity.Directions);
            Assert.AreEqual(fetchedEntity.Ingredients.First().Name, entity.Ingredients.First().Name);
            Assert.AreEqual(fetchedEntity.Ingredients.Last().Name, entity.Ingredients.Last().Name);
            Assert.AreEqual(fetchedEntity.Images, entity.Images);
            Assert.AreEqual(fetchedEntity.Author, entity.Author);
            Assert.AreEqual(fetchedEntity.SourceUrl, entity.SourceUrl);
            Assert.AreEqual(fetchedEntity.RawHtmlResponse, entity.RawHtmlResponse);
            Assert.AreEqual(fetchedEntity.Labels.First(), entity.Labels.First());
            Assert.AreEqual(fetchedEntity.Labels.Last(), entity.Labels.Last());
            Assert.AreEqual(fetchedEntity.Ingredients.First().Amount.Amount, entity.Ingredients.First().Amount.Amount);
            Assert.AreEqual(fetchedEntity.Ingredients.Last().Name, entity.Ingredients.Last().Name);
        }