public void TimeSeriesId_ToArrayWith1StringKey() { // Arrange var key1 = "B17"; var tsiId = new TimeSeriesId(key1); // Act var idAsArray = tsiId.ToArray(); // Assert idAsArray.Should().Equal(new string[] { key1 }); }
public void TimeSeriesId_ToArrayWith3StringKeys() { // Arrange var key1 = "B17"; var key2 = "F1"; var key3 = "R1"; var tsiId = new TimeSeriesId(key1, key2, key3); // Act var idAsArray = tsiId.ToArray(); // Assert idAsArray.Should().Equal(new string[] { key1, key2, key3 }); }
private static IDictionary <string, object> BuildMessageBase(TimeSeriesIdProperty[] timeSeriesIdProperties, TimeSeriesId tsiId) { var messageBase = new Dictionary <string, object>(); string[] tsiIdArray = tsiId.ToArray(); for (int i = 0; i < timeSeriesIdProperties.Count(); i++) { TimeSeriesIdProperty idProperty = timeSeriesIdProperties[i]; string tsiIdValue = tsiIdArray[i]; messageBase[idProperty.Name] = tsiIdValue; } return(messageBase); }
public async Task TimeSeriesInsightsInstances_Lifecycle() { // Arrange TimeSeriesInsightsClient client = GetClient(); int numOfIdProperties = 3; int numOfInstancesToSetup = 2; var timeSeriesInstances = new List <TimeSeriesInstance>(); string defaultTypeId = await getDefaultTypeIdAsync(client).ConfigureAwait(false); for (int i = 0; i < numOfInstancesToSetup; i++) { TimeSeriesId id = await GetUniqueTimeSeriesInstanceIdAsync(client, numOfIdProperties) .ConfigureAwait(false); var instance = new TimeSeriesInstance(id, defaultTypeId) { Name = Recording.GenerateAlphaNumericId("instance"), }; timeSeriesInstances.Add(instance); } IEnumerable <TimeSeriesId> timeSeriesInstancesIds = timeSeriesInstances.Select((instance) => instance.TimeSeriesId); // Act and assert try { await TestRetryHelper.RetryAsync <Response <InstancesOperationResult[]> >(async() => { // Create TSI instances Response <TimeSeriesOperationError[]> createInstancesResult = await client .Instances .CreateOrReplaceAsync(timeSeriesInstances) .ConfigureAwait(false); // Assert that the result error array does not contain any object that is set createInstancesResult.Value.Should().OnlyContain((errorResult) => errorResult == null); // Get the created instances by Ids Response <InstancesOperationResult[]> getInstancesByIdsResult = await client .Instances .GetAsync(timeSeriesInstancesIds) .ConfigureAwait(false); getInstancesByIdsResult.Value.Length.Should().Be(timeSeriesInstances.Count); foreach (InstancesOperationResult instanceResult in getInstancesByIdsResult.Value) { instanceResult.Instance.Should().NotBeNull(); instanceResult.Error.Should().BeNull(); instanceResult.Instance.TimeSeriesId.ToArray().Length.Should().Be(numOfIdProperties); instanceResult.Instance.TypeId.Should().Be(defaultTypeId); instanceResult.Instance.HierarchyIds.Count.Should().Be(0); instanceResult.Instance.InstanceFields.Count.Should().Be(0); } return(null); }, MaxNumberOfRetries, s_retryDelay); // Update the instances by adding descriptions to them timeSeriesInstances.ForEach((timeSeriesInstance) => timeSeriesInstance.Description = "Description"); Response <InstancesOperationResult[]> replaceInstancesResult = await client .Instances .ReplaceAsync(timeSeriesInstances) .ConfigureAwait(false); replaceInstancesResult.Value.Length.Should().Be(timeSeriesInstances.Count); replaceInstancesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error == null); // This retry logic was added as the TSI instance are not immediately available after creation await TestRetryHelper.RetryAsync <Response <InstancesOperationResult[]> >(async() => { // Get instances by name Response <InstancesOperationResult[]> getInstancesByNameResult = await client .Instances .GetAsync(timeSeriesInstances.Select((instance) => instance.Name)) .ConfigureAwait(false); getInstancesByNameResult.Value.Length.Should().Be(timeSeriesInstances.Count); foreach (InstancesOperationResult instanceResult in getInstancesByNameResult.Value) { instanceResult.Instance.Should().NotBeNull(); instanceResult.Error.Should().BeNull(); instanceResult.Instance.TimeSeriesId.ToArray().Length.Should().Be(numOfIdProperties); instanceResult.Instance.TypeId.Should().Be(defaultTypeId); instanceResult.Instance.HierarchyIds.Count.Should().Be(0); instanceResult.Instance.InstanceFields.Count.Should().Be(0); } return(null); }, MaxNumberOfRetries, s_retryDelay); // Get all Time Series instances in the environment AsyncPageable <TimeSeriesInstance> getAllInstancesResponse = client.Instances.GetAsync(); int numOfInstances = 0; await foreach (TimeSeriesInstance tsiInstance in getAllInstancesResponse) { numOfInstances++; tsiInstance.Should().NotBeNull(); } numOfInstances.Should().BeGreaterOrEqualTo(numOfInstancesToSetup); // Get search suggestions for the first instance TimeSeriesId timeSeriesIdToSuggest = timeSeriesInstances.First().TimeSeriesId; string suggestionString = timeSeriesIdToSuggest.ToArray().First(); Response <SearchSuggestion[]> searchSuggestionResponse = await TestRetryHelper.RetryAsync(async() => { Response <SearchSuggestion[]> searchSuggestions = await client .Instances .GetSearchSuggestionsAsync(suggestionString) .ConfigureAwait(false); if (searchSuggestions.Value.Length == 0) { throw new Exception($"Unable to find a search suggestion for string {suggestionString}."); } return(searchSuggestions); }, MaxNumberOfRetries, s_retryDelay); searchSuggestionResponse.Value.Length.Should().Be(1); } finally { // clean up try { Response <TimeSeriesOperationError[]> deleteInstancesResponse = await client .Instances .DeleteAsync(timeSeriesInstancesIds) .ConfigureAwait(false); // Assert that the response array does not have any error object set deleteInstancesResponse.Value.Should().OnlyContain((errorResult) => errorResult == null); } catch (Exception ex) { Console.WriteLine($"Test clean up failed: {ex.Message}"); throw; } } }