Example #1
0
        public async void DeleteHomePage()
        {
            DbContextOptions <JamesAmosDbContext> options =
                new DbContextOptionsBuilder <JamesAmosDbContext>
                    ().UseInMemoryDatabase("DeleteHomePage").Options;

            using (JamesAmosDbContext context = new JamesAmosDbContext(options))
            {
                // arrange
                HomePage homePage = new HomePage();
                homePage.ID           = 1;
                homePage.CardOneTitle = "hi";

                // Act
                context.HomePage.Add(homePage);

                context.SaveChanges();

                var toDelete = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID);

                context.HomePage.Remove(toDelete);

                context.SaveChanges();

                var deleted = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID);

                // Assert
                Assert.Null(deleted);
            }
        }
Example #2
0
        public async void EditHomePage()
        {
            DbContextOptions <JamesAmosDbContext> options =
                new DbContextOptionsBuilder <JamesAmosDbContext>
                    ().UseInMemoryDatabase("EditHomePage").Options;

            using (JamesAmosDbContext context = new JamesAmosDbContext(options))
            {
                // arrange
                HomePage homePage = new HomePage();
                homePage.ID           = 1;
                homePage.CardOneTitle = "hi";

                // Act
                context.HomePage.Add(homePage);

                context.SaveChanges();

                var created = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID);

                created.CardOneTitle = "bye";

                context.SaveChanges();
                // Assert
                Assert.Equal("bye", created.CardOneTitle);
            }
        }
Example #3
0
        public async void DeleteVlogWorks()
        {
            DbContextOptions <JamesAmosDbContext> options =
                new DbContextOptionsBuilder <JamesAmosDbContext>
                    ().UseInMemoryDatabase("DeleteVlog").Options;

            using (JamesAmosDbContext context = new JamesAmosDbContext(options))
            {
                // arrange
                Vlog vlog = new Vlog();
                vlog.ID       = 1;
                vlog.Subject  = "stuff";
                vlog.VideoUrl = "URL";

                // Act
                context.Vlogs.Add(vlog);

                context.SaveChanges();

                var toDelete = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID);

                context.Remove(toDelete);

                context.SaveChanges();

                var deleted = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID);

                // Assert
                Assert.Null(deleted);
            }
        }
Example #4
0
        public IActionResult Create(string Subject, string VideoUrl)
        {
            Vlog vlog = new Vlog();

            vlog.DateCreated = DateTime.Now;

            vlog.Subject = Subject;

            vlog.VideoUrl = VideoUrl;

            _context.Vlogs.Add(vlog);

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }