public void Test_RepositoryReadOnlyExtendedTSQL()
        {
            //Insert
            TestInsert10Cars();

            //Select a Randon index between 0 and 9 and get name selected
            int    ind     = new Random().Next(0, 9);
            string carname = carnames[ind];

            //Create Repository ReadOnly
            Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();

            fieldIdName.Add("id", typeof(int));
            IRepositoryReadOnlyExtendedTSQL <Car> RoRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);

            try
            {
                //Count
                Assert.AreEqual(10, RoRepository.Count($"SELECT * FROM {tablename}"));

                //Exists
                Assert.AreEqual(true, RoRepository.Exists($"SELECT * FROM {tablename} WHERE name = '{carname}'"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //Delete
                TestClearCars();
            }
        }
        public void Test_RepositoryReadOnlyPagination()
        {
            //Insert
            TestInsert10Cars();

            //Select a Randon index between 0 and 9 and get name selected
            int    ind     = new Random().Next(0, 9);
            string carname = carnames[ind];

            //Create Repository ReadOnly
            Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();

            fieldIdName.Add("id", typeof(int));
            IRepositoryReadOnlyPagination <Car> RoRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);

            try
            {
                //Pagination
                var CarsPag2 = RoRepository.FindAll(2, 5, "name", false, f => f.name != carname);
                Assert.IsNotNull(CarsPag2);
                Assert.AreEqual(9, CarsPag2.TotalRegisters);
                Assert.AreEqual(true, CarsPag2.Collection.Count <= 5);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //Delete
                TestClearCars();
            }
        }
        public void Test_RepositoryReadOnly()
        {
            //Insert
            TestInsert10Cars();

            //Select a Randon index between 0 and 9 and get name selected
            int    ind     = new Random().Next(0, 9);
            string carname = carnames[ind];

            //Create Repository ReadOnly
            Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();

            fieldIdName.Add("id", typeof(int));
            IRepositoryReadOnly <Car> RoRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);

            //Test Find method
            var Car_ind = RoRepository.Find(f => f.name == carname);

            Assert.IsNotNull(Car_ind);
            Assert.AreEqual(true, Car_ind.id == ind + 1 && Car_ind.name == carname);

            //Test FindAll
            var Cars = RoRepository.FindAll();

            Assert.IsNotNull(Cars);
            Assert.AreEqual(10, Cars.Count);

            //Delete
            TestClearCars();
        }
        public void testInit()
        {
            //SqlConnection connection = new SqlConnection(connectionString);
            //var context = new ConnectionContext(connection, true
            ContextCreator.Intialize();
            var context = ContextCreator.GetContext();


            myUow = new UnitOfWorkDapper <ConnectionContext>(context);
            Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();

            fieldIdName.Add("id", typeof(int));
            this.MyCarsRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);
        }
        public void Test_RepositoryReadOnlyTSQL()
        {
            //Insert
            TestInsert10Cars();
            try
            {
                //Select a Randon index between 0 and 9 and get name selected
                int    ind     = new Random().Next(0, 9);
                string carname = carnames[ind];

                //Create Repository ReadOnly
                Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();
                fieldIdName.Add("id", typeof(int));
                IRepositoryReadOnlyTSQL <Car> RoRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);


                //Test Find method
                var sql = $"Select * from {tablename} where name = @name";
                IDictionary <string, object> paramz = new ExpandoObject();
                paramz.Add("@name", carnames[ind]);

                var Car_ind = RoRepository.Find(sql, paramz);
                Assert.IsNotNull(Car_ind);
                Assert.AreEqual(true, Car_ind.id == ind + 1 && Car_ind.name == carname);

                //Test FindAll
                sql = $"Select * from {tablename}";
                var Cars = RoRepository.FindAll(sql, null);
                Assert.IsNotNull(Cars);
                Assert.AreEqual(10, Cars.Count);

                //Test FindAll Pagination
                var CarPag1 = RoRepository.FindAll(1, 5, "name", sql, false);
                Assert.IsNotNull(CarPag1);
                Assert.AreEqual(10, CarPag1.TotalRegisters);
                Assert.AreEqual(5, CarPag1.Collection.Count);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //Delete
                TestClearCars();
            }
        }
        public void Test_RepositoryReadOnlyExtended()
        {
            //Insert
            TestInsert10Cars();

            //Select a Randon index between 0 and 9 and get name selected
            int    ind     = new Random().Next(0, 9);
            string carname = carnames[ind];

            //Create Repository ReadOnly
            Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>();

            fieldIdName.Add("id", typeof(int));
            IRepositoryReadOnlyExtended <Car> RoRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName);

            try
            {
                //Reload
                Car Car_ind = new Car {
                    id = ind + 1
                };
                RoRepository.Reload(ref Car_ind);

                Assert.AreEqual(carname, Car_ind.name);

                //Count
                Assert.AreEqual(10, RoRepository.Count());

                //Exists
                Assert.AreEqual(true, RoRepository.Exists(f => f.name == carname));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //Delete
                TestClearCars();
            }
        }
 public void TestCleanUp()
 {
     myUow.Dispose();
     this.MyCarsRepository = null;
 }
Exemple #8
0
 public static void Purge(T entity)
 {
     InternalRepository.Delete(entity);
 }
Exemple #9
0
 public static T GetGlobal(int id)
 {
     return(InternalRepository.Get((int)id));
 }