public async void CreateGramWorksAgain() { DbContextOptions <NetGramDbContext> options = new DbContextOptionsBuilder <NetGramDbContext> ().UseInMemoryDatabase("Create").Options; using (NetGramDbContext context = new NetGramDbContext(options)) { // arrange NetGram netGram = new NetGram(); netGram.ID = 2; netGram.NamePoster = "Jason"; netGram.Caption = "Seattle"; // Act NetGramManager netGramManager = new NetGramManager(context); await netGramManager.SaveNetGram(netGram); var created = context.NetGrams.FirstOrDefault(n => n.ID == netGram.ID); // Assert Assert.Equal(netGram, created); } }
public async void EditGramWorksAgain() { DbContextOptions <NetGramDbContext> options = new DbContextOptionsBuilder <NetGramDbContext> ().UseInMemoryDatabase("Edits").Options; using (NetGramDbContext context = new NetGramDbContext(options)) { // arrange NetGram netGram = new NetGram(); netGram.ID = 2; netGram.NamePoster = "Jason"; netGram.Caption = "Seattle"; // Act NetGramManager netGramManager = new NetGramManager(context); await netGramManager.SaveNetGram(netGram); netGram.Caption = "Wow"; await netGramManager.SaveNetGram(netGram); // Assert Assert.Equal("Wow", netGram.Caption); } }
/// <summary> /// Deletes a net gram /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task Delete(int id) { NetGram netGram = await _context.NetGrams.FindAsync(id); if (netGram != null) { _context.Remove(netGram); await _context.SaveChangesAsync(); } }
public void GetWorks() { //arrange NetGram netGram = new NetGram(); netGram.Caption = "nice pic"; //assert Assert.Equal("nice pic", netGram.Caption); }
public void GetWorksAgain() { //arrange NetGram netGram = new NetGram(); netGram.Caption = "nice pic"; netGram.NamePoster = "Jason"; //assert Assert.Equal("Jason", netGram.NamePoster); }
/// <summary> /// Saves new and or updates existing netgrams /// </summary> /// <param name="netGram"></param> /// <returns></returns> public async Task SaveNetGram(NetGram netGram) { if (await _context.NetGrams.FirstOrDefaultAsync(n => n.ID == netGram.ID) == null) { _context.NetGrams.Add(netGram); } else { _context.NetGrams.Update(netGram); } await _context.SaveChangesAsync(); }
public void SetWorks() { //arrange NetGram netGram = new NetGram(); netGram.Caption = "nice pic"; netGram.NamePoster = "Jason"; //Act netGram.Caption = "crappy pic"; //assert Assert.Equal("crappy pic", netGram.Caption); }
/// <summary> /// Gets details of netgram /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <NetGram> GetDetails(int id) { NetGram netGram = await _context.NetGrams.FirstOrDefaultAsync(net => net.ID == id); return(netGram); }
public async Task OnGet() { NetGram = await _netGram.GetDetails(ID); }