Exemplo n.º 1
0
        public async Task ValidateShipment_RuleSetDefault_PriceError()
        {
            // Arrange
            var shipment = new CartModule.Core.Model.Shipment
            {
                ShipmentMethodCode   = "shippingMethodCode",
                ShipmentMethodOption = ":)",
            };

            shipment.Price = _shippingRate.Rate + 1;

            // Act
            var validator = new CartShipmentValidator();
            var result    = await validator.ValidateAsync(new ShipmentValidationContext
            {
                Shipment           = shipment,
                AvailShippingRates = _context.AvailShippingRates
            });

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().NotBeEmpty();
            result.Errors.Should().HaveCount(1);
            result.Errors.Should().Contain(x => x.ErrorCode == "SHIPMENT_METHOD_PRICE_CHANGED");
        }
        public async Task ValidateShipment_RuleSetDefault_ShipmentMethodCodeIsEmpty_Valid()
        {
            // Arrange
            var shipment = new CartModule.Core.Model.Shipment
            {
                ShipmentMethodCode = string.Empty
            };

            // Act
            var validator = new CartShipmentValidator(_context.AvailShippingRates);
            var result    = await validator.ValidateAsync(shipment, ruleSet : "default");

            // Assert
            result.IsValid.Should().BeTrue();
            result.Errors.Should().BeEmpty();
        }
        public async Task ValidateShipment_RuleSetStrict_UnavailableMethodError()
        {
            // Arrange
            var shipment = new CartModule.Core.Model.Shipment
            {
                ShipmentMethodCode = "UnavailableShipmentMethod"
            };

            // Act
            var validator = new CartShipmentValidator(_context.AvailShippingRates);
            var result    = await validator.ValidateAsync(shipment, ruleSet : "strict");

            // Assert
            result.IsValid.Should().BeFalse();
            result.Errors.Should().NotBeEmpty();
            result.Errors.Should().HaveCount(1);
            result.Errors.Should().Contain(x => x.ErrorCode == "SHIPMENT_METHOD_UNAVAILABLE");
        }
Exemplo n.º 4
0
        public async Task ValidateShipment_RuleSetDefault_ShipmentMethodCodeIsNull_Valid()
        {
            // Arrange
            var shipment = new CartModule.Core.Model.Shipment
            {
                ShipmentMethodCode = null
            };

            // Act
            var validator = new CartShipmentValidator();
            var result    = await validator.ValidateAsync(new ShipmentValidationContext
            {
                Shipment           = shipment,
                AvailShippingRates = _context.AvailShippingRates
            });

            // Assert
            result.IsValid.Should().BeTrue();
            result.Errors.Should().BeEmpty();
        }