Exemplo n.º 1
0
        public async Task ValidatePayment_AvailablePaymentMethodsIsNull_Valid()
        {
            // Arrange
            var item = _fixture.Create <Payment>();

            // Act
            var validator = new CartPaymentValidator(null);
            var result    = await validator.ValidateAsync(item, ruleSet : "strict");

            // Assert
            result.Errors.Should().BeEmpty();
            result.IsValid.Should().BeTrue();
        }
Exemplo n.º 2
0
        public async Task ValidatePayment_RuleSetNotStrict_Valid()
        {
            // Arrange
            var item = _fixture.Create <Payment>();

            // Act
            var validator     = new CartPaymentValidator(_context.AvailPaymentMethods);
            var randomRuleSet = _fixture.Create <string>();
            var result        = await validator.ValidateAsync(item, ruleSet : randomRuleSet);

            // Assert
            result.Errors.Should().BeEmpty();
            result.IsValid.Should().BeTrue();
        }
Exemplo n.º 3
0
        public async Task ValidatePayment_PaymentGatewayCodeIsNull_Valid()
        {
            // Arrange
            var item = _fixture.Create <Payment>();

            item.PaymentGatewayCode = null;

            // Act
            var validator = new CartPaymentValidator(_context.AvailPaymentMethods);
            var result    = await validator.ValidateAsync(item, ruleSet : "strict");

            // Assert
            result.Errors.Should().BeEmpty();
            result.IsValid.Should().BeTrue();
        }
Exemplo n.º 4
0
        public async Task ValidatePayment_AvailablePaymentMethodsIsNull_Valid()
        {
            // Arrange
            var item = _fixture.Create <Payment>();

            // Act
            var validator = new CartPaymentValidator();
            var result    = await validator.ValidateAsync(new PaymentValidationContext
            {
                Payment = item
            });

            // Assert
            result.Errors.Should().BeEmpty();
            result.IsValid.Should().BeTrue();
        }
Exemplo n.º 5
0
        public async Task ValidatePayment_PaymentGatewayNotContainingInAvailPaymentMethods_Valid()
        {
            // Arrange
            _context.AvailPaymentMethods = _fixture.CreateMany <PaymentMethod>().ToList();
            var item = _fixture.Create <Payment>();

            // Act
            var validator = new CartPaymentValidator(_context.AvailPaymentMethods);
            var result    = await validator.ValidateAsync(item, ruleSet : "strict");

            // Assert
            var expected = CartErrorDescriber.PaymentMethodUnavailable(item, item.PaymentGatewayCode);

            result.Errors.Should().Contain(x =>
                                           x.ErrorMessage == expected.ErrorMessage &&
                                           x.ErrorCode == expected.ErrorCode);
        }
Exemplo n.º 6
0
        public async Task ValidatePayment_PaymentGatewayContainingInAvailPaymentMethods_Valid()
        {
            // Arrange
            _context.AvailPaymentMethods = _fixture.CreateMany <PaymentMethod>().ToList();
            var item = _fixture
                       .Build <Payment>()
                       .With(x => x.PaymentGatewayCode, _context.AvailPaymentMethods.First().Code)
                       .Create();

            // Act
            var validator = new CartPaymentValidator(_context.AvailPaymentMethods);
            var result    = await validator.ValidateAsync(item, ruleSet : "strict");

            // Assert
            result.Errors.Should().BeEmpty();
            result.IsValid.Should().BeTrue();
        }
Exemplo n.º 7
0
        public async Task ValidatePayment_RuleSetNotStrict_Valid()
        {
            // Arrange
            var item = _fixture.Create <Payment>();

            // Act
            var validator     = new CartPaymentValidator();
            var randomRuleSet = _fixture.Create <string>();
            var result        = await validator.ValidateAsync(new PaymentValidationContext
            {
                Payment             = item,
                AvailPaymentMethods = _context.AvailPaymentMethods
            }, options => options.IncludeRuleSets(randomRuleSet));

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