Esempio n. 1
0
        public async Task Handle_SinglePaymentMethodPresentOnStripeCustomer_SinglePaymentMethodReturned()
        {
            //Arrange
            await using var environment = await IntegrationTestEnvironment.CreateAsync();

            var createdUser = await environment.Mediator.Send(
                new CreateUserForIdentityCommand(
                    TestClaimsPrincipalFactory.CreateWithIdentityName("some-identity-name")));

            var createdPaymentMethod = await environment
                                       .ServiceProvider
                                       .GetRequiredService <PaymentMethodService>()
                                       .CreateAsync(new PaymentMethodCreateOptions()
            {
                Card = new PaymentMethodCardCreateOptions()
                {
                    Number   = "4242424242424242",
                    Cvc      = "123",
                    ExpMonth = 10,
                    ExpYear  = 30
                },
                Type = "card"
            });

            await environment.Mediator.Send(
                new SetActivePaymentMethodForUserCommand(
                    createdUser,
                    createdPaymentMethod.Id));

            //Act
            var activePaymentMethod = await environment.Mediator.Send(
                new GetActivePaymentMethodForUserQuery(
                    createdUser));

            //Assert
            Assert.IsNotNull(activePaymentMethod);
        }
        public async Task Handle_ExistingPaymentMethodsPresent_DefaultPaymentMethodChangedToAddedMethod()
        {
            //Arrange
            await using var environment = await IntegrationTestEnvironment.CreateAsync();

            var user = await environment.Mediator.Send(
                new CreateUserForIdentityCommand(
                    TestClaimsPrincipalFactory.CreateWithIdentityName("some-identity-name")));

            var paymentMethodService = environment
                                       .ServiceProvider
                                       .GetRequiredService <PaymentMethodService>();

            var existingPaymentMethod = await CreatePaymentMethodAsync(paymentMethodService);

            await paymentMethodService.AttachAsync(existingPaymentMethod.Id, new PaymentMethodAttachOptions()
            {
                Customer = user.StripeCustomerId
            });

            var newPaymentMethod = await CreatePaymentMethodAsync(paymentMethodService);

            //Act
            await environment.Mediator.Send(
                new SetActivePaymentMethodForUserCommand(
                    user,
                    newPaymentMethod.Id));

            //Assert
            var stripeCustomer = await environment
                                 .ServiceProvider
                                 .GetRequiredService <CustomerService>()
                                 .GetAsync(user.StripeCustomerId);

            Assert.AreEqual(stripeCustomer.InvoiceSettings.DefaultPaymentMethodId, newPaymentMethod.Id);
        }
Esempio n. 3
0
        public async Task Handle_ProperArgumentsGivenAtEndOfMonth_FullServerProvisioningFlowIsRunAndProperInstanceIsCreated()
        {
            //Arrange
            var lastDayOfLastMonth =
                new DateTime(
                    DateTime.Now.Year,
                    DateTime.Now.Month,
                    1)
                .AddDays(-1);

            var fakeTimeProvider = Substitute.For <ITimeProvider>();

            fakeTimeProvider
            .UtcNow
            .Returns(lastDayOfLastMonth);

            await using var environment = await IntegrationTestEnvironment.CreateAsync(
                            new EnvironmentSetupOptions ()
            {
                IocConfiguration = services =>
                {
                    FakeOutMinimalLightsailFeaturesForFullProvisioning(services);

                    services.AddSingleton(fakeTimeProvider);
                }
            });

            var provisioningService = environment
                                      .ServiceProvider
                                      .GetRequiredService <IProvisioningService>();

            var paymentMethodService = environment
                                       .ServiceProvider
                                       .GetRequiredService <PaymentMethodService>();

            var user = await environment.Mediator.Send(
                new CreateUserForIdentityCommand(
                    TestClaimsPrincipalFactory.CreateWithIdentityName("some-identity-name")));

            var paymentMethod = await CreatePaymentMethodAsync(paymentMethodService);

            await environment.Mediator.Send(
                new SetActivePaymentMethodForUserCommand(
                    user,
                    paymentMethod.Id));

            //Act
            await environment.Mediator.Send(
                new ProvisionInstanceForUserCommand(
                    new Plan(
                        "nano_2_0",
                        1337,
                        new Bundle()
            {
                Price = 1337,
                BundleId = "nano_2_0"
            },
                        Array.Empty <PullDogPlan>()),
                    user));

            await provisioningService.ProcessPendingJobsAsync();

            //Assert
            await environment.WithFreshDataContext(async dataContext =>
            {
                var provisionedInstance = await dataContext
                                          .Instances
                                          .Include(x => x.Cluster)
                                          .ThenInclude(x => x.User)
                                          .SingleAsync();

                Assert.IsTrue(provisionedInstance.IsProvisioned);
                Assert.AreEqual(provisionedInstance.Cluster.UserId, user.Id);
            });
        }
Esempio n. 4
0
 public static void FakeAuthentication(this ControllerBase controller, string identityName)
 {
     controller.EnsureControllerContext();
     controller.HttpContext.User = TestClaimsPrincipalFactory.CreateWithIdentityName(identityName);
 }