Esempio n. 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);
        }
Esempio n. 2
0
        //private BudgieUserRepository budgieUserRepository;

        public BudgieUserLogic(BudgieUserRepository BudgieUserRepository, AccountRepository AccountRepository, AccountLogic AccountLogic)
        {
            budgieUserDB = BudgieUserRepository;
            accountDB    = AccountRepository;
            accountLogic = AccountLogic;
            bulist       = budgieUserDB.GetAllBudgieUsers();
        }
Esempio n. 3
0
        public void Test_RemoveBudgieUser_CallsRemoveABudgieUserToDatabase_AndSaveChangesOnContext()
        {
            //ARRANGE
            //ARRANGE
            Mock <BudgieUser> bb = new Mock <BudgieUser>();

            bb.Setup(c => c.id).Returns(1);

            var testData = new List <BudgieUser> {
                bb.Object
            }.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 burTest = new BudgieUserRepository(contextMock.Object);

            dbSetMock.Setup(c => c.Find(1)).Returns(bb.Object);

            //ACT
            burTest.removeBudgieUser(1);

            //ASSERT
            dbSetMock.Verify(c => c.Find(1), Times.Once);
            dbSetMock.Verify(c => c.Remove(bb.Object), Times.Once);
            contextMock.Verify(c => c.SaveChanges(), Times.Once);
        }
Esempio n. 4
0
        static void UpdateUser()
        {
            //Update
            string firstNameUpdate, lastNameUpdate, dobUpdate;
            int    id;

            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("--- Updating an existing Budgie User ---"); Console.WriteLine();

            UpdatedList();

            Console.WriteLine();

            Console.WriteLine("Please enter the id of the Budgie User you wish to update: ");
            id = Convert.ToInt32(Console.ReadLine());

            //BudgieUser budgieUserToUpdate = context.budgieUsers.Find(id);
            //Account accountToUpdate = context.accounts.Where(a => a.accountOwnerId == id).First();

            Console.WriteLine();

            Console.WriteLine("Updating first name (e.g. Ben): ");
            firstNameUpdate = (Console.ReadLine());
            //budgieUserToUpdate.firstName = firstNameUpdate;

            Console.WriteLine();

            Console.WriteLine("Updating last name (e.g. Bowes): ");
            lastNameUpdate = (Console.ReadLine());
            //budgieUserToUpdate.lastName = lastNameUpdate;

            Console.WriteLine();

            Console.WriteLine("Updating date of birth (e.g. DDMMYY (040191)): ");
            dobUpdate = (Console.ReadLine());
            //budgieUserToUpdate.dob = dobUpdate;

            bur.updateBudgieUser(id, firstNameUpdate, lastNameUpdate, dobUpdate);
            ar.updateNewAccount(id, lastNameUpdate, dobUpdate);
            //accountToUpdate.accountNumber = (lastNameUpdate + dobUpdate);

            Console.WriteLine("The following updates have been made: " + firstNameUpdate + " " + lastNameUpdate + " " + dobUpdate + " Account Number: " + (lastNameUpdate + dobUpdate));
            Console.WriteLine();

            Console.WriteLine("Press any key to save changes and continue: ");
            Console.ReadLine();
            context.SaveChanges();
            RestartApplication();
        }
Esempio n. 5
0
        static void RemoveUser()
        {
            int id;

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

            Console.WriteLine(); Console.WriteLine("--- Removing an existing Budgie User ---"); Console.WriteLine();

            UpdatedList();

            Console.WriteLine();

            Console.WriteLine("Please enter the id of the Budgie User you wish to Remove: ");
            id = Convert.ToInt32(Console.ReadLine());

            BudgieUser budgieUserToRemove = context.budgieUsers.Find(id);
            Account    accountToRemove    = context.accounts.Where(a => a.accountOwnerId == id).First();

            Console.WriteLine();

            Console.WriteLine("The Budgie User " + budgieUserToRemove.firstName + " " + budgieUserToRemove.lastName + " " + budgieUserToRemove.emailAddress + " has been successfully removed.");
            bur.removeBudgieUser(id);
            //context.budgieUsers.Remove(budgieUserToRemove);

            Console.WriteLine();

            Console.WriteLine("The Bank Account " + accountToRemove.accountNumber + " has also been successfully removed.");

            //ar.removeAccount(id);     NOT REQUIRED, context.budgieUsers.Remove(budgieUserToRemove); will remove Account as well due to the link between FK and PK (accountOwnerId)
            //context.accounts.Remove(accountToRemove);

            Console.WriteLine();

            Console.WriteLine("Press any key to continue: ");
            Console.ReadLine();

            RestartApplication();
        }
Esempio n. 6
0
        public void Test_GetAllBrokers_ReturnsAllBrokers()
        {
            //ARRANGE
            Mock <BudgieUser> bb = new Mock <BudgieUser>();
            Mock <BudgieUser> an = new Mock <BudgieUser>();
            Mock <BudgieUser> sn = new Mock <BudgieUser>();

            var expected = new List <BudgieUser>
            {
                bb.Object,
                an.Object,
                sn.Object
                //new BudgieUser{ id = 1, firstName = "Ben", lastName = "Bowes", emailAddress = "*****@*****.**", dob = "040191", password = "******"},
                //new BudgieUser{ id = 1, firstName = "Andrew", lastName = "Norman", emailAddress = "*****@*****.**", dob = "010494", password = "******"},
            };

            var testData = new List <BudgieUser>
            {
                bb.Object,
                an.Object,
                sn.Object
            }.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
            var actual = classUnderTest.GetAllBudgieUsers();

            //ASSERT
            CollectionAssert.AreEqual(expected, actual);
        }
Esempio n. 7
0
        public void Test_UpdateBudgieUser_RunsUpdateBudgieUserToDatabase_AndSaveChangesOnContext()
        {
            //ARRANGE
            Mock <BudgieUser> bb = new Mock <BudgieUser>();

            bb.Setup(c => c.id).Returns(1);

            var testData = new List <BudgieUser> {
                bb.Object
            }.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 burTest = new BudgieUserRepository(contextMock.Object);

            dbSetMock.Setup(c => c.Find(1)).Returns(bb.Object);

            //ACT
            bb.SetupSet(c => c.firstName = "Ben").Verifiable();
            bb.SetupSet(c => c.lastName  = "Bowes").Verifiable();
            bb.SetupSet(c => c.dob       = "040191").Verifiable();


            burTest.updateBudgieUser(1, "Ben", "Bowes", "040191");

            //ASSERT
            dbSetMock.Verify(c => c.Find(1));
            bb.VerifySet(c => c.firstName = "Ben");
            bb.VerifySet(c => c.lastName  = "Bowes");
            bb.VerifySet(c => c.dob       = "040191");
            contextMock.Verify(c => c.SaveChanges(), Times.Once);
        }
Esempio n. 8
0
 public BudgieUserLogic(BudgieUserRepository budgieUserRepository)
 {
     // TODO: Complete member initialization
     this.budgieUserRepository = budgieUserRepository;
 }
Esempio n. 9
0
 public BudgieUserLogic(BudgieUserRepository userRepo, AccountRepository accountRepo)
 {
     // TODO: Complete member initialization
     this.userRepo    = userRepo;
     this.accountRepo = accountRepo;
 }
Esempio n. 10
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();
        }
Esempio n. 11
0
 public BudgieUserController()
 {
     userRepo    = new BudgieUserRepository(budgieDBCFModel);
     accountRepo = new AccountRepository(budgieDBCFModel);
     buLogic     = new BudgieUserLogic(userRepo, accountRepo);
 }