Ejemplo n.º 1
0
        public void GetOwnedRestaurantsForUserShouldReturnCorrectNumberOfRestaurantsWhenUsernameFound(string username, int expected, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            AppUserRepo       uRepo;
            List <Restaurant> results;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    results = uRepo.GetOwnedRestaurantsForUserAsync(username).Result.ToList();
                }
                else
                {
                    results = uRepo.GetOwnedRestaurantsForUser(username).ToList();
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.Equal(expected, results.Count);
        }
Ejemplo n.º 2
0
        public void GetOwnedRestaurantsForUserShouldThrowExceptionIfIsUsernameNotFound(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            bool        result = false;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.GetOwnedRestaurantsForUserAsync(username).Wait();
                    }
                    else
                    {
                        uRepo.GetOwnedRestaurantsForUser(username);
                    }
                }
                catch (NotSupportedException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }