public async Task <Xpto> InserValues()
        {
            var xptoEntity = await repository.GetAll().FirstOrDefaultAsync();

            if (xptoEntity == null)
            {
                xptoEntity = new Xpto();

                await repository.CreateAsync(xptoEntity);

                await repository.CommitAsync();
            }

            xptoEntity = await UpdateValues(xptoEntity, "TotalProduced", "produced", "vol_produced");

            xptoEntity = await UpdateValues(xptoEntity, "TotalPlanned", "planned", "vol_planned");

            repository.Update(xptoEntity);
            try
            {
                await repository.CommitAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(await Task.FromResult(xptoEntity));
        }
Example #2
0
        public void TEST_MOCK_REPOSITORY()
        {
            var options = new DbContextOptionsBuilder <EFApplicationContext>()
                          .UseInMemoryDatabase("portal_xpto")
                          .Options;

            using (var context = new EFApplicationContext(options))
            {
                context.XptoSet.Add(new Xpto {
                    Id = Guid.NewGuid()
                });
                context.XptoSet.Add(new Xpto {
                    Id = Guid.NewGuid()
                });
                context.SaveChanges();
            }

            using (var context = new EFApplicationContext(options))
            {
                var service = new XptoRepository(context);
                var result  = service.GetAll().ToList();
                Assert.NotNull(result);
            }
        }