Ejemplo n.º 1
0
 public async Task Add(Retailer retailer)
 {
     _context.Set <RetailerDbModel>()
     .Add(new RetailerDbModel()
     {
         Id                = Guid.NewGuid(),
         CPF               = retailer.CPF.Value,
         Name              = retailer.Name,
         Password          = retailer.Password,
         Email             = retailer.Email.Address,
         PreApprovedOrders = retailer.PreApprovedOrders
     });
     await _context.SaveChangesAsync();
 }
Ejemplo n.º 2
0
        public async Task Add(Order order)
        {
            var retailer = await _context.Set <RetailerDbModel>().FirstOrDefaultAsync(r => r.CPF == order.Retailer.CPF.Value);

            _context.Set <OrderDbModel>()
            .Add(new OrderDbModel()
            {
                Code          = order.Code,
                RetailerId    = retailer.Id,
                Value         = order.Value,
                ReferenceDate = order.ReferenceDate,
                Status        = order.Status
            });
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task Create_Order_With_Approoved_Status_Success()
        {
            var options = new DbContextOptionsBuilder <CashbackContext>()
                          .UseInMemoryDatabase(databaseName: $"Teste_OrderService{Guid.NewGuid()}")
                          .Options;

            var retailerCpf        = new Cpf("15350946056");
            var orderReferenceDate = DateTime.Now;


            using (var context = new CashbackContext(options))
            {
                context.Database.EnsureCreated();

                var retailerRepository = new RetailerRepository(context);

                await retailerRepository.Add(new Domain.Retailers.Retailer(new Domain.Dtos.Retailers.CreateRetailerDto()
                {
                    CPF      = retailerCpf.Value,
                    Name     = "Test name",
                    Email    = "*****@*****.**",
                    Password = "******"
                }));

                var orderRepository = new OrderRepository(context);

                var orderService = new OrderService(
                    retailerRepository,
                    orderRepository,
                    new CashbackService(),
                    new Mock <ILogger <OrderService> >().Object);

                await orderService.Create(new Domain.Dtos.Orders.CreateOrderDto()
                {
                    Code          = "ABC",
                    ReferenceDate = orderReferenceDate,
                    Value         = 200
                }, retailerCpf.Value);
            }
            using (var context = new CashbackContext(options))
            {
                var orders = await context.Set <OrderDbModel>().ToListAsync();

                Assert.Single(orders);
                Assert.Equal("ABC", orders.First().Code);
                Assert.Equal(200, orders.First().Value);
                Assert.Equal(orderReferenceDate, orders.First().ReferenceDate);
                Assert.Equal(OrderStatus.Approved, orders.First().Status);
            }
        }