Exemple #1
0
        public async Task <Apprenticeship> CreateApprenticeship(
            Guid providerId,
            StandardOrFramework standardOrFramework,
            UserInfo createdBy,
            ApprenticeshipStatus status = ApprenticeshipStatus.Live,
            string marketingInformation = "Marketing info",
            string website          = "http://provider.com/apprenticeship",
            string contactTelephone = "01234 567890",
            string contactEmail     = "*****@*****.**",
            string contactWebsite   = "http://provider.com",
            DateTime?createdUtc     = null,
            IEnumerable <CreateApprenticeshipLocation> locations = null)
        {
            var provider = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetProviderById()
            {
                ProviderId = providerId
            });

            if (provider == null)
            {
                throw new ArgumentException("Provider does not exist.", nameof(providerId));
            }

            var apprenticeshipId = Guid.NewGuid();

            await _cosmosDbQueryDispatcher.ExecuteQuery(new CreateApprenticeship()
            {
                Id                  = apprenticeshipId,
                ProviderId          = providerId,
                ProviderUkprn       = provider.Ukprn,
                Status              = (int)status,
                ApprenticeshipTitle = standardOrFramework.StandardOrFrameworkTitle,
                ApprenticeshipType  = standardOrFramework.IsStandard ?
                                      ApprenticeshipType.StandardCode :
                                      ApprenticeshipType.FrameworkCode,
                StandardOrFramework  = standardOrFramework,
                MarketingInformation = marketingInformation,
                Url = website,
                ContactTelephone        = contactTelephone,
                ContactEmail            = contactEmail,
                ContactWebsite          = contactWebsite,
                ApprenticeshipLocations = locations ?? new List <CreateApprenticeshipLocation> {
                    CreateApprenticeshipLocation.CreateNational()
                },
                CreatedDate   = createdUtc ?? _clock.UtcNow,
                CreatedByUser = createdBy
            });

            var createdApprenticeships = await _cosmosDbQueryDispatcher.ExecuteQuery(
                new GetApprenticeshipsByIds()
            {
                ApprenticeshipIds = new[] { apprenticeshipId }
            });

            var apprenticeship = createdApprenticeships[apprenticeshipId];

            await _sqlDataSync.SyncApprenticeship(apprenticeship);

            return(apprenticeship);
        }
        public async Task Initialize_EmployerBasedLocationType_PopulatesModelCorrectly()
        {
            // Arrange
            var ukprn            = 12346;
            var adminUserId      = $"admin-user";
            var contactTelephone = "1111 111 1111";
            var website          = "https://somerandomprovider.com/apprenticeship";
            var contactWebsite   = "https://somerandomprovider.com";
            var marketingInfo    = "Providing Online training";
            var contactEmail     = "*****@*****.**";

            var providerId = await TestData.CreateProvider(
                ukprn : ukprn,
                providerName : "Provider 1",
                apprenticeshipQAStatus : ApprenticeshipQAStatus.Submitted);

            var providerUserId = $"{ukprn}-user";
            var user           = await TestData.CreateUser(providerUserId, "*****@*****.**", "Provider 1", "Person", providerId);

            var adminUser = await TestData.CreateUser(adminUserId, "*****@*****.**", "admin", "admin", null);

            var framework = await TestData.CreateFramework(1, 1, 1, "Test Framework");

            var apprenticeshipId = await TestData.CreateApprenticeship(providerId,
                                                                       framework,
                                                                       createdBy : user,
                                                                       contactEmail : contactEmail,
                                                                       contactTelephone : contactTelephone,
                                                                       contactWebsite : contactWebsite,
                                                                       marketingInformation : marketingInfo,
                                                                       website : website,
                                                                       locations : new[]
            {
                CreateApprenticeshipLocation.CreateNational()
            });

            var standardsAndFrameworksCache = new StandardsAndFrameworksCache(CosmosDbQueryDispatcher.Object);

            var submissionId = await TestData.CreateApprenticeshipQASubmission(
                providerId,
                submittedOn : Clock.UtcNow,
                submittedByUserId : providerUserId,
                providerMarketingInformation : "The overview",
                apprenticeshipIds : new[] { apprenticeshipId });

            await WithSqlQueryDispatcher(async dispatcher =>
            {
                var initializer = new FlowModelInitializer(CosmosDbQueryDispatcher.Object, dispatcher, standardsAndFrameworksCache);

                // Act
                var model = await initializer.Initialize(providerId);

                // Assert
                Assert.True(model.GotApprenticeshipDetails);
                Assert.Equal(contactEmail, model.ApprenticeshipContactEmail);
                Assert.Equal(contactTelephone, model.ApprenticeshipContactTelephone);
                Assert.Equal(contactWebsite, model.ApprenticeshipContactWebsite);
                Assert.Equal(apprenticeshipId, model.ApprenticeshipId);
                Assert.True(model.ApprenticeshipIsNational);
                Assert.Equal(ApprenticeshipLocationType.EmployerBased, model.ApprenticeshipLocationType);
                Assert.Equal(marketingInfo, model.ApprenticeshipMarketingInformation);
                Assert.Null(model.ApprenticeshipClassroomLocations);
                Assert.Equal(website, model.ApprenticeshipWebsite);
                Assert.True(model.ApprenticeshipStandardOrFramework.IsFramework);
                Assert.False(model.ApprenticeshipStandardOrFramework.IsStandard);
            });
        }
        public async Task Initialize_BothLocationType_InitializesModelCorrectly()
        {
            // Arrange
            var ukprn            = 12346;
            var adminUserId      = $"admin-user";
            var contactTelephone = "1111 111 1111";
            var website          = "https://somerandomprovider.com/apprenticeship";
            var contactWebsite   = "https://somerandomprovider.com";
            var marketingInfo    = "Providing Online training";
            var regions          = new List <string> {
                "123"
            };
            var contactEmail = "*****@*****.**";
            var radius       = 30;
            var deliveryMode = ApprenticeshipDeliveryMode.BlockRelease;
            var providerId   = await TestData.CreateProvider(
                ukprn : ukprn,
                providerName : "Provider 1",
                apprenticeshipQAStatus : ApprenticeshipQAStatus.Submitted);

            var providerUserId = $"{ukprn}-user";
            var user           = await TestData.CreateUser(providerUserId, "*****@*****.**", "Provider 1", "Person", providerId);

            var adminUser = await TestData.CreateUser(adminUserId, "*****@*****.**", "admin", "admin", null);

            var framework = await TestData.CreateFramework(1, 1, 1, "Test Framework");

            var venueId = await TestData.CreateVenue(providerId);

            var venue = await CosmosDbQueryDispatcher.Object.ExecuteQuery(new GetVenueById()
            {
                VenueId = venueId
            });

            var apprenticeshipId = await TestData.CreateApprenticeship(providerId,
                                                                       framework,
                                                                       createdBy : user,
                                                                       contactEmail : contactEmail,
                                                                       contactTelephone : contactTelephone,
                                                                       contactWebsite : contactWebsite,
                                                                       marketingInformation : marketingInfo,
                                                                       website : website,
                                                                       locations : new[]
            {
                CreateApprenticeshipLocation.CreateNational(),
                CreateApprenticeshipLocation.CreateFromVenue(
                    venue,
                    radius,
                    new[] { deliveryMode })
            });

            var standardsAndFrameworksCache = new StandardsAndFrameworksCache(CosmosDbQueryDispatcher.Object);

            var submissionId = await TestData.CreateApprenticeshipQASubmission(
                providerId,
                submittedOn : Clock.UtcNow,
                submittedByUserId : providerUserId,
                providerMarketingInformation : "The overview",
                apprenticeshipIds : new[] { apprenticeshipId });

            await WithSqlQueryDispatcher(async dispatcher =>
            {
                var initializer = new FlowModelInitializer(CosmosDbQueryDispatcher.Object, dispatcher, standardsAndFrameworksCache);

                // Act
                var model = await initializer.Initialize(providerId);

                // Assert
                Assert.True(model.GotApprenticeshipDetails);
                Assert.Equal(contactEmail, model.ApprenticeshipContactEmail);
                Assert.Equal(contactTelephone, model.ApprenticeshipContactTelephone);
                Assert.Equal(contactWebsite, model.ApprenticeshipContactWebsite);
                Assert.Equal(apprenticeshipId, model.ApprenticeshipId);
                Assert.True(model.ApprenticeshipIsNational);
                Assert.Equal(ApprenticeshipLocationType.ClassroomBasedAndEmployerBased, model.ApprenticeshipLocationType);
                Assert.Equal(marketingInfo, model.ApprenticeshipMarketingInformation);
                Assert.Collection(
                    model.ApprenticeshipClassroomLocations.Values,
                    location =>
                {
                    Assert.Equal(venueId, location.VenueId);
                    Assert.Equal(radius, location.Radius);
                    Assert.Contains(deliveryMode, location.DeliveryModes);
                });
                Assert.Equal(website, model.ApprenticeshipWebsite);
                Assert.True(model.ApprenticeshipStandardOrFramework.IsFramework);
                Assert.False(model.ApprenticeshipStandardOrFramework.IsStandard);
            });
        }