Ejemplo n.º 1
0
        public async Task Handle_ShouldPersistPaymentState()
        {
            var dateTimeMock = new Mock <IDateTime>();

            dateTimeMock.Setup(m => m.Now)
            .Returns(new DateTime(4001, 1, 1));


            var command = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand
            {
                Amount           = 80,
                ExpirationDate   = DateTime.Now,
                CardHolder       = "test",
                SecurityCode     = "123",
                CreditCardNumber = "379354508162306"
            };



            var handler = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand.CreatePaymentCommandHandler(Context, dateTimeMock.Object);

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

            var entity = Context.Payments.First();

            var paymentState = Context.PaymentStates.First();

            paymentState.ShouldNotBeNull();
            paymentState.PaymentId.ShouldBe(entity.Id.ToString());
            paymentState.Status.ShouldBe(PaymentStatus.Pending);
        }
Ejemplo n.º 2
0
        public async Task Handle_ShouldPersistPayment()
        {
            var command = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand
            {
                Amount           = 80,
                ExpirationDate   = DateTime.Today,
                CardHolder       = "test",
                SecurityCode     = "123",
                CreditCardNumber = "379354508162306"
            };

            var dateTimeMock = new Mock <IDateTime>();

            dateTimeMock.Setup(m => m.Now)
            .Returns(new DateTime(3001, 1, 1));

            var handler = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand.CreatePaymentCommandHandler(Context, dateTimeMock.Object);

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

            var entity = Context.Payments.First();

            entity.ShouldNotBeNull();
            entity.Amount.ToString().ShouldBe(command.Amount.ToString(CultureInfo.InvariantCulture));
            //entity.SecurityCode.ToString().ShouldBe(command.SecurityCode);
            entity.CreditCardNumber.ToString().ShouldBe(command.CreditCardNumber);
            entity.ExpirationDate.ShouldBe(command.ExpirationDate);
        }
Ejemplo n.º 3
0
        public void IsValid_ShouldBeFalse_WhenMissingMandatoryFields()
        {
            var command = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand
            {
                Amount         = 30,
                ExpirationDate = DateTime.Today,
                CardHolder     = "test",
            };
            var dateTimeMock = new Mock <IDateTime>();

            dateTimeMock.Setup(m => m.Now)
            .Returns(new DateTime(3001, 1, 1));

            var validator = new CreatePaymentCommandValidator(Context, dateTimeMock.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
Ejemplo n.º 4
0
        public void IsValid_ShouldBeTrue_WhenAllParametersAreCorrect()
        {
            var dateTimeMock = new Mock <IDateTime>();

            dateTimeMock.Setup(m => m.Now)
            .Returns(new DateTime(2001, 1, 1));

            var command = new Application.Payments.Commands.CreatePayment.CreatePaymentCommand
            {
                Amount           = 30,
                SecurityCode     = "123",
                ExpirationDate   = DateTime.Today,
                CardHolder       = "test",
                CreditCardNumber = "379354508162306"
            };


            var validator = new CreatePaymentCommandValidator(Context, dateTimeMock.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }