示例#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 ActionResult Create(FavoriteCreate model)
        {
            if (ModelState.IsValid)
            {
                return(View(model));
            }

            var userId   = Guid.Parse(User.Identity.GetUserId());
            var services = new FavoriteService(userId);

            services.CreateFavorite(model);

            return(RedirectToAction("Index"));
        }
示例#3
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);
            }
        }