Ejemplo n.º 1
0
        public void delete_test()
        {
            moqDbContext     = new Mock <DbContextEntities>();
            moqDbSetTranfert = new Mock <DbSet <Transfert> >();
            moqDbSetCompte   = new Mock <DbSet <Compte> >();

            moqDbSetCompte.Setup(m => m.Find(It.IsAny <Object[]>())).Returns((Object[] ids) => comptes.FirstOrDefault(compte => compte.id == (int)ids[0]));
            moqDbSetTranfert.Setup(m => m.Find(It.IsAny <Object[]>())).Returns((Object[] ids) => transferts.FirstOrDefault(transfert => transfert.id == (int)ids[0]));
            moqDbContext.Setup(m => m.SaveChanges()).Returns(3);
            moqDbSetTranfert.Setup(m => m.Remove(It.IsAny <Transfert>())).Returns((Transfert t) => { transferts.Remove(t); return(t); });

            transfertRepository = new TransfertRepository(moqDbContext.Object, moqDbSetTranfert.Object, moqDbSetCompte.Object);

            bool resulat = transfertRepository.Delete(1);

            Assert.IsTrue(resulat);
            Assert.IsTrue(comptes.ElementAt(0).solde == 1100);
            Assert.IsTrue(comptes.ElementAt(1).solde == 1900);
        }
Ejemplo n.º 2
0
 public bool DeleteTransfert(int id)
 {
     return(transfertRepository.Delete(id));
 }