public bool DeleteSalles(int id)
 {
     try
     {
         if (db.salles.Find(id) != null)
         {
             salle salle = db.salles.Find(id);
             if (!ValidatorSalle.IsSalleActive(salle) && !ValidatorSalle.IsSalleContainSeance(salle))
             {
                 db.salles.Remove(salle);
                 db.SaveChanges();
                 return(true);
             }
             else if (ValidatorSalle.IsSalleActive(salle))
             {
                 throw new SalleActiveException();
             }
             else
             {
                 throw new SalleHaveSeanceException();
             }
         }
         else
         {
             throw new InvalidItemException("salle");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #2
0
        public void IsSalleActive_FalsParam()
        {
            //Arrange
            ManagerSalle manager       = new ManagerSalle(_context);
            salle        InactiveSalle = manager.GetSalle(6, null, null);

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleActive(InactiveSalle);
                //Assert
                Assert.IsFalse(testResult, "La Salle n'est pas Active mais la fonction dit que OUI");
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }
Beispiel #3
0
        public void IsSalleActive_WithNullParam()
        {
            //Arrange
            ManagerSalle manager   = new ManagerSalle(_context);
            salle        NullSalle = null;

            //Act
            try
            {
                var testResult = ValidatorSalle.IsSalleActive(NullSalle);
                //Assert
                Assert.Fail("A exception should have been throw");
            }
            catch (NullIdExecption NIE)
            {
                Assert.AreEqual("aucune Salle avec cette ID existe", NIE.Message);
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type {e.GetType()} occure with a message : {e.Message}");
            }
        }