Exemple #1
0
        private async Task <IEnumerable <TrainingDetail> > InternalGetAllStandardDetailsAsync()
        {
            using (var client = new StandardApiClient(DasApiBaseUrl))
            {
                try
                {
                    _logger.Info("Querying Apprenticeship API for Standards");
                    var standards = await client.GetAllAsync().ConfigureAwait(false);

                    var standardSummaries = standards as IList <StandardSummary> ?? standards.ToList();
                    _logger.Info($"Apprenticeship API returned {standardSummaries.Count} Standards");
                    return(standardSummaries.Select(standard =>
                                                    new TrainingDetail()
                    {
                        TrainingCode = standard.Id,
                        EffectiveTo = standard.EffectiveTo,
                        Level = standard.Level,
                        Title = standard.Title,
                        Uri = standard.Uri
                    }));
                }
                catch (Exception ex)
                {
                    throw new InfrastructureException(ex);
                }
            }
        }
        public void ShouldSeeaStandardIsMissing()
        {
            //Arrange
            const string standardCode = "-1";

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

            var consumer = new StandardApiClient(MockProviderServiceBaseUri);

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

            MockProviderService.VerifyInteractions();
        }
Exemple #3
0
        public async Task <StandardsView> GetStandardsAsync(bool refreshCache = false)
        {
            if (!await _cache.ExistsAsync(StandardsKey) || refreshCache)
            {
                var api = new StandardApiClient(_configuration.BaseUrl);

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

                await _cache.SetCustomValueAsync(StandardsKey, MapFrom(standards));
            }

            return(await _cache.GetCustomValueAsync <StandardsView>(StandardsKey));
        }
Exemple #4
0
        public Task <StandardsView> GetStandardsAsync(bool refreshCache = false)
        {
            if (!_cache.Exists(StandardsKey) || refreshCache)
            {
                var api = new StandardApiClient(_apprenticeshipInfoServiceApiBase);

                //BUG: FindAll should be FindAllAsync - currently a blocking call.
                var standards = api.FindAll().OrderBy(x => x.Title).ToList();

                _cache.Set(StandardsKey, MapFrom(standards));
            }

            return(Task.FromResult(_cache.Get <StandardsView>(StandardsKey)));
        }
Exemple #5
0
        private async Task <Standard> InternalGetStandardDetailsAsync(int code)
        {
            using (var client = new StandardApiClient(DasApiBaseUrl))
            {
                try
                {
                    var standard = await client.GetAsync(code);

                    return(new Standard {
                        Code = code, Title = standard.Title, Uri = standard.Uri
                    });
                }
                catch (Exception ex)
                {
                    throw new InfrastructureException(ex);
                }
            }
        }
        public void ShouldGetaStandard()
        {
            //Arrange
            const string standardCode = "12";

            MockProviderService
            .UponReceiving($"a request to retrieve standard with id '{standardCode}'")
            .With(new ProviderServiceRequest
            {
                Method  = HttpVerb.Get,
                Path    = $"/standards/{standardCode}",
                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
                {
                    StandardId = standardCode
                }
            });

            var consumer = new StandardApiClient(MockProviderServiceBaseUri);

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

            //Assert
            Assert.AreEqual(standardCode, result.StandardId);

            MockProviderService.VerifyInteractions();
        }