Пример #1
0
        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);
        }
Пример #2
0
        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 GetProductByIdQueryHandlerTests()
        {
            var _mediatoR               = new Mock <IMediator>();
            var _mockMapper             = new Mock <IMapper>();
            var mockedProductRepository = new Mock <IProductRepository>();

            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _mockUnitOfWork.Setup(x => x.ProductRepository).Returns(mockedProductRepository.Object);

            _getProductByIdQueryHandler = new GetProductByIdQueryHandler(_mockUnitOfWork.Object, _mockMapper.Object);
        }
        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);
        }
Пример #6
0
        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());
        }
Пример #7
0
        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);
        }
Пример #8
0
 public GetProductByIdQueryHandlerTests()
 {
     _getProductByIdQueryHandler = new GetProductByIdQueryHandler(_productRepository.Object);
 }