Ejemplo n.º 1
0
        public void GetAccountsByAmountLargerThan()
        {
            FormationContext context = new FormationContext();
            IBankService     service = new BankService(context);
            var accounts             = service.GetAccountsByAmountLargerThan(1000);

            Assert.AreEqual(1, accounts.Count());
        }
Ejemplo n.º 2
0
        public void GetAccountsByCustomerId()
        {
            FormationContext context = new FormationContext();
            IBankService     service = new BankService(context);
            var accounts             = service.GetAccountsByCustomerId(1);

            Assert.AreEqual(1, accounts.Count());
        }
Ejemplo n.º 3
0
        public void TestAccountDTO()
        {
            FormationContext context = new FormationContext();
            IBankService     service = new BankService(context);
            Account          account = service.GetAccountById(12);
            AccountDTO       dto     = account.ToDTO();
            var dtos = service.GetAccountsByCustomerId(1).ToDTOs();

            Assert.AreEqual(250, dtos.First().Solde);
            Assert.AreEqual("Cyril Vincent", dtos.First().Name);
        }
Ejemplo n.º 4
0
        public void TestDTO()
        {
            FormationContext context = new FormationContext();
            IBankService     service = new BankService(context);
            var accounts             = service.GetAccountsByCustomerId(1);

            accounts.Select(a => new AccountDTO
            {
                Id       = a.Id,
                BankName = a.Bank.Name
            });
        }
Ejemplo n.º 5
0
        public void LazyEf()
        {
            FormationContext context  = new FormationContext();
            Bank             bank     = context.Banks.First();
            Customer         customer = context.Customers.First();
            Account          account  = new Account {
                Bank = bank, Owner = customer
            };

            bank.Accounts.Add(account);
            context.SaveChanges();
        }
Ejemplo n.º 6
0
        public void TestEFSimple()
        {
            FormationContext context = new FormationContext();
            Bank             bank    = new Bank {
                Name = "CyrilBank"
            };

            context.Banks.Add(bank);
            context.SaveChanges();
            Bank bank2 = context.Banks.First();

            Assert.AreEqual(bank.Name, "CyrilBank");
        }
Ejemplo n.º 7
0
        public void ServiceWithEF()
        {
            FormationContext context = new FormationContext();
            IBankService     service = new BankService(context);
            Account          account = service.GetAccountById(12);

            Assert.IsNotNull(account);
            service.Deposit(account, 100);
            Transaction t = account.Transactions.Last();

            Assert.AreEqual(100, t.Amount);
            service.Save();
        }
Ejemplo n.º 8
0
        public void TransactionsEF()
        {
            FormationContext context = new FormationContext();
            Bank             b       = context.Banks.First();
            Account          account = b.Accounts.First();

            account.Transactions.Add(new Transaction {
                Amount = 100
            });
            account.Transactions.Add(new Transaction {
                Amount = -50
            });
            account.Balance = 50;
            context.SaveChanges();
        }
Ejemplo n.º 9
0
        public void CreateUpdateDeleteEF()
        {
            FormationContext context  = new FormationContext();
            Bank             bank     = context.Banks.First();
            Customer         customer = context.Customers.First();
            Account          account  = new Account {
                Bank = bank, Owner = customer
            };

            context.Accounts.Add(account);
            context.SaveChanges();
            account          = context.Accounts.First();
            account.Balance += 100;
            context.SaveChanges();
            context.Accounts.Remove(account);
            context.SaveChanges();
        }
Ejemplo n.º 10
0
        public void TestEFSimple()
        {
            FormationContext context = new FormationContext();

            context.Books.Add(new Book {
                Title = "C#", Price = 10
            });
            context.Books.Add(new Book {
                Title = "EF", Price = 12
            });

            context.SaveChanges();
            var res = context.Books.Where(b => b.Price < 11).First();

            Assert.AreEqual("C#", res.Title);
            res.Price += 1;
            context.SaveChanges();
        }
Ejemplo n.º 11
0
        public void ManyToManyEF()
        {
            FormationContext context = new FormationContext();
            Bank             b       = context.Banks.First();
            Customer         c1      = new Customer {
                FirstName = "Cyril", LastName = "Vincent"
            };

            b.Customers.Add(c1);
            Customer c2 = new Customer {
                FirstName = "Toto", LastName = "Titi"
            };

            b.Customers.Add(c2);
            Bank b2 = new Bank {
                Name = "NewBank"
            };

            context.Banks.Add(b2);
            context.SaveChanges();
            c2.Banks.Add(b2);
            context.SaveChanges();
        }
Ejemplo n.º 12
0
        public void LazyEf2()
        {
            FormationContext context = new FormationContext();
            Bank             bank    = context.Banks.First();

            // Pas de jointure
            foreach (Bank b in context.Banks)
            {
                // b.Id
            }
            // Lazy Loading
            Assert.AreEqual(0, bank.Accounts.First().Balance);
            // Include Eagger Loading
            var banks = context.Banks.Include(e => e.Accounts);
            // Lazy Join
            var res = context.Banks.Where(b => b.Accounts.Count == 0).Include(e => e.Accounts);

            foreach (Bank b in res)
            {
            }

            // Bank 1-* Account 1-* Transaction
            // Tester avec 2 Accounts et 2-3 Transactions
        }
Ejemplo n.º 13
0
        private readonly IDbSet <T> dbset; // générique

        public RepositoryBase(FormationContext dataContext)
        {
            this.dataContext = dataContext;
            dbset            = dataContext.Set <T>();// set ; remplit la variable dbset avec T
        }
Ejemplo n.º 14
0
 public BankService(FormationContext context)
 {
     Context = context;
 }
Ejemplo n.º 15
0
 public DataBaseFactory()
 {
     datacontext = new FormationContext();
 }