示例#1
0
        public void GetBlacklistForUserShouldReturnCorrectNumberOfRestaurantsWhenUsernameFound(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.GetBlacklistForUserAsync(username).Result.ToList();
                }
                else
                {
                    results = uRepo.GetBlacklistForUser(username).ToList();
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.Equal(expected, results.Count);
        }
示例#2
0
        public void GetBlacklistForUserShouldThrowExceptionIfIsUsernameNotFound(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.GetBlacklistForUserAsync(username).Wait();
                    }
                    else
                    {
                        uRepo.GetBlacklistForUser(username);
                    }
                }
                catch (NotSupportedException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }