public async Task Modificar_Vigencia_Promocion_Success() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, MaximaCantidadDeCuotas = 3, FechaInicio = DateTime.Now.Date.AddDays(-3), FechaFin = DateTime.Now.Date.AddDays(-2) }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionCreadaId = await createHandler.Handle(command, default(CancellationToken)); GetPromocionesVigentesQuery getPromocionesVigentesQuery = new GetPromocionesVigentesQuery(); GetPromocionesVigentesHandler getPromocionesVigentesHandler = new GetPromocionesVigentesHandler(_promocionRepositoryAsync); var promocionesVigentes = await getPromocionesVigentesHandler.Handle(getPromocionesVigentesQuery, default(CancellationToken)); Assert.AreEqual(0, promocionesVigentes.Data.Count()); UpdateVigenciaPromocionCommand updateVigenciaPromocionCommand = new UpdateVigenciaPromocionCommand { Id = promocionCreadaId.Data, FechaInicio = command.FechaInicio, FechaFin = DateTime.Now.Date.AddDays(2) }; UpdateVigenciaPromocionCommandHandler updateVigenciaPromocionCommandHandler = new UpdateVigenciaPromocionCommandHandler(_promocionRepositoryAsync); await updateVigenciaPromocionCommandHandler.Handle(updateVigenciaPromocionCommand, default(CancellationToken)); promocionesVigentes = await getPromocionesVigentesHandler.Handle(getPromocionesVigentesQuery, default(CancellationToken)); Assert.AreEqual(1, promocionesVigentes.Data.Count()); }
public async Task Eliminar_Promocion_Success() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, MaximaCantidadDeCuotas = 3, FechaInicio = new DateTime(2021, 3, 1), FechaFin = new DateTime(2021, 3, 31) }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionCreadaId = await createHandler.Handle(command, default(CancellationToken)); DeletePromocionByIdCommand deletePromocionByIdCommand = new DeletePromocionByIdCommand { Id = promocionCreadaId.Data }; DeleteProductByIdCommandHandler deleteProductByIdCommandHandler = new DeleteProductByIdCommandHandler(_promocionRepositoryAsync); var promocionEliminado = await deleteProductByIdCommandHandler.Handle(deletePromocionByIdCommand, default(CancellationToken)); GetPromocionByIdQuery getPromocionByIdQuery = new GetPromocionByIdQuery { Id = promocionCreadaId.Data }; GetProductByIdQueryHandler getProductByIdQueryHandler = new GetProductByIdQueryHandler(_promocionRepositoryAsync); var promocionById = await getProductByIdQueryHandler.Handle(getPromocionByIdQuery, default(CancellationToken)); Assert.AreEqual(promocionCreadaId.Data, promocionEliminado.Data); Assert.IsFalse(promocionById.Data.Activo); }
public async Task <Response <Guid> > Handle(CreatePromocionCommand request, CancellationToken cancellationToken) { var promocion = _mapper.Map <Promocion>(request); promocion.FechaCreacion = DateTime.UtcNow; promocion.Activo = true; await _promocionRepository.AddAsync(promocion); return(new Response <Guid>(promocion.Id)); }
public async Task Ver_Promociones_Vigentes_Venta_Success() { var createCommands = new CreatePromocionCommand[] { new CreatePromocionCommand() { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, PorcentajeDeDescuento = 30, FechaInicio = DateTime.Now.Date.AddDays(-1), FechaFin = DateTime.Now.Date.AddDays(1) }, new CreatePromocionCommand() { Bancos = new string[] { "ICBC" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "Colchones" }, PorcentajeDeDescuento = 30, FechaInicio = DateTime.Now.Date.AddDays(-1), FechaFin = DateTime.Now.Date.AddDays(1) }, new CreatePromocionCommand() { Bancos = new string[] { "ICBC" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "Colchones" }, PorcentajeDeDescuento = 20, FechaInicio = DateTime.Now.Date.AddDays(-5), FechaFin = DateTime.Now.Date.AddDays(-3) } }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); foreach (var cmd in createCommands) { await createHandler.Handle(cmd, default(CancellationToken)); } GetPromocionesVigentesParaVentaQuery getPromocionesVigentesParaVentaQuery = new GetPromocionesVigentesParaVentaQuery { Banco = "ICBC" }; GetPromocionesVigentesParaVentaQueryHandler getPromocionesVigentesParaVentaQueryHandler = new GetPromocionesVigentesParaVentaQueryHandler(_promocionRepositoryAsync, _mapper); var promocionesVigentesVenta = await getPromocionesVigentesParaVentaQueryHandler.Handle(getPromocionesVigentesParaVentaQuery, default(CancellationToken)); Assert.AreEqual(1, promocionesVigentesVenta.Data.Count()); }
public async Task Modificar_Vigencia_Promocion_Error() { var createCommands = new CreatePromocionCommand[] { new CreatePromocionCommand() { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "ElectroCocina" }, PorcentajeDeDescuento = 30, FechaInicio = DateTime.Now.Date.AddDays(-2), FechaFin = DateTime.Now.Date.AddDays(1) }, new CreatePromocionCommand() { Bancos = new string[] { "ICBC" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "Colchones" }, PorcentajeDeDescuento = 30, FechaInicio = DateTime.Now.Date, FechaFin = DateTime.Now.Date.AddDays(1) } }; int errors = 0; string errorField = ""; CreatePromocionCommandValidator valiator = new CreatePromocionCommandValidator(_promocionRepositoryAsync, _mapper); CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); foreach (var cmd in createCommands) { var validation = valiator.Validate(cmd); if (!validation.IsValid) { errors++; errorField = validation.Errors.First().PropertyName; } else { await createHandler.Handle(cmd, default(CancellationToken)); } } Assert.AreEqual(1, errors); Assert.AreEqual("Solapamiento", errorField); }
public void Crear_Promocion_Sin_Cuotas_Ni_Descuento_Error() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "ElectroCocina" }, FechaInicio = DateTime.Now.Date.AddDays(-1), FechaFin = DateTime.Now.Date.AddDays(1) }; CreatePromocionCommandValidator valiator = new CreatePromocionCommandValidator(_promocionRepositoryAsync, _mapper); var validation = valiator.Validate(command); Assert.IsFalse(validation.IsValid); Assert.AreEqual(validation.Errors.First().PropertyName, "CuotaODescuento"); }
public void Crear_Promocion_Con_Fin_Menor_Inicio_Error() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "EFECTIVO" }, CategoriasProductos = new string[] { "ElectroCocina" }, PorcentajeDeDescuento = 50, FechaInicio = DateTime.Now.Date.AddDays(-1), FechaFin = DateTime.Now.Date.AddDays(-2) }; CreatePromocionCommandValidator valiator = new CreatePromocionCommandValidator(_promocionRepositoryAsync, _mapper); var validation = valiator.Validate(command); Assert.IsFalse(validation.IsValid); Assert.AreEqual(nameof(command.FechaFin), validation.Errors.First().PropertyName); }
public async Task Crear_Promocion_Success() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, MaximaCantidadDeCuotas = 3, FechaInicio = new DateTime(2021, 3, 1), FechaFin = new DateTime(2021, 3, 31) }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionCreada = await createHandler.Handle(command, default(CancellationToken)); Assert.NotNull(promocionCreada.Data); Assert.AreNotEqual(Guid.Empty, promocionCreada.Data); }
public async Task Ver_Listado_Promociones_Success() { CreatePromocionCommand createCommand = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, PorcentajeDeDescuento = 30, FechaInicio = new DateTime(2021, 3, 1), FechaFin = new DateTime(2021, 3, 31) }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionCreada = await createHandler.Handle(createCommand, default(CancellationToken)); GetAllPromocionesQuery getAllCommand = new GetAllPromocionesQuery(); GetAllPromocionesQueryHandler getAllHandler = new GetAllPromocionesQueryHandler(_promocionRepositoryAsync); var promociones = await getAllHandler.Handle(getAllCommand, default(CancellationToken)); Assert.AreEqual(1, promociones.Data.Count()); Assert.AreEqual(promocionCreada.Data, promociones.Data.First().Id); }
public async Task Modificar_Promocion_Success() { var command = new CreatePromocionCommand { Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "TARJETA_CREDITO" }, CategoriasProductos = new string[] { "ElectroCocina" }, MaximaCantidadDeCuotas = 3, FechaInicio = new DateTime(2021, 3, 1), FechaFin = new DateTime(2021, 3, 31) }; CreatePromocionCommandHandler createHandler = new CreatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionCreada = await createHandler.Handle(command, default(CancellationToken)); UpdatePromocionCommand updatePromocionCommand = new UpdatePromocionCommand { Id = promocionCreada.Data, Bancos = new string[] { "Galicia" }, MediosDePago = new string[] { "GIFT_CARD" }, CategoriasProductos = new string[] { "ElectroCocina" }, MaximaCantidadDeCuotas = 3, FechaInicio = new DateTime(2021, 3, 1), FechaFin = new DateTime(2021, 3, 31) }; UpdatePromocionCommandHandler updatePromocionCommandHandler = new UpdatePromocionCommandHandler(_promocionRepositoryAsync, _mapper); var promocionModificado = await updatePromocionCommandHandler.Handle(updatePromocionCommand, default(CancellationToken)); GetPromocionByIdQuery getPromocionByIdQuery = new GetPromocionByIdQuery { Id = promocionCreada.Data }; GetProductByIdQueryHandler getProductByIdQueryHandler = new GetProductByIdQueryHandler(_promocionRepositoryAsync); var promocionById = await getProductByIdQueryHandler.Handle(getPromocionByIdQuery, default(CancellationToken)); Assert.AreEqual(promocionCreada.Data, promocionModificado.Data); Assert.NotNull(promocionById.Data.FechaModificacion); Assert.AreEqual("GIFT_CARD", promocionById.Data.MediosDePago.FirstOrDefault()); }
public async Task <IActionResult> Post(CreatePromocionCommand command) => Ok(await Mediator.Send(command));