Esempio n. 1
0
        public async Task ItShouldReturnSuccess()
        {
            _uow.Setup(x => x.OrderItemTypeRepository.IsQuantityProductValid(It.IsAny <long>(), It.IsAny <int>())).ReturnsAsync(true);
            _uow.Setup(x => x.OrderRepository.Add(It.IsAny <Order>())).ReturnsAsync(OrderRepositoryFake.OrderValid());
            _uow.Setup(x => x.ProductRepository.GetProductById(It.IsAny <long>())).ReturnsAsync(ProductRepositoryFake.GetById());

            _orderService.Setup(x => x.AddOrder(It.IsAny <decimal>())).ReturnsAsync(OrderRepositoryFake.OrderValid());
            _AddresService.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())).ReturnsAsync(AddressRepositoryFake.GetFirstOrDefaultValid());

            AddOrderWithOutUserCommand command = new AddOrderWithOutUserCommand();

            command.City         = "São Paulo";
            command.Neighborhood = "Madalena";
            command.Number       = 1;
            command.Street       = "Tuiuti";
            command.OrderItems.Add(new OrderItemModel()
            {
                Description     = "",
                OrderItemTypeID = 1,
                Products        = { 1, 2 }
            });

            var result = await _handler.Handle(command, CancellationToken.None);

            foreach (var item in result.Errors)
            {
                _output.WriteLine(item);
            }

            Assert.True(result.Success);
        }
Esempio n. 2
0
        public async Task ItShouldReturnErrorWhenFieldIsRequired(AddressRequestModelFake request)
        {
            _uow.Setup(x => x.OrderItemTypeRepository.IsQuantityProductValid(It.IsAny <long>(), It.IsAny <int>())).ReturnsAsync(true);
            _uow.Setup(x => x.OrderRepository.Add(It.IsAny <Order>())).ReturnsAsync(OrderRepositoryFake.OrderValid());
            _uow.Setup(x => x.ProductRepository.GetProductById(It.IsAny <long>())).ReturnsAsync(ProductRepositoryFake.GetById());

            _orderService.Setup(x => x.AddOrder(It.IsAny <decimal>())).ReturnsAsync(OrderRepositoryFake.OrderValid());

            AddOrderWithOutUserCommand command = new AddOrderWithOutUserCommand();

            command.City         = request.City;
            command.Neighborhood = request.Neighborhood;
            command.Number       = request.Number;
            command.Street       = request.Street;
            command.OrderItems.Add(new OrderItemModel()
            {
                Description     = "",
                OrderItemTypeID = 1,
                Products        = { 1, 2 }
            });

            var result = await _handler.Handle(command, CancellationToken.None);

            foreach (var item in result.Errors)
            {
                _output.WriteLine(item);
            }

            Assert.False(result.Success);
        }
        public async Task ItShouldReturnSuccess()
        {
            _uow.Setup(x => x.OrderItemTypeRepository.IsQuantityProductValid(It.IsAny <long>(), It.IsAny <int>())).ReturnsAsync(true);
            _uow.Setup(x => x.OrderRepository.Add(It.IsAny <Order>())).ReturnsAsync(OrderRepositoryFake.OrderValid());
            _uow.Setup(x => x.ProductRepository.GetProductById(It.IsAny <long>())).ReturnsAsync(ProductRepositoryFake.GetById());
            _uow.Setup(x => x.UserRepository.GetById(It.IsAny <long>())).ReturnsAsync(new User());

            _orderService.Setup(x => x.AddOrder(It.IsAny <decimal>())).ReturnsAsync(OrderRepositoryFake.OrderValid());

            AddOrderCommand command = new AddOrderCommand();

            command.UserID = 1;
            command.OrderItems.Add(new OrderItemModel()
            {
                Description     = "",
                OrderItemTypeID = 1,
                Products        = { 1, 2 }
            });

            var result = await _handler.Handle(command, CancellationToken.None);

            foreach (var item in result.Errors)
            {
                _output.WriteLine(item);
            }

            Assert.True(result.Success);
        }