Exemplo n.º 1
0
        public void GetUserByUsernameShouldReturnUserWithMatchingUsername(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;

            AppUser     u;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    u = uRepo.GetUserByUsernameAsync(username).Result;
                }
                else
                {
                    u = uRepo.GetUserByUsername(username);
                }
            }

            //Assert
            Assert.Equal(username, u.Username);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void DBContainsUsernameShouldReturnFalseIfUsernameNotInDB(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            bool        result;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    result = uRepo.DBContainsUsernameAsync(username).Result;
                }
                else
                {
                    result = uRepo.DBContainsUsername(username);
                }
            }
            //Assert
            Assert.False(result);
        }
        public ActionResult Delete(AppUser account)
        {
            AppUserRepo repo = new AppUserRepo();

            repo.DeleteAccount(account.userID);
            return(RedirectToAction("Index", "Home", new { }));
        }
Exemplo n.º 5
0
        public void DBContainsUsernameShouldNotThrowExceptionIfDBIsEmpty(bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB2")
                          .Options;

            bool        result = true;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    uRepo.DBContainsUsernameAsync("LiterallyAnything").Wait();
                }
                else
                {
                    uRepo.DBContainsUsername("LiterallyAnything");
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }
Exemplo n.º 6
0
        public void DBContainsUsernameShouldReturnFalseIfIfDBIsEmpty(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB3")
                          .Options;
            bool        result;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    result = uRepo.DBContainsUsernameAsync(username).Result;
                }
                else
                {
                    result = uRepo.DBContainsUsername(username);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.False(result);
        }
Exemplo n.º 7
0
        public void AddRestaurantToBlacklistShouldSucceedIfUserAndRestaurantAreValid(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            Blacklist      result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                if (useAsync)
                {
                    uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait();
                }
                else
                {
                    uRepo.AddRestaurantToBlacklist(username, rId, rRepo);
                }
                result = context.Blacklist.Find(rId, username);
            }

            //Assert
            Assert.Equal(username, result.Username);
            Assert.Equal(rId, result.RestaurantId);
        }
        public ActionResult Edit(int userID)
        {
            AppUserRepo repo    = new AppUserRepo();
            AppUser     account = repo.GetAccount(userID);

            return(View(account));
        }
Exemplo n.º 9
0
 public WorkController(IConfiguration config, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) : base(config, webHostEnvironment, httpContextAccessor)
 {
     _WorkRepo    = new WorkRepo(ConnString);
     _PaymentRepo = new PaymentRepo(ConnString);
     _JobRepo     = new JobRepo(ConnString);
     _AppUserRepo = new AppUserRepo(ConnString);
 }
Exemplo n.º 10
0
        public void GetUsersShouldNotThrowExceptionIfDBIsEmpty()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB1")
                          .Options;

            bool        result = true;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                try
                {
                    uRepo.GetUsers();
                }
                catch
                {
                    result = false;
                }
            }
            //Assert
            Assert.True(result);
        }
Exemplo n.º 11
0
        public void GetUserByUsernameShouldNotThrowExceptionIfUsernameIsInDB(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            bool        result = true;
            AppUserRepo uRepo;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                if (useAsync)
                {
                    uRepo.GetUserByUsernameAsync(username).Wait();
                }
                else
                {
                    uRepo.GetUserByUsername(username);
                }
            }
            //If exception is throw, test will exit before reaching Assert
            //Assert
            Assert.True(result);
        }
Exemplo n.º 12
0
        public ActionResult Edit(AppUser userAccount)
        {
            AppUserRepo repo = new AppUserRepo();

            if (ModelState.IsValid)
            {
                repo.UpdateAccount(userAccount.userID, userAccount);
                return(RedirectToAction("Details", new { userID = userAccount.userID }));
            }
            return(View());
        }
