Пример #1
0
        public async void FavoriteControllerUpdateTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("FavoritesUpdate")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                FavoriteService TestService = new FavoriteService(context);
                Favorite        favorites   = new Favorite();
                favorites.UserID = 1;
                favorites.PetID  = 2;
                favorites.Notes  = "Did this test pass?";
                await TestService.CreateFavorite(favorites);

                favorites.Notes = "Let's change the test";

                await TestService.UpdateFavorite(favorites);

                var TestFavorite = await TestService.GetFavorite(favorites.UserID, favorites.PetID);

                Assert.Equal("Let's change the test", TestFavorite.Notes);
            }
        }
Пример #2
0
        public async void CRUDFavoritesTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("Favorites")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                //CREATE
                Favorite fav     = new Favorite();
                Profile  profile = new Profile();
                profile.Username    = "******";
                profile.LocationZip = 98107;
                fav.Profile         = profile;
                fav.Notes           = "G'BOY GREGG";

                context.Favorites.Add(fav);
                context.SaveChanges();

                //READ
                var newFav = await context.Favorites.FirstOrDefaultAsync(r => r.Profile == fav.Profile);

                Assert.Equal("Greg", fav.Profile.Username);

                //UPDATE
                newFav.Notes = "BAD BOY GREG! You're Bad!";
                context.Update(newFav);
                context.SaveChanges();

                var newFavorite = await context.Favorites.FirstOrDefaultAsync(r => r.Notes == newFav.Notes);

                Assert.Equal("BAD BOY GREG! You're Bad!", newFavorite.Notes);

                //DELETE
                context.Favorites.Remove(newFavorite);
                context.SaveChanges();

                var deletedFavorite = await context.Favorites.FirstOrDefaultAsync(r => r.Profile.Username == newFavorite.Profile.Username);

                Assert.True(deletedFavorite == null);
            }
        }
Пример #3
0
        public async void ProfileControllerCreateTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("Profiles")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                ProfileService TestService = new ProfileService(context);
                Profile        profile     = new Profile();
                profile.Username    = "******";
                profile.LocationZip = 98146;
                await TestService.CreateProfile(profile);

                var TestProfile = await TestService.GetProfile("James");

                Assert.Equal("James", TestProfile.Username);
            }
        }
Пример #4
0
        public async void CRUDProfileTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("Profile")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                //CREATE
                Profile profile = new Profile();
                profile.Username    = "******";
                profile.LocationZip = 98107;

                context.Profiles.Add(profile);
                context.SaveChanges();

                //READ
                var newProfile = await context.Profiles.FirstOrDefaultAsync(r => r.Username == profile.Username);

                Assert.Equal("Greg", newProfile.Username);

                //UPDATE
                newProfile.Username = "******";
                context.Update(newProfile);
                context.SaveChanges();

                var newProf = await context.Profiles.FirstOrDefaultAsync(r => r.Username == newProfile.Username);

                Assert.Equal("Carl", newProf.Username);

                //DELETE
                context.Profiles.Remove(newProf);
                context.SaveChanges();

                var deletedProfile = await context.Profiles.FirstOrDefaultAsync(r => r.Username == newProf.Username);

                Assert.True(deletedProfile == null);
            }
        }
Пример #5
0
        public async void FavoriteControllerDeleteTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("FavoritesDelete")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                FavoriteService TestService = new FavoriteService(context);
                Favorite        favorites   = new Favorite();
                favorites.UserID = 1;
                favorites.PetID  = 2;
                favorites.Notes  = "Did this test pass?";
                await TestService.CreateFavorite(favorites);

                await TestService.DeleteFavorite(1, 2);

                var TestFavorite = await context.Favorites.FirstOrDefaultAsync(x => x.UserID == 1 && x.PetID == 2);

                Assert.Null(TestFavorite);
            }
        }
Пример #6
0
 public ProfileService(LTBDBContext context)
 {
     _context = context;
 }
Пример #7
0
 public FavoriteService(LTBDBContext context)
 {
     _context = context;
 }
Пример #8
0
 public ReviewsService(LTBDBContext context)
 {
     _context = context;
 }
Пример #9
0
 public PetController(LTBDBContext context)
 {
     _context = context;
 }