Пример #1
0
 public bool DeleteCinema(int id)
 {
     try
     {
         if (db.cinemas.Find(id) != null)
         {
             cinema cinema = db.cinemas.Find(id);
             if (!ValidatorCinema.IsCinemaContainSalle(cinema))
             {
                 cinema = db.cinemas.Find(id);
                 db.cinemas.Remove(cinema);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 throw new CinemaHasSalleException();
             }
         }
         else
         {
             throw new InvalidItemException("cinema");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
        public void CinemaContainSalle_CinemaWithSalle()
        {
            //Arrange
            ManagerCinema manager = new ManagerCinema(_context);

            //Act
            var testResult1 = ValidatorCinema.IsCinemaContainSalle(manager.GetCinema(2));

            //Assert
            Assert.IsTrue(testResult1, "un cinema contient des salle n'as pas renvoyer true");
        }
        public void CinemaContainSalle_emptyCinema()
        {
            //Arrange
            ManagerCinema manager = new ManagerCinema(_context);

            //Act
            var testResult1 = ValidatorCinema.IsCinemaContainSalle(manager.GetCinema(3));

            //Assert
            Assert.IsFalse(testResult1, "un cinema vide n'as pas renvoyer false");
        }
Пример #4
0
 public bool PostCinema(cinema cinema)
 {
     try
     {
         if (!ValidatorCinema.IsCinemaExist(cinema, GetAllCinema()))
         {
             db.cinemas.Add(cinema);
             db.SaveChanges();
             return(true);
         }
         else
         {
             throw new ExistingItemException("cinema");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #5
0
 public bool PutCinema(cinema cinema)
 {
     try
     {
         if (ValidatorCinema.IsCinemaExist(cinema, GetAllCinema()))
         {
             //db.Entry(cinema).State = EntityState.Modified;
             db.Set <cinema>().AddOrUpdate(cinema);
             db.SaveChanges();
             return(true);
         }
         else
         {
             throw new ItemNotExistException("cinema");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void CinemaContainSalle_CinemaNull()
        {
            //Arrange
            ManagerCinema manager    = new ManagerCinema(_context);
            cinema        Nullcinema = null;

            //Act
            try
            {
                ValidatorCinema.IsCinemaContainSalle(Nullcinema);
                Assert.Fail("an exception should have been thown");
            }
            catch (NullParametreException NPE)
            {
                Assert.AreEqual("this exception was raised because candidate in IsCinemaContainSalle was null", NPE.Message);
            }
            catch (Exception e)
            {
                Assert.Fail($"unexpected error of type{e.GetType()}​​​​ occure with a message : {e.Message}​​​​");
            }
        }