Exemplo n.º 13
0
        public ActionResult Create(AppUser newUser)
        {
            AppUserRepo repo = new AppUserRepo();

            if (ModelState.IsValid)
            {
                repo.AddAccount(newUser);

                return(RedirectToAction("Details", new { userID = newUser.userID }));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 14
0
        public void AddRestaurantToFavoritesShouldThrowExceptionIfRestrauntAlreadyInUsersBlacklist(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddFavoritesTestingDB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            bool           result = false;

            using (var context = new Project2DBContext(options))
            {
                context.Favorite.Add(new Favorite {
                    Username = username, RestaurantId = rId
                });
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.AddRestaurantToFavoritesAsync(username, rId, rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToFavorites(username, rId, rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Exemplo n.º 15
0
        public void GetUsersShouldReturnAListWithProperNumberOfUsers()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "StaticFilledUserDB")
                          .Options;
            AppUserRepo    uRepo;
            List <AppUser> uList;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                uList = uRepo.GetUsers().ToList();
            }
            //Assert
            Assert.Equal(4, uList.Count);
        }
Exemplo n.º 16
0
        public virtual async Task <AppUser_Dto> RegisterAsync(RegisterDto input)
        {
            await CheckSelfRegistrationAsync();

            var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.EmailAddress, CurrentTenant.Id);

            (await UserManager.CreateAsync(user, input.Password)).CheckErrors();

            await UserManager.SetEmailAsync(user, input.EmailAddress);

            await UserManager.AddDefaultRolesAsync(user);

            var appUser = await AppUserRepo.GetAsync(x => x.Id == user.Id);

            appUser.EmployeeId = input.EmployeeId;

            var result = await AppUserRepo.UpdateAsync(appUser);

            return(ObjectMapper.Map <AppUser, AppUser_Dto>(result));
        }
Exemplo n.º 17
0
        public ActionResult LogIn(string userName, string passWord)
        {
            //call repo method to get account absed on username
            AppUserRepo repo = new AppUserRepo();

            var user = repo.GetUser(userName);

            if (user == null)
            {
                ViewBag.Error = "No account with that username";
                return(View());
            }
            if (user.passWord != passWord)
            {
                ViewBag.Error = "Incorrect password";
                return(View());
            }

            // pass accounts user ID to details view
            return(RedirectToAction("Details", new { userID = user.userID }));
        }
Exemplo n.º 18
0
 public UnitOfWork(ExamicaDbContext _context)
 {
     context              = _context;
     Answers              = new AnswerRepo(_context);
     AppUsers             = new AppUserRepo(_context);
     ComplexQuestions     = new ComplexQuestionRepo(_context);
     ExamAppUsers         = new ExamAppUserRepo(_context);
     ExamComplexQuestions = new ExamComplexQuestionRepo(_context);
     ExamQuestions        = new ExamQuestionRepo(_context);
     Exams                    = new ExamRepo(_context);
     Options                  = new OptionRepo(_context);
     OrganizationAdmins       = new OrganizationAdminRepo(_context);
     organizationExaminees    = new OrganizationExamineeRepo(_context);
     OrganizationExaminers    = new OrganizationExaminerRepo(_context);
     OrganizationObservers    = new OrganizationObsereverRepo(_context);
     Organizations            = new OrganizationRepo(_context);
     QuestionComplexQuestions = new QuestionComplexQuestionRepo(_context);
     Questions                = new QuestionRepo(_context);
     QuestionOptions          = new QuestionOptionRepo(_context);
     Results                  = new ResultRepo(_context);
     PricingPlans             = new PricingPlanRepo(_context);
 }
Exemplo n.º 19
0
        public void AddRestaurantToFavoritesShouldThrowExceptionIfUserNotInDB(string username, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyDB9")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.AddRestaurantToFavoritesAsync(username, "literally anything", rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToFavorites(username, "literally anything", rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Exemplo n.º 20
0
        public void AddRestaurantToBlacklistShouldThrowExceptionIfRestaurantNotInDB(string username, string rId, bool useAsync)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddTesting3DB")
                          .Options;
            AppUserRepo    uRepo;
            RestaurantRepo rRepo;
            bool           result = false;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                rRepo = new RestaurantRepo(context);
                try
                {
                    if (useAsync)
                    {
                        uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait();
                    }
                    else
                    {
                        uRepo.AddRestaurantToBlacklist(username, rId, rRepo);
                    }
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
                catch (AggregateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Exemplo n.º 21
0
        public void AddUserShouldThrowExceptionIfUsernameAlreadyInDB(string username)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddTesting1DB")
                          .Options;

            AppUser u = new AppUser {
                Username = username, FirstName = "a", LastName = "b", Email = "e"
            };
            AppUser u2 = new AppUser {
                Username = username, FirstName = "blah", LastName = "bleh", Email = "e"
            };
            AppUserRepo uRepo;
            bool        result = false;

            using (var context = new Project2DBContext(options))
            {
                context.AppUser.Add(u2);
                context.SaveChanges();
            }

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                try
                {
                    uRepo.AddUser(u);
                }
                catch (DbUpdateException)
                {
                    result = true;
                }
            }

            //Assert
            Assert.True(result);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        public void AddUserShouldAddCorrectUsertoDB(string username)
        {
            //Arrange
            var options = new DbContextOptionsBuilder <Project2DBContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyAddTesting2DB")
                          .Options;

            AppUser u = new AppUser {
                Username = username, FirstName = "a", LastName = "b", Email = "e"
            };
            AppUserRepo uRepo;
            AppUser     result;

            //Act
            using (var context = new Project2DBContext(options))
            {
                uRepo = new AppUserRepo(context);
                uRepo.AddUser(u);
                result = context.AppUser.Find(username);
            }

            //Assert
            Assert.Equal(u, result);
        }
Exemplo n.º 24
0
 public AccountController(IConfiguration config, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) : base(config, webHostEnvironment, httpContextAccessor)
 {
     _AppUserRepo = new AppUserRepo(ConnString);
 }