Beispiel #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();
        }
Beispiel #2
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);
        }