public void CanGetComments(string input, string expected) { WorkGram workGram = new WorkGram(); workGram.Comments = input; Assert.Equal(expected, workGram.Comments); }
public void CanGetViewsCount(int input, int expected) { WorkGram workGram = new WorkGram(); workGram.Views = input; Assert.Equal(expected, workGram.Views); }
public void something() { WorkGram workGram = new WorkGram(); workGram.UserName = "******"; Assert.Equal("user One", workGram.UserName); }
public void CanGetTitleOfUser(string input, string expected) { WorkGram workGram = new WorkGram(); workGram.Title = input; Assert.Equal(expected, workGram.Title); }
public async Task DeleteAsync(int id) { WorkGram workGram = await _context.WorkGrams.FindAsync(id); if (workGram != null) { _context.Remove(workGram); await _context.SaveChangesAsync(); } }
public async Task SaveAsync(WorkGram workGram) { //Creating a new WorkGram if database does not exsist. if (await _context.WorkGrams.FirstOrDefaultAsync(make => make.ID == workGram.ID) == null) { _context.WorkGrams.Add(workGram); } else //Database does exsist, so go to update instead. { _context.WorkGrams.Update(workGram); } await _context.SaveChangesAsync(); }
public async void CrudUsersInDb() { DbContextOptions <WorkGramDbContext> options = new DbContextOptionsBuilder <WorkGramDbContext>() .UseInMemoryDatabase("GetUserName") .Options; using (WorkGramDbContext context = new WorkGramDbContext(options)) { //Arrange (CREATE) WorkGram workGram = new WorkGram(); workGram.UserName = "******"; context.WorkGrams.Add(workGram); context.SaveChanges(); //Act (READ) var userName = await context.WorkGrams.FirstOrDefaultAsync(x => x.UserName == workGram.UserName); //Assert Assert.Equal("UserOne", workGram.UserName); //UPDATE workGram.UserName = "******"; context.Update(userName); context.SaveChanges(); var updateUser = await context.WorkGrams.FirstOrDefaultAsync(x => x.UserName == workGram.UserName); Assert.Equal("updated User", updateUser.UserName); //DELETE context.WorkGrams.Remove(updateUser); context.SaveChanges(); var deleteUser = await context.WorkGrams.FirstOrDefaultAsync(x => x.UserName == workGram.UserName); Assert.True(deleteUser == null); } }
public async void CrudViewsInDb() { DbContextOptions <WorkGramDbContext> options = new DbContextOptionsBuilder <WorkGramDbContext>() .UseInMemoryDatabase("GetViewsname") .Options; using (WorkGramDbContext context = new WorkGramDbContext(options)) { //Arrange (CREATE) WorkGram workGram = new WorkGram(); workGram.Views = 1; context.WorkGrams.Add(workGram); context.SaveChanges(); //Act (READ) var viewsName = await context.WorkGrams.FirstOrDefaultAsync(x => x.Views == workGram.Views); //Assert Assert.Equal(1, workGram.Views); //UPDATE workGram.Views = 456; context.Update(viewsName); context.SaveChanges(); var updateViews = await context.WorkGrams.FirstOrDefaultAsync(x => x.Views == workGram.Views); Assert.Equal(456, updateViews.Views); //DELETE context.WorkGrams.Remove(updateViews); context.SaveChanges(); var deleteViews = await context.WorkGrams.FirstOrDefaultAsync(x => x.Views == workGram.Views); Assert.True(deleteViews == null); } }
public async void CrudURLInDb() { DbContextOptions <WorkGramDbContext> options = new DbContextOptionsBuilder <WorkGramDbContext>() .UseInMemoryDatabase("GetURLname") .Options; using (WorkGramDbContext context = new WorkGramDbContext(options)) { //Arrange (CREATE) WorkGram workGram = new WorkGram(); workGram.URL = "https://via.placeholder.com/250"; context.WorkGrams.Add(workGram); context.SaveChanges(); //Act (READ) var urlName = await context.WorkGrams.FirstOrDefaultAsync(x => x.URL == workGram.URL); //Assert Assert.Equal("https://via.placeholder.com/250", workGram.URL); //UPDATE workGram.URL = "https://via.placeholder.com/150"; context.Update(urlName); context.SaveChanges(); var updateURL = await context.WorkGrams.FirstOrDefaultAsync(x => x.URL == workGram.URL); Assert.Equal("https://via.placeholder.com/150", updateURL.URL); //DELETE context.WorkGrams.Remove(updateURL); context.SaveChanges(); var deleteURL = await context.WorkGrams.FirstOrDefaultAsync(x => x.URL == workGram.URL); Assert.True(deleteURL == null); } }
/// <summary> /// Will get the specific data for the ID that is sent in /// </summary> /// <returns>Specific WorkGram data</returns> public async Task OnGetAsync() { WorkGram = await _workGram.FindWorkGram(ID); }
public async Task <WorkGram> FindWorkGram(int id) { WorkGram workGram = await _context.WorkGrams.FirstOrDefaultAsync(wg => wg.ID == id); return(workGram); }