public async Task GetProductByIdQueryHandlerAsync_WithNullParameter_ThrowsException() { //Arrange GetProductByIdQueryRequest command = null; //Act var actualException = await Assert.ThrowsAsync <Exception>(() => _getProductByIdQueryHandler.Handle(command, new CancellationToken())); //Assert Assert.Equal(MessageConstants.GetProductByIdQueryRequestNull, actualException.Message); }
public async Task WhenProductWithGivenIdDoesNotExistThenThrowNotFoundException() { var productId = Guid.NewGuid(); var inputQuery = CreateQuery(productId); _productRepository.Setup(r => r.GetById(productId)) .ReturnsAsync(() => null); Func <Task> act = async() => await _getProductByIdQueryHandler.Handle(inputQuery, default); await act.Should().ThrowAsync <NotFoundException>(); }
public async Task GetProductByIdQueryHandler_WhenCalled_ReturnGetCategoryByIdLookupModel() { var returnModel = new GetProductByIdQueryLookupModel { ProductId = 1, Name = "Product1" }; _productServiceMock .Setup(x => x.GetProductByIdAsync(It.IsAny <int>(), CancellationToken.None)) .ReturnsAsync(returnModel); var query = new GetProductByIdQuery { ProductId = 1 }; var container = Registrations(); await using var scope = container.BeginLifetimeScope(); var options = scope.Resolve <DbContextOptions <TechnicalTestDbContext> >(); await using var context = new TechnicalTestDbContext(options); await SeedMockDataAsync(context); var handler = new GetProductByIdQueryHandler(_productServiceMock.Object); var result = await handler.Handle(query, CancellationToken.None); Assert.AreEqual("Product1", result.Name); }
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 void GetProdcuctByIdNotFound(ProductVm product) { var handler = new GetProductByIdQueryHandler(_productService.Object); var result = handler.Handle(new GetProductByIdQuery(product.Id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <ProductVm> > >(result); Assert.AreEqual(StatusCodes.Status404NotFound, result.Result.StatusCode); }
public void GetProductByIdSuccessfully(ProductVm product) { _productService.Setup(ps => ps.GetProductById(It.IsAny <Guid>())).ReturnsAsync(new Product { Id = product.Id, Name = product.Name, Price = product.Price }); var handler = new GetProductByIdQueryHandler(_productService.Object); var result = handler.Handle(new GetProductByIdQuery(product.Id), default); Assert.IsNotNull(result); Assert.IsInstanceOf <Task <Response <ProductVm> > >(result); Assert.AreEqual(StatusCodes.Status200OK, result.Result.StatusCode); }
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 Ver_Promocion_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)); GetPromocionByIdQuery getPromocionByIdQuery = new GetPromocionByIdQuery { Id = promocionCreada.Data }; GetProductByIdQueryHandler getProductByIdQueryHandler = new GetProductByIdQueryHandler(_promocionRepositoryAsync); var promocionById = await getProductByIdQueryHandler.Handle(getPromocionByIdQuery, default(CancellationToken)); Assert.AreEqual(promocionCreada.Data, promocionById.Data.Id); }