public void ReadElementById_Invalid_Input() { var dbContext = new Mock <IDbContext>(); var logger = new Mock <ILogger <IngredientsDbService> >(); var ingrDbService = new IngredientsDbService(dbContext.Object, logger.Object); Assert.Null(ingrDbService.ReadElementById(0)); Assert.Null(ingrDbService.ReadElementById(-1)); }
public void ReadElementById_Valid_Data_In_Table() { var ingredient = Utils.CreateMockDbSet(new List <Ingredient> { new Ingredient() { IngredientID = 1, Name = "Test" } }); var dbContext = new Mock <IDbContext>(); dbContext.Setup(d => d.Ingredients).Returns(ingredient.Object); var logger = new Mock <ILogger <IngredientsDbService> >(); var ingrDbService = new IngredientsDbService(dbContext.Object, logger.Object); var result = ingrDbService.ReadElementById(1); 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(result.IngredientID == 1); Assert.True(result.Name == "Test"); }
public void ReadElementById_Valid_Input_No_Such_Table() { var dbContext = new Mock <IDbContext>(); var logger = new Mock <ILogger <IngredientsDbService> >(); var ingrDbService = new IngredientsDbService(dbContext.Object, logger.Object); var result = ingrDbService.ReadElementById(1); 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); }