Exemplo n.º 1
0
        public void CanGetComments(string input, string expected)
        {
            WorkGram workGram = new WorkGram();

            workGram.Comments = input;

            Assert.Equal(expected, workGram.Comments);
        }
Exemplo n.º 2
0
        public void CanGetViewsCount(int input, int expected)
        {
            WorkGram workGram = new WorkGram();

            workGram.Views = input;

            Assert.Equal(expected, workGram.Views);
        }
Exemplo n.º 3
0
        public void something()
        {
            WorkGram workGram = new WorkGram();

            workGram.UserName = "******";

            Assert.Equal("user One", workGram.UserName);
        }
Exemplo n.º 4
0
        public void CanGetTitleOfUser(string input, string expected)
        {
            WorkGram workGram = new WorkGram();

            workGram.Title = input;

            Assert.Equal(expected, workGram.Title);
        }
Exemplo n.º 5
0
        public async Task DeleteAsync(int id)
        {
            WorkGram workGram = await _context.WorkGrams.FindAsync(id);

            if (workGram != null)
            {
                _context.Remove(workGram);
                await _context.SaveChangesAsync();
            }
        }
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
0
        public async Task <WorkGram> FindWorkGram(int id)
        {
            WorkGram workGram = await _context.WorkGrams.FirstOrDefaultAsync(wg => wg.ID == id);

            return(workGram);
        }