public void DeleteRecipeTest()
        {
            // Arrange
            IDataAccessObjectFactory factory  = DatabaseFactory.GetInstance();
            IDataAccessObject        database = factory.GetDao();

            database.AddRecipe(new RecipeDto()
            {
                Name   = "Test",
                Amount = 0,
                PreparationDescription = "Preparation test",
                PreparationTime        = TimeSpan.FromMinutes(30),
                SkillLevel             = "Skill level test"
            });

            // Act
            database.DeleteRecipe("Test");

            // Assert
            List <RecipeSimplifiedDto> list = database.GetRecipeList();

            foreach (RecipeSimplifiedDto r in list)
            {
                if (r.Name == "Test")
                {
                    Assert.Fail();
                }
            }
        }
Beispiel #2
0
        public List <RecipeSimplifiedDto> GetRecipeList()
        {
            IDataAccessObject dao = daoFactory.GetDao();
            List <DataTransferObjects.RecipeSimplifiedDto> list = dao.GetRecipeList();
            List <RecipeSimplifiedDto> retVal = new List <RecipeSimplifiedDto>();

            foreach (DataTransferObjects.RecipeSimplifiedDto recipe in list)
            {
                retVal.Add(new RecipeSimplifiedDto()
                {
                    adaptee = recipe
                });
            }
            return(retVal);
        }
        public void GetRecipeListTest()
        {
            IDataAccessObjectFactory factory  = DatabaseFactory.GetInstance();
            IDataAccessObject        database = factory.GetDao();

            try
            {
                database.GetRecipeList();
            }
            catch (Exception)
            {
                Debug.WriteLine("Check connection: " + factory.GetConnectionString());
                SendEmailToDatabaseAdmin();
                Assert.Fail();
            }
        }
        public void GetRecipeTest()
        {
            // Arrange
            IDataAccessObjectFactory factory  = DatabaseFactory.GetInstance();
            IDataAccessObject        database = factory.GetDao();
            var list = database.GetRecipeList();
            int id   = list[0].IdRecipe;

            // Act
            var r = database.GetRecipe(id);

            if (r == null)
            {
                Debug.WriteLine("Check connection: " + factory.GetConnectionString());
                Assert.Fail();
            }
        }
        public void AddRecipeTest()
        {
            // Arrange
            IDataAccessObjectFactory factory  = DatabaseFactory.GetInstance();
            IDataAccessObject        database = factory.GetDao();
            RecipeDto newRecipe = new RecipeDto()
            {
                Amount = 2,
                Name   = "Test",
                PreparationDescription = "DescriptionTest",
                PreparationTime        = new TimeSpan(0, 20, 0),
                SkillLevel             = "Begginer",
                Ingredients            = new List <IngredientDto>()
                {
                    new IngredientDto()
                    {
                        Amount = 2, IngredientName = "IngredientTest", Unit = "UnitTest"
                    },
                    new IngredientDto()
                    {
                        Amount = 2, IngredientName = "IngredientTest2", Unit = "UnitTest"
                    }
                },
                Picture = ImageConverter.ImagetoByteArray(@"C:\Users\Bartek\Downloads\zupa-pomidorowa.jpg")
            };

            // Act
            database.AddRecipe(newRecipe);

            // Assert
            List <RecipeSimplifiedDto> list = database.GetRecipeList();

            foreach (RecipeSimplifiedDto r in list)
            {
                if (r.Name == "Test")
                {
                    // Cleanup and pass
                    database.DeleteRecipe("Test");
                    Assert.Pass();
                }
            }

            Debug.WriteLine("Check connection: " + factory.GetConnectionString());
            Assert.Fail();
        }
        public List <RecipeSimplifiedDto> Get()
        {
            var result = (List <RecipeSimplifiedDto>)cache.GetValue("List");

            if (result == null)
            {
                IDataAccessObject          dao  = daoFactory.GetDao();
                List <RecipeSimplifiedDto> list = dao.GetRecipeList();
                result = new List <RecipeSimplifiedDto>();
                foreach (RecipeSimplifiedDto recipe in list)
                {
                    result.Add(recipe);
                }
                cache.Add("List", result, DateTimeOffset.UtcNow.AddMinutes(15));
            }

            return(result);
        }