public async Task ShouldGetSamples() { // Arrange var sampleName = "msgraph-training-aspnetmvcapp"; // Act var samples = await _repositoriesService.GetRepositories(Constants.Samples); var exampleSample = samples.Find((node) => node.Name.Equals(sampleName)); Assert.NotEmpty(samples); Assert.IsType <List <Node> >(samples); Assert.NotNull(exampleSample); }
public async Task <IActionResult> GetSamplesListAsync() { if (!_cache.TryGetValue(Constants.Samples, out var samples)) { samples = await _repositoriesService.GetRepositories(Constants.Samples); //Read timeout from config file var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromSeconds(_config.GetValue <double>(Constants.Timeout))); // Save data in cache. _cache.Set(Constants.Samples, samples, cacheEntryOptions); _logger.LogInformation("RepositoriesController :samples cache refreshed"); } return(Ok(samples)); }
public MainWindowViewModel() { _gitManager = new GitManager(); _repositoryService = new RepositoriesService(); _repositories = new ObservableCollection <Models.Repository>(_repositoryService.GetRepositories()); BrowseCommand = new RelayCommand(SelectPath); }
/// <summary> /// checks state of cache /// </summary> /// <returns>task</returns> private async Task CheckCacheForRepositories() { try { //cache samples list if the cache is empty if (!_cache.TryGetValue(Constants.Samples, out var samples)) { var stopWatch = Stopwatch.StartNew(); samples = await _repositoryService.GetRepositories(Constants.Samples); //Read timeout from config file var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromSeconds(_config.GetValue <double>(Constants.Timeout))); // Save data in cache. _cache.Set(Constants.Samples, samples, cacheEntryOptions); stopWatch.Stop(); _logger.LogInformation($"{nameof(RepositoryHostedService)} :samples cache refreshed in {stopWatch.Elapsed} milliseconds"); } //cache the list of sdks if they're not cached if (!_cache.TryGetValue(Constants.Sdks, out var sdkList)) { var stopWatch = Stopwatch.StartNew(); sdkList = await _repositoryService.GetRepositories(Constants.Sdks); //Read timeout from config file var cacheEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromSeconds(_config.GetValue <double>(Constants.Timeout))); // Save data in cache. _cache.Set(Constants.Sdks, sdkList, cacheEntryOptions); stopWatch.Stop(); _logger.LogInformation($"{nameof(RepositoryHostedService)} :sdks cache refreshed in {stopWatch.Elapsed} milliseconds"); } } catch (Exception ex) { _logger.LogCritical(ex, ex.Message); } }
/// <summary> /// Sets up HTTP methods mappings. /// </summary> /// <param name="service">Service handling requests</param> public RepositoriesModule(RepositoriesService service) : base("/") { Get["/api/program/{programId}/repositories"] = parameters => { var programId = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path); var xGwImsOrgId = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header); var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header); var xApiKey = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header); Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'GetRepositories'"); Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'GetRepositories'"); Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'GetRepositories'"); Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'GetRepositories'"); return(service.GetRepositories(Context, programId, xGwImsOrgId, authorization, xApiKey)); }; Get["/api/program/{programId}/repository/{repositoryId}"] = parameters => { var programId = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path); var repositoryId = Parameters.ValueOf <string>(parameters, Context.Request, "repositoryId", ParameterType.Path); var xGwImsOrgId = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header); var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header); var xApiKey = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header); Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'GetRepository'"); Preconditions.IsNotNull(repositoryId, "Required parameter: 'repositoryId' is missing at 'GetRepository'"); Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'GetRepository'"); Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'GetRepository'"); Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'GetRepository'"); return(service.GetRepository(Context, programId, repositoryId, xGwImsOrgId, authorization, xApiKey)); }; }