Ejemplo n.º 1
0
        public void ReadAllElements_Valid_Data_In_Table()
        {
            var recipes = Utils.CreateMockDbSet(new List <Recipe>
            {
                new Recipe()
                {
                    RecipeID        = 1,
                    FinishedProduct = 10
                },
                new Recipe()
                {
                    RecipeID        = 2,
                    FinishedProduct = 20
                }
            });


            var dbContext = new Mock <IDbContext>();

            dbContext.Setup(d => d.Recipes).Returns(recipes.Object);
            var logger       = new Mock <ILogger <RecipesDbService> >();
            var rcpDbService = new RecipesDbService(dbContext.Object, logger.Object);

            var results = rcpDbService.ReadAllElements();

            logger.Verify(l => l.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Never);

            Assert.True(results.Count == 2);
            Assert.True(results.FirstOrDefault().RecipeID == 1);
            Assert.True(results.FirstOrDefault().FinishedProduct == 10);
            Assert.True(results.LastOrDefault().RecipeID == 2);
            Assert.True(results.LastOrDefault().FinishedProduct == 20);
        }
Ejemplo n.º 2
0
        public void ReadAllElements_No_Data_In_Table()
        {
            var dbContext = new Mock <IDbContext>();

            dbContext.Setup(d => d.RecipePictures).Returns <RecipesDbService>(null);
            var logger = new Mock <ILogger <RecipesDbService> >();

            var rcpDbService = new RecipesDbService(dbContext.Object, logger.Object);

            var result = rcpDbService.ReadAllElements();

            logger.Verify(l => l.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once);
            Assert.Null(result);
        }