public void FilterChangeLogRecordsByWorkload() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var searchOptions = new ChangeLogSearchOptions(workload: "Compliance"); // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Compliance", item.WorkloadArea); Assert.Equal("eDiscovery", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.Target); }); }); }
public void FilterChangeLogRecordsByEndDateAndDaysRange() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var endDate = DateTime.Parse("2021-01-01"); var searchOptions = new ChangeLogSearchOptions(endDate: endDate, daysRange: 30); // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("dca6467b-d026-4316-8353-2c6c02598af3", item.Id); Assert.Equal("Reports", item.WorkloadArea); Assert.Equal("Identity and access reports", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("dca6467b-d026-4316-8353-2c6c02598af3", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("relyingPartyDetailedSummary,listing", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("relyingPartyDetailedSummary,listing", item.Target); }); }); }
public void UpdateCurrentItemsOnChangeLogsPropertySetter() { // Arrange & Act var changeLogRecords = new ChangeLogRecords { ChangeLogs = GetChangeLogRecords().ChangeLogs }; /* 1st Assert - CurrentItems should always be equal * to the current count of changelog items in list. */ Assert.Equal(8, changeLogRecords.CurrentItems); Assert.Equal(changeLogRecords.CurrentItems, changeLogRecords.ChangeLogs.Count()); /* Take only first two changelog items from list, * e.g. in a pagination scenario. */ changeLogRecords.ChangeLogs = changeLogRecords.ChangeLogs .Take(2) .ToList(); /* 2nd Assert - CurrentItems value should always change * with current count of changelog items in list. */ Assert.Equal(2, changeLogRecords.CurrentItems); Assert.Equal(changeLogRecords.CurrentItems, changeLogRecords.ChangeLogs.Count()); }
public async Task CorrectlySeedLocaleCachesOfChangeLogRecordsWhenMultipleRequestsSingleLocaleReceived() { /* Arrange & Act */ // Fetch en-US changelog records ChangeLogRecords englishChangeLogRecords1 = await FetchChangeLogRecordsAsync(new CultureInfo("en-US")); // Fetch es-ES changelog records ChangeLogRecords englishChangeLogRecords2 = await FetchChangeLogRecordsAsync(new CultureInfo("en")); // Fetch fr-FR changelog records ChangeLogRecords englishChangeLogRecords3 = await FetchChangeLogRecordsAsync(new CultureInfo("en-us")); /* Assert */ // records 1 Assert.Equal(525, englishChangeLogRecords1.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords1.ChangeLogs.FirstOrDefault().WorkloadArea); // records 2 Assert.Equal(525, englishChangeLogRecords2.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords2.ChangeLogs.FirstOrDefault().WorkloadArea); // records 3 Assert.Equal(525, englishChangeLogRecords3.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords3.ChangeLogs.FirstOrDefault().WorkloadArea); }
public async Task CorrectlySeedLocaleCachesOfChangeLogRecordsWhenMultipleRequestsMultipleLocaleReceived() { /* Arrange & Act */ // Fetch en-US changelog records ChangeLogRecords englishChangeLogRecords = await FetchChangeLogRecordsAsync(new CultureInfo("en-US")); // Fetch es-ES changelog records ChangeLogRecords espanolChangeLogRecords = await FetchChangeLogRecordsAsync(new CultureInfo("es")); // Fetch fr-FR changelog records ChangeLogRecords frenchChangeLogRecords = await FetchChangeLogRecordsAsync(new CultureInfo("fr-CA")); /* Assert */ // en-US Assert.Equal(525, englishChangeLogRecords.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords.ChangeLogs.FirstOrDefault().WorkloadArea); // es-ES Assert.Equal(495, espanolChangeLogRecords.ChangeLogs.Count()); Assert.Equal("Cumplimiento", espanolChangeLogRecords.ChangeLogs.FirstOrDefault().WorkloadArea); // fr-FR Assert.Equal(495, frenchChangeLogRecords.ChangeLogs.Count()); Assert.Equal("Conformité", frenchChangeLogRecords.ChangeLogs.FirstOrDefault().WorkloadArea); }
public async Task CorrectlySeedLocaleCachesOfChangeLogRecordsWhenMultipleRequestsSingleLocaleReceived() { // Arrange _changesStore = new ChangesStore(_configuration, _changesCache, _httpClientUtility); /* Act */ // Fetch en-US changelog records ChangeLogRecords englishChangeLogRecords1 = await _changesStore.FetchChangeLogRecordsAsync(new CultureInfo("en-US")); // Fetch es-ES changelog records ChangeLogRecords englishChangeLogRecords2 = await _changesStore.FetchChangeLogRecordsAsync(new CultureInfo("en")); // Fetch fr-FR changelog records ChangeLogRecords englishChangeLogRecords3 = await _changesStore.FetchChangeLogRecordsAsync(new CultureInfo("en-us")); /* Assert */ // records 1 Assert.Equal(525, englishChangeLogRecords1.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords1.ChangeLogs.FirstOrDefault().WorkloadArea); // records 2 Assert.Equal(525, englishChangeLogRecords2.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords2.ChangeLogs.FirstOrDefault().WorkloadArea); // records 3 Assert.Equal(525, englishChangeLogRecords3.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords3.ChangeLogs.FirstOrDefault().WorkloadArea); }
public void PaginateChangeLogRecordsFirstPage() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var searchOptions = new ChangeLogSearchOptions { Page = 1, PageLimit = 2 }; // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert -- fetch first two items from the changelog sample Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Compliance", item.WorkloadArea); Assert.Equal("eDiscovery", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.Target); }); }, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Extensions", item.WorkloadArea); Assert.Equal("Schema extensions", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("schema extensions,Microsoft Cloud for US Government.", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("schema extensions,Microsoft Cloud for US Government", item.Target); }); }); }
public void FilterChangeLogRecordsByDates() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var startDate = DateTime.Parse("2020-01-01"); var endDate = DateTime.Parse("2020-10-01"); var searchOptions = new ChangeLogSearchOptions(startDate: startDate, endDate: endDate); // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Compliance", item.WorkloadArea); Assert.Equal("eDiscovery", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("6a6c7aa0-4b67-4d07-9ebf-c2bc1bcef553", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("ediscoveryCase,reviewSet,reviewSetQuery", item.Target); }); }, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Extensions", item.WorkloadArea); Assert.Equal("Schema extensions", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("schema extensions,Microsoft Cloud for US Government.", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("schema extensions,Microsoft Cloud for US Government", item.Target); }); }); }
public async Task SetDefaultLocaleInFetchChangeLogRecords(string locale) { /* Arrange & Act */ // Fetch default changelog records ChangeLogRecords englishChangeLogRecords = await FetchChangeLogRecordsAsync(new CultureInfo(locale)); ChangeLogRecords englishChangeLogRecords1 = await FetchChangeLogRecordsAsync(null); // Assert - we have the English translation Assert.Equal(525, englishChangeLogRecords.ChangeLogs.Count()); Assert.Equal(525, englishChangeLogRecords1.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords.ChangeLogs.FirstOrDefault().WorkloadArea); Assert.Equal("Compliance", englishChangeLogRecords1.ChangeLogs.FirstOrDefault().WorkloadArea); }
/// <summary> /// Fetches <see cref="ChangeLogRecords"/> from a uri source or an in-memory cache. /// </summary> /// <param name="cultureInfo">The culture of the localized file to be retrieved.</param> /// <returns><see cref="ChangeLogRecords"/> containing entries of <see cref="ChangeLog"/>.</returns> public async Task <ChangeLogRecords> FetchChangeLogRecordsAsync(CultureInfo cultureInfo) { var locale = cultureInfo.GetSupportedLocaleVariant().ToLower(); // lowercased in line with source files // Fetch cached changelog records ChangeLogRecords changeLogRecords = await _changeLogCache.GetOrCreateAsync(locale, cacheEntry => { lock (_changesLock) { /* Check whether a previous thread already seeded an * instance of the localized changelog records during the lock. */ var lockedLocale = locale; var seededChangeLogRecords = _changeLogCache.Get <ChangeLogRecords>(lockedLocale); if (seededChangeLogRecords != null) { // Already seeded by another thread return(Task.FromResult(seededChangeLogRecords)); } // Set cache expiry cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(_defaultRefreshTimeInHours); // Construct the locale-specific relative uri var relativeUrl = string.Format(_changeLogRelativeUrl, lockedLocale); // Append to get the absolute uri var requestUri = _configuration[ChangesServiceConstants.ChangelogBaseUrlConfigPath] + relativeUrl; // Construct the http request message using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri); // Get the file contents from source var jsonFileContents = _httpClientUtility.ReadFromDocumentAsync(httpRequestMessage) .GetAwaiter().GetResult(); // Return the changelog records from the file contents return(Task.FromResult(ChangesService.DeserializeChangeLogRecords(jsonFileContents))); } }); return(changeLogRecords); }
public async Task SetDefaultLocaleInFetchChangeLogRecords(string locale) { // Arrange _changesStore = new ChangesStore(_configuration, _changesCache, _httpClientUtility); /* Act */ // Fetch default changelog records ChangeLogRecords englishChangeLogRecords = await _changesStore.FetchChangeLogRecordsAsync(new CultureInfo(locale)); ChangeLogRecords englishChangeLogRecords1 = await _changesStore.FetchChangeLogRecordsAsync(null); // Assert - we have the English translation Assert.Equal(525, englishChangeLogRecords.ChangeLogs.Count()); Assert.Equal(525, englishChangeLogRecords1.ChangeLogs.Count()); Assert.Equal("Compliance", englishChangeLogRecords.ChangeLogs.FirstOrDefault().WorkloadArea); Assert.Equal("Compliance", englishChangeLogRecords1.ChangeLogs.FirstOrDefault().WorkloadArea); }
public void UpdateTotalItemsOnChangeLogsPropertySetter() { // Arrange & Act var changeLogRecords = new ChangeLogRecords { ChangeLogs = GetChangeLogRecords().ChangeLogs }; // 1st Assert Assert.Equal(8, changeLogRecords.TotalItems); Assert.Equal(8, changeLogRecords.ChangeLogs.Count()); /* Take only first two changelog items from list, * e.g. in a pagination scenario. */ changeLogRecords.ChangeLogs = changeLogRecords.ChangeLogs .Take(2) .ToList(); // 2nd Assert - TotalItems value should not change Assert.Equal(8, changeLogRecords.TotalItems); Assert.Equal(2, changeLogRecords.ChangeLogs.Count()); }
public void PaginateChangeLogRecordsLastPage() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var searchOptions = new ChangeLogSearchOptions { Page = 2, PageLimit = 2 }; // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert -- fetch last item from the changelog sample Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("dca6467b-d026-4316-8353-2c6c02598af3", item.Id); Assert.Equal("Reports", item.WorkloadArea); Assert.Equal("Identity and access reports", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("dca6467b-d026-4316-8353-2c6c02598af3", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("relyingPartyDetailedSummary,listing", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("relyingPartyDetailedSummary,listing", item.Target); }); }); }
public void PaginateChangeLogRecordsMiddlePage() { // Arrange var changeLogRecords = new ChangeLogRecords { ChangeLogs = ChangeLogRecordsModelShould.GetChangeLogRecords().ChangeLogs }; var searchOptions = new ChangeLogSearchOptions { Page = 2, PageLimit = 1 }; // Act var changeLog = Services.ChangesService.FilterChangeLogRecords(changeLogRecords, searchOptions, _graphProxyConfigs); // Assert -- fetch middle item from the changelog sample Assert.NotNull(changeLog); Assert.Collection(changeLog.ChangeLogs, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Extensions", item.WorkloadArea); Assert.Equal("Schema extensions", item.SubArea); Assert.Collection(item.ChangeList, item => { Assert.Equal("2d94636a-2d78-44d6-8b08-ff2a9121214b", item.Id); Assert.Equal("Resource", item.ApiChange); Assert.Equal("schema extensions,Microsoft Cloud for US Government.", item.ChangedApiName); Assert.Equal("Addition", item.ChangeType); Assert.Equal("schema extensions,Microsoft Cloud for US Government", item.Target); }); }); }