Exemple #1
0
        public void B3_CarteMemVider()
        {
            m_maxScore += 4;

            ICarteMemoire target       = CréerUneCarteMemoireTest();
            IPhoto        objPhotoTest = CréerUnePhotoTest();

            // on va ajouter quelques photos
            int nbPhotos = m_objRandom.Next(5, 10);

            for (int index = 0; index < nbPhotos; index++)
            {
                target.Ajouter(CréerUnePhotoTest());
            }
            Assert.AreEqual(nbPhotos, target.NbPhotos);
            m_totalScore++;

            // On va tester la méthode permettant de vider la carte
            target.Vider();

            Assert.AreEqual(0, target.NbPhotos);
            m_totalScore++;

            Assert.AreEqual(0, target.EspaceUtilise);
            m_totalScore++;

            Assert.AreEqual(target.EspaceDisponible, target.TailleEnOctets);
            m_totalScore++;
        }
Exemple #2
0
        public void C5_CameraPhotoCourante()
        {
            m_maxScore += 7;

            ICamera       target      = new Camera();
            ICarteMemoire objCarteMem = CréerUneCarteMemoireTest();

            Assert.IsNull(target.PhotoCourante); // H14 24-12

            for (int index = 0; index < m_objRandom.Next(10, 20); index++)
            {
                objCarteMem.Ajouter(CréerUnePhotoTest());
            }

            target.InsererCarteMemoire(objCarteMem);
            Assert.AreEqual(0, target.PosPhotoCourante);
            Assert.AreEqual(objCarteMem.PhotoAt(0), target.PhotoCourante); // H19
            m_totalScore++;

            target.PhotoSuivante();
            Assert.AreEqual(1, target.PosPhotoCourante);
            Assert.AreEqual(objCarteMem.PhotoAt(1), target.PhotoCourante); // H14 24-12

            target.PhotoPrecedente();
            Assert.AreEqual(0, target.PosPhotoCourante);
            Assert.AreEqual(objCarteMem.PhotoAt(0), target.PhotoCourante); // H14 24-12

            target.PhotoPrecedente();
            Assert.AreEqual(objCarteMem.NbPhotos - 1, target.PosPhotoCourante);
            Assert.AreEqual(objCarteMem.PhotoAt(objCarteMem.NbPhotos - 1), target.PhotoCourante); // H14 24-12

            target.PhotoSuivante();
            Assert.AreEqual(0, target.PosPhotoCourante);
            m_totalScore++;

            // à ce stade la carte mémoire est vide
            target.ViderLaCarte();
            ExécuterPhotoSuivanteEtPrecedente(target, Camera.ERR_MSG_CARTE_VIDE);

            //à ce stade il n'y pas de carte dans la caméra
            target.EjecterCarteMemoire();
            try
            {
                target.ViderLaCarte();
                Assert.Fail("InvalidOperationException attendue");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(Camera.ERR_MSG_CARTE_MANQUANTE, e.Message);
                m_totalScore++;
            }
            catch (Exception)
            {
                Assert.Fail("InvalidOperationException attendue");
            }
            ExécuterPhotoSuivanteEtPrecedente(target, Camera.ERR_MSG_CARTE_MANQUANTE);
        }
Exemple #3
0
        public void B4_CarteMemPhotoAt()
        {
            m_maxScore += 3;

            ICarteMemoire target = CréerUneCarteMemoireTest();

            for (int index = 0; index < m_objRandom.Next(10, 20); index++)
            {
                Photo objPhoto = CréerUnePhotoTest();
                target.Ajouter(objPhoto);
                Assert.AreEqual(objPhoto, target.PhotoAt(index));
            }
            m_totalScore++;

            try
            {
                target.PhotoAt(-1);
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
            catch (ArgumentOutOfRangeException)
            {
                m_totalScore++;
            }
            catch (Exception)
            {
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }

            try
            {
                target.PhotoAt(target.NbPhotos);
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
            catch (ArgumentOutOfRangeException)
            {
                m_totalScore++;
            }
            catch (Exception)
            {
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
        }
Exemple #4
0
        public void B5_CarteMemSupprimer()
        {
            m_maxScore += 5;

            ICarteMemoire target        = CréerUneCarteMemoireTest();
            IPhoto        objPhotoTest1 = CréerUnePhotoTest();
            IPhoto        objPhotoTest2 = CréerUnePhotoTest();

            // On va ajouter deux photos sur la carte mémoire avant d'essayer de supprimer
            target.Ajouter(objPhotoTest1);
            target.Ajouter(objPhotoTest2);

            long espaceUtiliséAvantSupp = target.EspaceUtilise;
            long espaceDispoAvantSupp   = target.EspaceDisponible;

            // On va supprimer la deuxième photo
            target.SupprimerAt(1);

            Assert.AreEqual(1, target.NbPhotos);
            m_totalScore++;

            Assert.AreEqual(espaceUtiliséAvantSupp - objPhotoTest2.TailleEnOctets, target.EspaceUtilise);
            Assert.AreEqual(espaceDispoAvantSupp + objPhotoTest2.TailleEnOctets, target.EspaceDisponible);
            m_totalScore++;

            // On va ajouter quelques photos sur la carte et les supprimer
            target.Vider();
            int nbPhotos = m_objRandom.Next(5, 10);

            for (int index = 0; index < m_objRandom.Next(5, 10); index++)
            {
                target.Ajouter(CréerUnePhotoTest());
            }

            for (int index = 0; index < target.NbPhotos; index++)
            {
                espaceUtiliséAvantSupp = target.EspaceUtilise;
                espaceDispoAvantSupp   = target.EspaceDisponible;
                int    randomIndex        = m_objRandom.Next(0, target.NbPhotos);
                IPhoto objPhotoASupprimer = target.PhotoAt(randomIndex);
                target.SupprimerAt(randomIndex);
                Assert.AreEqual(espaceUtiliséAvantSupp - objPhotoASupprimer.TailleEnOctets, target.EspaceUtilise);
                Assert.AreEqual(espaceDispoAvantSupp + objPhotoASupprimer.TailleEnOctets, target.EspaceDisponible);
            }
            m_totalScore++;

            // on va supprimer une photo avec des arguments non valides
            try
            {
                target.SupprimerAt(-1);
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
            catch (ArgumentOutOfRangeException)
            {
                m_totalScore++;
            }
            catch (Exception)
            {
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }

            try
            {
                target.SupprimerAt(target.NbPhotos);
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
            catch (ArgumentOutOfRangeException)
            {
                m_totalScore++;
            }
            catch (Exception)
            {
                Assert.Fail("ArgumentOutOfRangeException attendue");
            }
        }