示例#1
0
 /// <summary>
 /// Deletes Extra-Model connesction from the databse.
 /// </summary>
 /// <param name="connection">Connection that needs to be deleted.</param>
 public void DeleteConnectionRepo(model_extra_connection connection)
 {
     try
     {
         this.DataBase.model_extra_connection.Remove(connection);
         this.DataBase.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         Console.WriteLine(e.InnerException.InnerException.Message);
         Console.ReadLine();
     }
 }
示例#2
0
        /// <summary>
        /// Checks if the Extra-Model connection that needs to be deleted is proper.
        /// </summary>
        /// <param name="selection">Id of the connection that needs to be deleted.</param>
        public void DeleteConnection(string selection)
        {
            IEnumerable <model_extra_connection> connections = this.repository.ListExtraConnectionRepo();

            IEnumerable <int> model_ids = connections
                                          .Select(c => c.id);

            if (this.IsStringNumber(selection) && model_ids.Contains(int.Parse(selection)))
            {
                model_extra_connection toBeDeleted = connections.Where(m => m.id == int.Parse(selection)).First();
                this.repository.DeleteConnectionRepo(toBeDeleted);
            }
            else
            {
                if (!this.IsStringNumber(selection))
                {
                    throw new ArgumentException("Invalid id. You have to select number");
                }
                else
                {
                    throw new ArgumentException("Model cannot be found. Please select another one");
                }
            }
        }
示例#3
0
        public void Setup()
        {
            this.mockedRepository = new Mock <ICarRepository>();

            car_brands brand1 = new car_brands()
            {
                id = 1, name = "Ferari", url = "valami", country = "hungary"
            };
            car_brands brand2 = new car_brands()
            {
                id = 2, name = "Lambo", url = "semmi", country = "italy"
            };
            car_brands brand3 = new car_brands()
            {
                id = 3, name = "Peugeot", url = "halad", country = "france"
            };

            this.mockedRepository
            .Setup(m => m.ListBrandsRepo())
            .Returns(new[] { brand1, brand2, brand3 });

            car_models model1 = new car_models()
            {
                id = 1, brand_id = 2, name = "MurceLago", horsepower = 300
            };
            car_models model2 = new car_models()
            {
                id = 2, brand_id = 1, name = "Testarosa", horsepower = 120
            };
            car_models model3 = new car_models()
            {
                id = 3, brand_id = 3, name = "406", horsepower = 60
            };

            this.mockedRepository
            .Setup(m => m.ListModelsRepo())
            .Returns(new[] { model1, model2, model3 });

            extra extra1 = new extra()
            {
                id = 1, name = "turbo", category_name = "Engine", price = 20
            };
            extra extra2 = new extra()
            {
                id = 2, name = "air conditioning", category_name = "Interior", price = 20
            };
            extra extra3 = new extra()
            {
                id = 3, name = "dark windows", category_name = "Exterior", price = 20
            };

            this.mockedRepository
            .Setup(m => m.ListExtraRepo())
            .Returns(new[] { extra1, extra2, extra3 });

            model_extra_connection connection1 = new model_extra_connection()
            {
                id = 1, extra_id = 1, model_id = 1
            };
            model_extra_connection connection2 = new model_extra_connection()
            {
                id = 2, extra_id = 1, model_id = 3
            };
            model_extra_connection connection3 = new model_extra_connection()
            {
                id = 3, extra_id = 2, model_id = 4
            };

            this.mockedRepository
            .Setup(m => m.ListExtraConnectionRepo())
            .Returns(new[] { connection1, connection2, connection3 });
        }