Example #1
0
        public void Test_AddNewBudgieUser_CallsAddABudgieUserToDatabase_AndSavesChangesOnContext()
        {
            //ARRANGE
            Mock <BudgieUser> bb = new Mock <BudgieUser>();

            var testData = new List <BudgieUser>().AsQueryable();

            dbSetMock.As <IQueryable <BudgieUser> >().Setup(d => d.Provider).Returns(testData.Provider);
            dbSetMock.As <IQueryable <BudgieUser> >().Setup(d => d.Expression).Returns(testData.Expression);
            dbSetMock.As <IQueryable <BudgieUser> >().Setup(d => d.ElementType).Returns(testData.ElementType);
            dbSetMock.As <IQueryable <BudgieUser> >().Setup(d => d.GetEnumerator()).Returns(testData.GetEnumerator);

            var contextMock = new Mock <BudgieDBCFModel>();

            contextMock.Setup(c => c.budgieUsers).Returns(dbSetMock.Object);

            BudgieUserRepository classUnderTest = new BudgieUserRepository(contextMock.Object);

            //ACT
            classUnderTest.addNewBudgieUser(bb.Object);

            //ASSERT
            dbSetMock.Verify(c => c.Add(It.IsAny <BudgieUser>()), Times.Once);
            contextMock.Verify(c => c.SaveChanges(), Times.Once);
        }
Example #2
0
        public void RegisterUser(BudgieUser budgieuser)
        {
            budgieuser.roles = "User";

            budgieUserDB.addNewBudgieUser(budgieuser);

            Account newAccount = new Account()
            {
                accountNumber = budgieuser.lastName + budgieuser.dob, balance = 0, budget = 0, accountOwnerId = budgieuser.id
            };

            accountDB.addNewAccount(newAccount);
        }
Example #3
0
        static void AddUser()
        {
            string firstName, lastName, emailAddress, dob, password, confirmPassword;
            int    newAccountId = 0;

            BudgieDBCFModel      context = new BudgieDBCFModel();
            BudgieUserLogic      newUser = new BudgieUserLogic(new BudgieUserRepository(new BudgieDBCFModel()));
            BudgieUserRepository bur     = new BudgieUserRepository(context);
            AccountRepository    ar      = new AccountRepository(context);

            Console.WriteLine(); Console.WriteLine("--- Creating a new Budgie User ---"); Console.WriteLine();

            Console.WriteLine("Please enter your email address (e.g. [email protected]): ");
            emailAddress = (Console.ReadLine());
            bool isInDatabase = newUser.CheckForDuplicateEmail(emailAddress);

            if (isInDatabase == true)
            {
                Console.WriteLine("This email is already in use, please quit and log into your original account or restart the application and try again.");
            }
            else
            {
                Console.WriteLine();

                Console.WriteLine("Please enter your first name (e.g. Ben): ");
                firstName = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your last name (e.g. Bowes): ");
                lastName = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your date of birth (e.g. DDMMYY (040191)): ");
                dob = (Console.ReadLine());

                Console.WriteLine();

                Console.WriteLine("Please enter your new password: "******"Please confirm your new password: "******"Your passwords do not match, please restart the application and try again.");
                    Console.WriteLine();
                    RestartApplication();
                }
                else
                {
                    //Add
                    BudgieUser newBudgieUser = new BudgieUser()
                    {
                        firstName = firstName, lastName = lastName, emailAddress = emailAddress, dob = dob, password = password
                    };

                    bur.addNewBudgieUser(newBudgieUser);
                    //context.budgieUsers.Add(newBudgieUser);

                    //context.SaveChanges();

                    Console.WriteLine("New BudgieUser has been successfully registered: Name = " + newBudgieUser.firstName + " " + newBudgieUser.lastName);
                    Console.WriteLine();
                    Console.WriteLine("Automatically creating a new bank account...");
                    Console.WriteLine();

                    foreach (BudgieUser budgieUser in context.budgieUsers)
                    {
                        if (emailAddress == budgieUser.emailAddress)
                        {
                            newAccountId = budgieUser.id;
                        }
                    }

                    Account newAccount = new Account()
                    {
                        accountNumber = lastName + dob, balance = 0, budget = 0, accountOwnerId = newAccountId
                    };

                    ar.addNewAccount(newAccount);
                    //context.accounts.Add(newAccount);

                    Console.WriteLine("Your new account has been successfully created: Account Number = " + newAccount.accountNumber);
                    Console.WriteLine();
                    Console.WriteLine("You may log in and start smart budgeting your finances today! Thank you for joining Budgie.");
                }
            }
            RestartApplication();
        }