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

            using (InstaDbContext context = new InstaDbContext(options))
            {
                FitnessPost post = new FitnessPost();
                post.ID          = 1;
                post.Location    = "Golds Gym";
                post.URL         = "crimson.jpeg";
                post.Description = "Doing my best to stay fit";

                FitnessPost post2 = new FitnessPost();
                post2.ID          = 2;
                post2.Location    = "Anytime fitness";
                post2.URL         = "packer.jpeg";
                post2.Description = "Loving life";

                FitMangementService fitService = new FitMangementService(context);

                await fitService.FindFitnessPost(1);

                FitnessPost find = await context.FitnessPosts.FirstOrDefaultAsync(r => r.ID == post.ID);

                Assert.Equal("Golds Gym", post.Location);
            }
        }
Example #2
0
        public async void CanGetAllPosts()
        {
            DbContextOptions <InstaDbContext> options =
                new DbContextOptionsBuilder <InstaDbContext>
                    ().UseInMemoryDatabase("GetPosts").Options;

            using (InstaDbContext context = new InstaDbContext(options))
            {
                FitnessPost post = new FitnessPost();
                post.ID          = 1;
                post.Location    = "Golds Gym";
                post.URL         = "crimson.jpeg";
                post.Description = "Doing my best to stay fit";

                FitnessPost post2 = new FitnessPost();
                post2.ID          = 2;
                post2.Location    = "Anytime fitness";
                post2.URL         = "packer.jpeg";
                post2.Description = "Loving life";

                FitMangementService fitService = new FitMangementService(context);
                await context.FitnessPosts.AddAsync(post);

                await context.FitnessPosts.AddAsync(post2);

                await context.SaveChangesAsync();

                List <FitnessPost> find = await fitService.GetFitnessPosts();

                Assert.Equal(2, find.Count);
            }
        }
Example #3
0
        public async void CanDeleteAPost()
        {
            DbContextOptions <InstaDbContext> options =
                new DbContextOptionsBuilder <InstaDbContext>
                    ().UseInMemoryDatabase("DeletePost").Options;

            using (InstaDbContext context = new InstaDbContext(options))
            {
                FitnessPost post = new FitnessPost();
                post.ID          = 1;
                post.Location    = "Golds Gym";
                post.URL         = "crimson.jpeg";
                post.Description = "Doing my best to stay fit";

                FitnessPost post2 = new FitnessPost();
                post2.ID          = 2;
                post2.Location    = "Golds Gym";
                post2.URL         = "crimson.jpeg";
                post2.Description = "Doing my best to stay fit";

                FitMangementService fitService = new FitMangementService(context);

                await fitService.DeleteAsync(post2.ID);

                var deleted = await context.FitnessPosts.FirstOrDefaultAsync(r => r.ID == post2.ID);

                Assert.Null(deleted);
            }
        }
        public async Task DeleteAsync(int id)
        {
            FitnessPost fitnessPost = await _context.FitnessPosts.FindAsync(id);

            if (fitnessPost != null)
            {
                _context.Remove(fitnessPost);
                await _context.SaveChangesAsync();
            }
        }
 public async Task SaveAsync(FitnessPost fitnessPost)
 {
     if (await _context.FitnessPosts.FirstOrDefaultAsync(m => m.ID == fitnessPost.ID) == null)
     {
         _context.FitnessPosts.Add(fitnessPost);
     }
     else
     {
         _context.FitnessPosts.Update(fitnessPost);
     }
     await _context.SaveChangesAsync();
 }
Example #6
0
 public async Task OnGet()
 {
     FitnessPost = await _FitnessPost.FindFitnessPost(ID);
 }
        public async Task <FitnessPost> FindFitnessPost(int id)
        {
            FitnessPost fitnessPost = await _context.FitnessPosts.FirstOrDefaultAsync(m => m.ID == id);

            return(fitnessPost);
        }