public void Should_OK_GetCatById_When_Exist_Element() { var options = new DbContextOptionsBuilder <CatMashDBContext>() .UseInMemoryDatabase(databaseName: "CatMashDB4") .Options; // Run the test against one instance of the context using (var context = new CatMashDBContext(options)) { context.TCat.Add(new TCat { CatId = 78, CatUrl = "img1" }); context.TCat.Add(new TCat { CatUrl = "img2" }); context.TCat.Add(new TCat { CatUrl = "img3" }); var updateCount = context.SaveChanges(); Assert.Equal(3, updateCount); var catId = 78; var catMashRepository = new CatMashRepository(context); var result = catMashRepository.GetCatById(catId); Assert.NotNull(result); Assert.Equal(78, result.CatId); } }
public void Should_NullReferenceException_GetCatById_When_Emty_DataBase() { var options = new DbContextOptionsBuilder <CatMashDBContext>() .UseInMemoryDatabase(databaseName: "CatMashDB3") .Options; // Run the test against one instance of the context using (var context = new CatMashDBContext(options)) { var catId = 1; var catMashRepository = new CatMashRepository(context); Assert.Throws <ElementNotFoundException>(() => catMashRepository.GetCatById(catId)); } }