Exemple #1
0
        public void TestaInclusaoELeituraDBSQLEF()
        {
            //**** CHECAR A STRING DE CONEXÃO NO ARQUIVO appsettings.json
            IUnitOfWorkTest unitOfWorkTest = new UnitOfWorkTestEF();

            Guid?guid = Guid.Parse("97A7513F-7D57-4171-96B5-AE02E2A9C6CE");

            Customer cliente = unitOfWorkTest.Customers.Get(guid);

            if (cliente == null)
            {
                cliente = new Customer {
                    Nome = "José da Silva"
                };
                cliente.SetId((guid));
                unitOfWorkTest.Customers.Save(cliente);
            }
            else
            {
                cliente.Nome = $"José da Silva + {DateTime.Now.ToShortDateString()} + {DateTime.Now.ToLongTimeString()}";
                unitOfWorkTest.Customers.Update(cliente);
            }
            unitOfWorkTest.SaveChanges();

            var obj = unitOfWorkTest.Customers.Get(guid);

            Assert.AreEqual(guid, obj.Id);
        }
        public void TestaInclusaoELeituraDBSQLEF()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json");
            var config = configuration.Build();

            var builder = new DbContextOptionsBuilder <UnitTesteContextEF>();

            builder.UseSqlServer(config.GetConnectionString("EF"));

            IUnitOfWorkTest unitOfWorkTest = new UnitOfWorkTestEF(new UnitTesteContextEF(builder.Options));

            var guid = Guid.Parse("97A7513F-7D57-4171-96B5-AE02E2A9C6CE");

            var cliente = unitOfWorkTest.Customers.Get(guid);

            if (cliente == null)
            {
                cliente = new Customer {
                    Nome = "José da Silva"
                };
                cliente.SetId((guid));
                unitOfWorkTest.Customers.Save(cliente);
            }
            else
            {
                cliente.Nome = $"José da Silva + {DateTime.Now.ToShortDateString()} + {DateTime.Now.ToLongTimeString()}";
                unitOfWorkTest.Customers.Update(cliente);
            }

            unitOfWorkTest.SaveChanges();

            var obj = unitOfWorkTest.Customers.Get(guid);

            Assert.AreEqual(guid, obj.Id);
        }