Esempio n. 1
0
        public void JedisDeleteMethod()
        {
            using (ServiceJediTournamentEntities.ServiceJediTournamentClient client = new ServiceJediTournamentEntities.ServiceJediTournamentClient()) {
                List <JediWCF> testList = client.getJedis();

                Assert.AreNotEqual(0, testList.Count);

                int oldCount = testList.Count;

                List <int> toRemoveList = new List <int>();

                // Insert 5 jedis
                for (int i = 1; i <= 5; i++)
                {
                    JediWCF j = new JediWCF();
                    j.Id               = testList[oldCount - 1].Id + i;
                    j.Nom              = "test" + i;
                    j.IsSith           = true;
                    j.Caracteristiques = new List <CaracteristiqueWCF>();

                    testList.Add(j);
                    toRemoveList.Add(j.Id);
                }

                client.updateJedis(testList);
                testList = client.getJedis();


                client.removeJedis(toRemoveList);
                testList = client.getJedis();
                Assert.AreEqual(testList.Count, oldCount);
            }
        }
Esempio n. 2
0
        public void JedisUpdateMethod()
        {
            ServiceJediTournamentEntities.ServiceJediTournamentClient client = new ServiceJediTournamentEntities.ServiceJediTournamentClient();
            List<JediWCF> testList = client.getJedis();

            Assert.AreNotEqual(0, testList.Count);

            int count = testList.Count;

            JediWCF j = new JediWCF();
            j.Nom = "test";
            j.IsSith = true;
            j.Caracteristiques = new List<CaracteristiqueWCF>();

            testList.Add(j);

            client.updateJedis(testList);

            testList = null;
            testList = client.getJedis();

            Assert.AreEqual(count + 1, testList.Count);

            client.Close();
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                ServiceJediClient         service = new ServiceJediClient();
                List <CaracteristiqueWCF> listCar = service.getAllCaracteristique().ToList();

                JediWCF jediWCF = new JediWCF();
                jediWCF.Nom    = collection[1];
                jediWCF.IsSith = collection[2].StartsWith("true");

                List <CaracteristiqueWCF> listCarRes = new List <CaracteristiqueWCF>();
                char[]   delimiterChars = { ',' };
                string[] caractStr      = collection[3].Split(delimiterChars);
                foreach (string str in caractStr)
                {
                    if (str != "false")
                    {
                        listCarRes.Add(listCar.Find(x => x.Id == Int32.Parse(str)));
                    }
                }

                jediWCF.Caracteristiques = listCarRes.ToArray();

                service.addJedi(jediWCF);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 4
0
        public void JedisDeleteMethod()
        {
            using(ServiceJediTournamentEntities.ServiceJediTournamentClient client = new ServiceJediTournamentEntities.ServiceJediTournamentClient()) {
                List<JediWCF> testList = client.getJedis();

                Assert.AreNotEqual(0, testList.Count);

                int oldCount = testList.Count;

                List<int> toRemoveList = new List<int>();

                // Insert 5 jedis
                for (int i = 1; i <= 5; i++) {
                    JediWCF j = new JediWCF();
                    j.Id = testList[oldCount - 1].Id + i;
                    j.Nom = "test" + i;
                    j.IsSith = true;
                    j.Caracteristiques = new List<CaracteristiqueWCF>();

                    testList.Add(j);
                    toRemoveList.Add(j.Id);
                }

                client.updateJedis(testList);
                testList = client.getJedis();

                client.removeJedis(toRemoveList);
                testList = client.getJedis();
                Assert.AreEqual(testList.Count, oldCount);
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                ServiceJediClient service = new ServiceJediClient();
                List<CaracteristiqueWCF> listCar = service.getAllCaracteristique().ToList();

                JediWCF jediWCF = new JediWCF();
                jediWCF.Nom = collection[1];
                jediWCF.IsSith = collection[2].StartsWith("true");

                List<CaracteristiqueWCF> listCarRes = new List<CaracteristiqueWCF>();
                char[] delimiterChars = {','};
                string[] caractStr = collection[3].Split(delimiterChars);
                foreach (string str in caractStr)
                {
                    if (str != "false")
                    {
                        listCarRes.Add(listCar.Find(x => x.Id == Int32.Parse(str)));
                    }
                }

                jediWCF.Caracteristiques = listCarRes.ToArray();

                service.addJedi(jediWCF);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 6
0
        public void JedisUpdateMethod()
        {
            ServiceJediTournamentEntities.ServiceJediTournamentClient client = new ServiceJediTournamentEntities.ServiceJediTournamentClient();
            List <JediWCF> testList = client.getJedis();

            Assert.AreNotEqual(0, testList.Count);

            int count = testList.Count;

            JediWCF j = new JediWCF();

            j.Nom              = "test";
            j.IsSith           = true;
            j.Caracteristiques = new List <CaracteristiqueWCF>();


            testList.Add(j);

            client.updateJedis(testList);

            testList = null;
            testList = client.getJedis();

            Assert.AreEqual(count + 1, testList.Count);

            client.Close();
        }
Esempio n. 7
0
        public void updateJedi(JediWCF jedi)
        {
            List <Jedi> jedis           = bm.getJedis();
            int         index_to_modify = jedis.FindIndex(x => x.Id == jedi.Id);

            jedis[index_to_modify] = jedi.toJedi();
            bm.updateJedi(jedis);
        }
Esempio n. 8
0
        public void deleteJedi(JediWCF jedi)
        {
            List <Jedi> jedis           = bm.getJedis();
            int         index_to_modify = jedis.FindIndex(x => x.Id == jedi.Id);

            jedis.RemoveAt(index_to_modify);
            bm.updateJedi(jedis);
        }
        //
        // GET: /Jedi/Edit/5
        public ActionResult Edit(int id)
        {
            ServiceJediClient service = new ServiceJediClient();
            JediWCF           jedi    = service.getAllJedi().ToList().Find(x => x.Id == id);

            if (jedi == null)
            {
                return(HttpNotFound());
            }
            return(View(new JediModels(jedi)));
        }
Esempio n. 10
0
        public void addJedi(JediWCF jedi)
        {
            List <Jedi>            jedis      = bm.getJedis();
            List <Caracteristique> listCaract = new List <Caracteristique>();

            foreach (CaracteristiqueWCF car in jedi.Caracteristiques)
            {
                listCaract.Add(car.toCaracteristique());
            }
            jedis.Add(new Jedi(jedi.Nom, jedi.IsSith, listCaract));
            bm.updateJedi(jedis);
        }
        public JediModels(JediWCF jedi)
        {
            Id = jedi.Id;
            Nom = jedi.Nom;
            IsSith = jedi.IsSith;

            List<CaracteristiqueModels> list = new List<CaracteristiqueModels>();
            foreach (CaracteristiqueWCF c in jedi.Caracteristiques)
            {
                list.Add(new CaracteristiqueModels(c));
            }
            Caracts = new CaracteristiqueCollection(list);
        }
Esempio n. 12
0
 public JediModels(JediWCF jedi)
 {
     Id = jedi.Id;
     Nom = jedi.Nom;
     IsSith = jedi.IsSith;
 
     List<CaracteristiqueModels> list = new List<CaracteristiqueModels>();
     foreach (CaracteristiqueWCF c in jedi.Caracteristiques)
     {
         list.Add(new CaracteristiqueModels(c));
     }
     Caracts = new CaracteristiqueCollection(list);
 }
Esempio n. 13
0
        /// <summary>
        /// Constructor from a JediWCF 
        /// </summary>
        /// <param name="j">JediWCF provided by the web service</param>
        public JediWebModel(JediWCF j)
        {
            Id = j.Id;
            Nom = j.Nom;
            IsSith = j.IsSith;

            // Adaptation caractéristiques
            Caracteristiques = new List<CaracWebModel>();

            if (j.Caracteristiques != null) {
                foreach (CaracteristiqueWCF c in j.Caracteristiques) {
                    Caracteristiques.Add(new CaracWebModel(c));
                }
            }
        }
Esempio n. 14
0
        public JediWCF convert()
        {
            JediWCF j = new JediWCF();
            j.Id = this.Id;
            j.Nom = this.Nom;
            j.IsSith = this.IsSith;

            j.Caracteristiques = new List<CaracteristiqueWCF>();

            foreach(CaracWebModel c in this.Caracteristiques) {
                j.Caracteristiques.Add(c.convert(c.Id));
            }

            return j;
        }
Esempio n. 15
0
        public JediWCF convert()
        {
            JediWCF j = new JediWCF();

            j.Id     = this.Id;
            j.Nom    = this.Nom;
            j.IsSith = this.IsSith;

            j.Caracteristiques = new List <CaracteristiqueWCF>();

            foreach (CaracWebModel c in this.Caracteristiques)
            {
                j.Caracteristiques.Add(c.convert(c.Id));
            }

            return(j);
        }
Esempio n. 16
0
        /// <summary>
        /// Constructor from a JediWCF
        /// </summary>
        /// <param name="j">JediWCF provided by the web service</param>
        public JediWebModel(JediWCF j)
        {
            Id     = j.Id;
            Nom    = j.Nom;
            IsSith = j.IsSith;

            // Adaptation caractéristiques
            Caracteristiques = new List <CaracWebModel>();

            if (j.Caracteristiques != null)
            {
                foreach (CaracteristiqueWCF c in j.Caracteristiques)
                {
                    Caracteristiques.Add(new CaracWebModel(c));
                }
            }
        }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         ServiceJediClient service = new ServiceJediClient();
         JediWCF           jedi    = service.getAllJedi().ToList().Find(x => x.Id == id);
         if (jedi == null)
         {
             return(HttpNotFound());
         }
         service.deleteJedi(jedi);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 18
0
        /// <summary>
        /// Ajoute un nouveau jedi
        /// </summary>
        /// <param name="j">Jedi à ajouter</param>
        /// <returns>Vrai si l'ajout s'est fait, sinon faux</returns>
        bool IServiceJediTournament.newJedi(JediWCF item)
        {
            bool flag = true;

            JediTournamentManager manager = new JediTournamentManager();
            List <Jedi>           values  = manager.getJedis();

            item.Id = values.Max(j => j.Id) + 1;
            values.Add(item.convert());

            try {
                manager.updateJedis(values);
            }
            catch {
                flag = false;
            }

            return(flag);
        }
Esempio n. 19
0
        public void JediWCFTest()
        {
            //get
            ServiceJediReference.ServiceJediClient service = new ServiceJediReference.ServiceJediClient();
            BusinessLayer.BusinessManager          bm      = new BusinessLayer.BusinessManager();
            List <JediWCF> result   = service.getAllJedi();
            List <Jedi>    original = bm.getJedis(); //met a jour l'id
            List <JediWCF> expected = new List <JediWCF>();

            foreach (Jedi jedi in original)
            {
                expected.Add(new JediWCF(jedi));
            }
            foreach (JediWCF jedi in expected)
            {
                Assert.IsTrue(result.Exists(x => x.Nom == jedi.Nom), "Le jedi " + jedi.Nom + " n'est pas present");
            }

            //add
            List <Caracteristique> list_carac = bm.getCaracteristique().FindAll(x => x.Id == 1);
            JediWCF j = new JediWCF(new Jedi("TestAjout", false, list_carac));

            service.addJedi(j);
            result = service.getAllJedi();
            Assert.IsTrue(result.Exists(x => x.Nom == j.Nom), "Le jedi " + j.Nom + " n'est pas present");

            //update
            j        = result.Find(x => x.Nom == "TestAjout");
            j.IsSith = true;
            service.updateJedi(j);
            result = service.getAllJedi();
            Assert.IsTrue(result.Exists(x => x.Nom == j.Nom && x.IsSith == true), "Le jedi " + j.Nom + " n'a pas ete modife");

            //delete
            service.deleteJedi(j);
            result = service.getAllJedi();
            Assert.IsTrue(!result.Exists(x => x.Nom == j.Nom), "Le jedi " + j.Nom + "existe toujours");
        }