Exemple #1
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();
        }
        public void UpdateUser(BudgieUser budgieuser)
        {
            int idUpdate = 0;

            foreach (BudgieUser bu in bulist)
            {
                if (bu.emailAddress == budgieuser.emailAddress)
                {
                    idUpdate = bu.id;
                }
            }

            budgieUserDB.updateBudgieUser(idUpdate, budgieuser.firstName, budgieuser.lastName, budgieuser.dob);
            accountLogic.updateNewAccount(idUpdate, budgieuser.lastName, budgieuser.dob);
        }
Exemple #3
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);
        }