public async void CanGetAllNoodle() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanGetAllNoodles") .Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Noodle noodle1 = new Noodle(); noodle1.Id = 1; noodle1.Name = "Organic Ramen"; Noodle noodle2 = new Noodle(); noodle2.Id = 2; noodle2.Name = "Shoyu Ramen"; Noodle noodle3 = new Noodle(); noodle3.Id = 3; noodle3.Name = "Bestest Ramen"; //act await context.Noodles.AddAsync(noodle1); await context.Noodles.AddAsync(noodle2); await context.Noodles.AddAsync(noodle3); await context.SaveChangesAsync(); //assert Assert.Equal(3, context.Noodles.Count()); } }
public async void CanCreateNewNoodle() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanPostNewNoodle") .Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Noodle noodle = new Noodle { Name = "Instant Noodle Shrimp", BrandId = 2, Flavor = "Tom Yum", ImgUrl = "https://www.bing.com", Description = "much tasty" }; //act await context.Noodles.AddAsync(noodle); await context.SaveChangesAsync(); NoodleController nc = new NoodleController(context); var addedNoodle = nc.Create(noodle); var results = context.Noodles.Where(x => x.Name == "Instant Noodle Shrimp"); //assert Assert.Equal(1, results.Count()); } }
public async void CanUpdateNoodle() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanUpdateNoodle").Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Noodle noodle = new Noodle { Flavor = "Tom Yum" }; NoodleController nc = new NoodleController(context); //act await context.Noodles.AddAsync(noodle); await context.SaveChangesAsync(); //the seeded data at id# 1 is Chapagetti, and this //test will override the flavor var updatedNoodle = nc.Update(1, noodle); //assert Assert.Equal("Tom Yum", noodle.Flavor); } }
public static void Initialize(NoodleContext context) { if (!context.Noodles.Any()) { context.Noodles.AddRange( new Noodle { Name = "SeaFood", Company = "Cup Noodle", Price = 4.10 }, new Noodle { Name = "Twigim Udon", Company = "Nongshim", Price = 1.25 }, new Noodle { Name = "Samyang", Company = "Nongshim", Price = 1.30 } ); context.SaveChanges(); } }
public async void CanGetBrandById() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanGetBrandById") .Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Brand brand1 = new Brand(); brand1.Id = 1; brand1.Name = "Nissan"; Brand brand2 = new Brand(); brand2.Id = 2; brand2.Name = "Nongshim"; Brand brand3 = new Brand(); brand3.Id = 3; brand3.Name = "Mama"; Brand brand4 = new Brand(); brand4.Id = 4; brand4.Name = "Maggi"; BrandController bc = new BrandController(context); //act await context.Brands.AddAsync(brand1); await context.Brands.AddAsync(brand2); await context.Brands.AddAsync(brand3); await context.Brands.AddAsync(brand4); await context.SaveChangesAsync(); var findBrand = bc.GetByID(2); //assert Assert.Equal(brand2.Name, findBrand.Result.Value.Name); } }
public async void CanDeleteNoodleByID() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanDeleteNoodlesByID") .Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Noodle noodle1 = new Noodle(); noodle1.Id = 1; noodle1.Name = "Organic Ramen"; Noodle noodle2 = new Noodle(); noodle2.Id = 2; noodle2.Name = "Shoyu Ramen"; Noodle noodle3 = new Noodle(); noodle3.Id = 3; noodle3.Name = "Bestest Ramen"; //act await context.Noodles.AddAsync(noodle1); await context.Noodles.AddAsync(noodle2); await context.Noodles.AddAsync(noodle3); await context.SaveChangesAsync(); var findNoodle = context.Noodles.Find(1); NoodleController nc = new NoodleController(context); var deletedNoodle = nc.Delete(findNoodle.Id); //assert Assert.Equal(2, context.Noodles.Count()); } }
public async void CanDeleteBrandById() { DbContextOptions <NoodleContext> options = new DbContextOptionsBuilder <NoodleContext>() .UseInMemoryDatabase("CanDeleteBrandById") .Options; using (NoodleContext context = new NoodleContext(options)) { //arrange Brand brand1 = new Brand(); brand1.Id = 1; brand1.Name = "Number111"; Brand brand2 = new Brand(); brand2.Id = 2; brand2.Name = "Number222"; Brand brand3 = new Brand(); brand3.Id = 3; brand3.Name = "Number333"; BrandController bc = new BrandController(context); //act await context.Brands.AddAsync(brand1); await context.Brands.AddAsync(brand2); await context.Brands.AddAsync(brand3); var findBrand = context.Brands.Find(1); var deletedBrand = bc.Delete(findBrand.Id); //assert Assert.Equal(2, context.Brands.Count()); } }
public HomeController(NoodleContext context) { db = context; }
/// <summary> /// Creates an instance of the BrandController class /// </summary> /// <param name="context">The Brand database context</param> public BrandController(NoodleContext context) { _context = context; }