Esempio n. 1
0
        public ApiClient ResetSandboxClient(SandboxInitializationModel createModel, User user)
        {
            var client = SetupDefaultSandboxClient(createModel, user);

            ProvisionSandbox(client);

            return(client);
        }
            protected override void Arrange()
            {
                const int         VendorId    = 444;
                const SandboxType SandboxType = SandboxType.Minimal;

                var defaultApplicationCreator = A.Fake <IDefaultApplicationCreator>();

                var application = new Application {
                    ApplicationName = "Application.ApplicationName"
                };

                application.CreateApplicationEducationOrganization(111);
                application.CreateApplicationEducationOrganization(222);
                application.CreateApplicationEducationOrganization(333);

                A.CallTo(
                    () =>
                    defaultApplicationCreator.FindOrCreateUpdatedDefaultSandboxApplication(VendorId, SandboxType))
                .Returns(application);

                ApiClient apiClient = new ApiClient {
                    Name = "ApiClient.Name"
                };

                var clientAppRepo = A.Fake <IClientAppRepo>();
                var user          = new User {
                    Vendor = new Vendor {
                        VendorId = VendorId
                    }
                };

                var sandboxClientCreateModel = new SandboxInitializationModel
                {
                    Name        = "SandboxInitializationModel.Name",
                    SandboxType = SandboxType
                };

                A.CallTo(
                    () => clientAppRepo.SetupDefaultSandboxClient(
                        sandboxClientCreateModel.Name,
                        sandboxClientCreateModel.SandboxType,
                        null,
                        null,
                        user.UserId,
                        application.ApplicationId)).Returns(apiClient);

                var clientAppConfigValueProviderRepo = A.Fake <IConfigValueProvider>();

                var sandboxProvisioner = A.Fake <ISandboxProvisioner>();

                var creator = new ClientCreator(clientAppConfigValueProviderRepo, clientAppRepo, defaultApplicationCreator, sandboxProvisioner);

                _apiClient = creator.CreateNewSandboxClient(sandboxClientCreateModel, user);
            }
Esempio n. 3
0
        private ApiClient SetupDefaultSandboxClient(SandboxInitializationModel createModel, User user)
        {
            var defaultApplication = _defaultApplicationCreator
                                     .FindOrCreateUpdatedDefaultSandboxApplication(user.Vendor.VendorId, createModel.SandboxType);

            return(_clientAppRepo.SetupDefaultSandboxClient(
                       createModel.Name,
                       createModel.SandboxType,
                       createModel.Key,
                       createModel.Secret,
                       user.UserId,
                       defaultApplication.ApplicationId));
        }
Esempio n. 4
0
        public ApiClient CreateNewSandboxClient(SandboxInitializationModel createModel, User user)
        {
            if (user.ApiClients.Count >= _maximumSandboxesPerUser)
            {
                var message = $"The maximum of {_maximumSandboxesPerUser} sandboxes for user id {user.UserId} has been reached!";
                message += " To configure please update the 'MaximumSandboxesPerUser' app setting in the web.config.";
                _log.Error(message);
                throw new ArgumentOutOfRangeException(message);
            }

            var client = SetupDefaultSandboxClient(createModel, user);

            ProvisionSandbox(client);

            return(client);
        }