Exemplo n.º 1
0
        public void Test_RepositorReadOnly()
        {
            //Insert
            TestInsert10Assember();

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

            //Create Repository
            IRepositoryReadOnly <Assembler> RoRepository = new MyRepository <Assembler, MyContext>(this.uow, "Assemblers", new KeyValuePair <string, Type>("id", typeof(int)));

            //Test Find method
            var asb = RoRepository.Find(f => f.name == assembler);

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

            //Test FindAll
            var asbs = RoRepository.FindAll(f => 1 == 1);

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

            //Delete
            TestClearDb();
        }
Exemplo n.º 2
0
        public void Test_RepositorReadOnlyPagination()
        {
            //Insert
            TestInsert10Assember();

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

            //Create Repository
            IRepositoryReadOnlyPaginationExtended <Assembler> RoRepository = new MyRepository <Assembler, MyContext>(this.uow, "Assemblers", new KeyValuePair <string, Type>("id", typeof(int)));

            //Test FindAll method
            var asb = RoRepository.FindAll(1, 5, f => f.name, false, f => 1 == 1);

            Assert.IsNotNull(asb);
            Assert.AreEqual(10, asb.TotalRegisters);
            Assert.AreEqual(5, asb.Collection.Count);

            //Delete
            TestClearDb();
        }
Exemplo n.º 3
0
        public void RepositoryWrite_Assembler_Success()
        {
            vmuow.UnitOfWorkEFcore <Context> uow = new vmuow.UnitOfWorkEFcore <Context>(new DbContextOptionsBuilder <Context>()
                                                                                        .UseInMemoryDatabase("Teste"));

            ITest <Assembler> RepAssembler = new MyRepository <Assembler, Context>(uow);

            using (var ctx = uow.dbContext)
            {
                RepAssembler.Add(new Assembler {
                    id   = 1,
                    name = "Honda"
                });

                RepAssembler.Add(new Assembler
                {
                    id   = 2,
                    name = "Toyota"
                });

                RepAssembler.Add(new Assembler
                {
                    id   = 3,
                    name = "Fiat"
                });

                ctx.SaveChanges();
            }

            IList <Assembler> Asseblers = null;

            using (var ctx = uow.dbContext)
            {
                Asseblers = RepAssembler.FindAll();
            }

            Assert.AreEqual(3, Asseblers.Count);
            uow.Dispose();
        }
Exemplo n.º 4
0
        public void RepositoryWrite_car_Success()
        {
            RepositoryWrite_Assembler_Success();

            vmuow.UnitOfWorkEFcore <Context> uow = new vmuow.UnitOfWorkEFcore <Context>(new DbContextOptionsBuilder <Context>()
                                                                                        .UseInMemoryDatabase("Teste"));


            ITest <Car>       RepCar       = new MyRepository <Car, Context>(uow);
            ITest <Assembler> RepAssembler = new MyRepository <Assembler, Context>(uow);

            using (var ctx = uow.dbContext)
            {
                var _assembler = RepAssembler.Find(f => f.name == "Honda");

                Assert.IsNotNull(_assembler);

                var car = new Car
                {
                    id        = 1,
                    name      = "Honda Civic",
                    assembler = _assembler,
                };

                RepCar.Add(car);
                ctx.SaveChanges();
            }

            IList <Assembler> assemblers = null;
            IList <Car>       cars       = null;

            using (var ctx = uow.dbContext)
            {
                assemblers = RepAssembler.FindAll();
                cars       = RepCar.FindAll();
            }

            Assert.AreEqual(3, assemblers.Count);
            Assert.AreEqual(1, cars.Count);



            var carTst = new Car
            {
                id        = 1,
                name      = "Toyota Corola",
                assembler = assemblers.FirstOrDefault(f => f.name == "Toyota")
            };

            Assert.IsNotNull(carTst.assembler);

            using (var ctx = uow.dbContext)
            {
                RepCar.Update(carTst);
                ctx.SaveChanges();
            }

            cars       = null;
            assemblers = null;

            using (var ctx = uow.dbContext)
            {
                assemblers = RepAssembler.FindAll();
                cars       = RepCar.FindAll();
            }


            Assert.AreEqual(3, assemblers.Count);
            Assert.AreEqual(1, cars.Count);
            Assert.AreEqual("Toyota Corola", cars.First().name);
        }