public void EmpruntSucces() { Pret pret = adherent.Emprunte(exemplaire1); Assert.IsTrue(adherent.Prets.Contains(pret)); Assert.IsFalse(pret.EstTermine()); Assert.IsFalse(exemplaire1.EstDisponible()); }
public void TraiterEmprunt(int idAdherent, int idExemplaire) { using (IUnitOfWork uow = BeginTransaction()) { Adherent adherent = depotAdherents.Read(idAdherent); if (adherent == null) { throw new Exception("L'adhérent est inconnu."); } if (adherent.EstQuotaDepasse()) { throw new Exception("L'adhérent ne peut pas emprunter plus d'exemplaires."); } Exemplaire exemplaire = depotExemplaires.Read(idExemplaire); if (exemplaire == null) { throw new Exception("L'exemplaire est inconnu."); } if (!exemplaire.EstDisponible()) { throw new Exception("L'exemplaire est en cours de prêt."); } adherent.Emprunte(exemplaire); depotAdherents.Update(adherent); depotExemplaires.Update(exemplaire); uow.Commit(); } }
public void Supprimer(int idExemplaire) { using (IUnitOfWork uow = BeginTransaction()) { Exemplaire ex = depotExemplaires.Read(idExemplaire); if (ex == null) { throw new Exception("Ne peut pas supprimer un exemplaire inexistant."); } if (ex.Ouvrage == null) { throw new Exception("Ne peut pas supprimer d'exemplaire sans ouvrage"); } if (!ex.EstDisponible()) { throw new Exception("Ne peut pas supprimer un exemplaire en cours de pret."); } Ouvrage ouvrage = depotOuvrages.Read(ex.Ouvrage.Id); if (ouvrage == null) { throw new Exception("Ne peut pas supprimer un exemplaire dont l'ouvrage est inexistant."); } ouvrage.Remove(ex); depotExemplaires.Delete(ex); uow.Commit(); } }
public void TraiterRetour(int idExemplaire) { using (IUnitOfWork uow = BeginTransaction()) { Exemplaire exemplaire = depotExemplaires.Read(idExemplaire); if (exemplaire == null) { throw new Exception("Cet exemplaire est inconnu."); } if (exemplaire.EstDisponible()) { throw new Exception("Cet exemplaire n'est pas emprunté."); } Adherent adherent = exemplaire.LouePar(); adherent.Retourne(exemplaire); depotAdherents.Update(adherent); depotExemplaires.Update(exemplaire); uow.Commit(); } }