Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void RemoveUser(BudgieUser budgieuser)
        {
            int id = 0;

            foreach (BudgieUser bu in bulist)
            {
                if (bu.emailAddress == budgieuser.emailAddress)
                {
                    id = bu.id;
                }
            }
            budgieUserDB.removeBudgieUser(id);
        }
Exemplo n.º 3
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();
        }