Beispiel #1
0
        private async Task <IEnumerable <TrainingDetail> > InternalGetFrameworkDetailsAsync()
        {
            using (var client = new FrameworkApiClient(DasApiBaseUrl))
            {
                try
                {
                    _logger.Info("Querying Apprenticeship API for Frameworks");
                    var frameworks = await client.GetAllAsync().ConfigureAwait(false);

                    var frameworkSummaries = frameworks as IList <FrameworkSummary> ?? frameworks.ToList();
                    _logger.Info($"Apprenticeship API returned {frameworkSummaries.Count} Frameworks");
                    return(frameworkSummaries.Select(framework =>
                                                     new TrainingDetail()
                    {
                        TrainingCode = framework.Id,
                        EffectiveTo = framework.EffectiveTo,
                        Level = framework.Level
                    }));
                }
                catch (Exception ex)
                {
                    throw new InfrastructureException(ex);
                }
            }
        }
        public void ShouldSeeAFrameworkIsMissing()
        {
            //Arrange
            const string frameworkId = "1-2-3";

            MockProviderService
            .UponReceiving($"a request to retrieve framework with id '{frameworkId}'")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = $"/frameworks/{frameworkId}",
                Headers = new Dictionary <string, string>
                {
                    { "Accept", "application/json" }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status = 404
            });

            var consumer = new FrameworkApiClient(MockProviderServiceBaseUri);

            //Act
            Assert.Throws <EntityNotFoundException>(() => consumer.Get(frameworkId));

            MockProviderService.VerifyInteractions();
        }
Beispiel #3
0
        public async Task <FrameworksView> GetFrameworksAsync(bool refreshCache = false)
        {
            if (!await _cache.ExistsAsync(FrameworksKey) || refreshCache)
            {
                var api = new FrameworkApiClient(_configuration.BaseUrl);

                var frameworks = api.FindAll().OrderBy(x => x.Title).ToList();

                await _cache.SetCustomValueAsync(FrameworksKey, MapFrom(frameworks));
            }

            return(await _cache.GetCustomValueAsync <FrameworksView>(FrameworksKey));
        }
Beispiel #4
0
        public Task <FrameworksView> GetFrameworksAsync(bool refreshCache = false)
        {
            if (!_cache.Exists(FrameworksKey) || refreshCache)
            {
                var api = new FrameworkApiClient(_apprenticeshipInfoServiceApiBase);

                //BUG: FindAll should be FindAllAsync
                var frameworks = api.FindAll().OrderBy(x => x.Title).ToList();

                _cache.Set(FrameworksKey, MapFrom(frameworks));
            }

            return(Task.FromResult(_cache.Get <FrameworksView>(FrameworksKey)));
        }
        public void ShouldGetFramework()
        {
            //Arrange
            const string frameworkId = "403-2-1";

            MockProviderService
            .UponReceiving($"a request to retrieve framework with id '{frameworkId}'")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = $"/frameworks/{frameworkId}",
                Headers = new Dictionary <string, string>
                {
                    { "Accept", "application/json" }
                }
            })
            .WillRespondWith(new ProviderServiceResponse
            {
                Status  = 200,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", "application/json; charset=utf-8" }
                },
                Body = new
                {
                    FrameworkId = frameworkId
                }
            });

            var consumer = new FrameworkApiClient(MockProviderServiceBaseUri);

            //Act
            var result = consumer.Get(frameworkId); // TODO is this needed?

            //Assert
            Assert.AreEqual(frameworkId, result.FrameworkId);

            MockProviderService.VerifyInteractions();
        }