예제 #1
0
        private static async Task TestTimeSeriesTypeWhereErrorIsExpected(TimeSeriesInsightsTypes typesClient, List <TimeSeriesType> timeSeriesTypes, string timeSeriesTypesName)
        {
            // create numeric type and expect failure due to invalid input expression
            Response <TimeSeriesTypeOperationResult[]> createTypesResult = await typesClient
                                                                           .CreateOrReplaceAsync(timeSeriesTypes)
                                                                           .ConfigureAwait(false);

            // Assert that the result error array does not contain an error
            createTypesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error != null);

            // Get the type by name and expect error
            Response <TimeSeriesTypeOperationResult[]> getTypesByNamesResult = await typesClient
                                                                               .GetByNameAsync(new string[] { timeSeriesTypesName })
                                                                               .ConfigureAwait(false);

            getTypesByNamesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error != null);

            // Delete the type by name and expect error
            Response <TimeSeriesOperationError[]> deleteTypesResponse = await typesClient
                                                                        .DeleteByNameAsync(new string[] { timeSeriesTypesName })
                                                                        .ConfigureAwait(false);

            // Response is null even when type does not exist.
            deleteTypesResponse.Value.Should().OnlyContain((errorResult) => errorResult == null);
        }
예제 #2
0
        public async Task TimeSeriesInsightsTypes_Lifecycle()
        {
            // Arrange
            TimeSeriesInsightsClient client      = GetClient();
            TimeSeriesInsightsTypes  typesClient = client.GetTypesClient();
            var timeSeriesTypes           = new List <TimeSeriesType>();
            var tsiTypeNamePrefix         = "type";
            int numOfTypesCreated         = 0;
            var timeSeriesTypesProperties = new Dictionary <string, string>
            {
                { Recording.GenerateAlphaNumericId(tsiTypeNamePrefix), Recording.GenerateId() },
                { Recording.GenerateAlphaNumericId(tsiTypeNamePrefix), Recording.GenerateId() }
            };

            // Build aggregate variable
            var countExpression    = new TimeSeriesExpression("count()");
            var aggregateVariable  = new AggregateVariable(countExpression);
            var variables          = new Dictionary <string, TimeSeriesVariable>();
            var variableNamePrefix = "aggregateVariable";

            variables.Add(Recording.GenerateAlphaNumericId(variableNamePrefix), aggregateVariable);

            foreach (KeyValuePair <string, string> property in timeSeriesTypesProperties)
            {
                var type = new TimeSeriesType(property.Key, variables)
                {
                    Id = property.Value
                };
                timeSeriesTypes.Add(type);
                numOfTypesCreated++;
            }

            // Act and assert
            try
            {
                // Get all Time Series types in the environment
                AsyncPageable <TimeSeriesType> getAllTypesResponse = typesClient.GetTypesAsync();

                await foreach (TimeSeriesType tsiType in getAllTypesResponse)
                {
                    tsiType.Should().NotBeNull();
                }

                // Create Time Series types
                Response <TimeSeriesTypeOperationResult[]> createTypesResult = await typesClient
                                                                               .CreateOrReplaceAsync(timeSeriesTypes)
                                                                               .ConfigureAwait(false);

                // Assert that the result error array does not contain any object that is set
                createTypesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error == null);
                Response <TimeSeriesTypeOperationResult[]> getTypesByNamesResult;

                // This retry logic was added as the TSI types are not immediately available after creation
                await TestRetryHelper.RetryAsync <Response <TimeSeriesTypeOperationResult[]> >(async() =>
                {
                    // Get the created types by names
                    getTypesByNamesResult = await typesClient
                                            .GetByNameAsync(timeSeriesTypesProperties.Keys)
                                            .ConfigureAwait(false);

                    getTypesByNamesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error == null);
                    getTypesByNamesResult.Value.Length.Should().Be(timeSeriesTypes.Count);
                    foreach (TimeSeriesTypeOperationResult typesResult in getTypesByNamesResult.Value)
                    {
                        typesResult.Error.Should().BeNull();
                        typesResult.TimeSeriesType.Should().NotBeNull();
                        typesResult.TimeSeriesType.Id.Should().NotBeNullOrEmpty();
                        typesResult.TimeSeriesType.Variables.Count.Should().Be(1);
                        typesResult.TimeSeriesType.Variables.IsSameOrEqualTo(variables);
                    }
                    return(null);
                }, MaxNumberOfRetries, s_retryDelay);

                // Update variables with adding a new variable
                foreach (TimeSeriesType type in timeSeriesTypes)
                {
                    type.Description = "Description";
                }

                Response <TimeSeriesTypeOperationResult[]> updateTypesResult = await typesClient
                                                                               .CreateOrReplaceAsync(timeSeriesTypes)
                                                                               .ConfigureAwait(false);

                updateTypesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error == null);
                updateTypesResult.Value.Length.Should().Be(timeSeriesTypes.Count);

                // This retry logic was added as the TSI types are not immediately available after creation
                await TestRetryHelper.RetryAsync <Response <TimeSeriesTypeOperationResult[]> >(async() =>
                {
                    // Get type by Id
                    Response <TimeSeriesTypeOperationResult[]> getTypeByIdResult = await typesClient
                                                                                   .GetByIdAsync(timeSeriesTypesProperties.Values)
                                                                                   .ConfigureAwait(false);

                    getTypeByIdResult.Value.Length.Should().Be(numOfTypesCreated);
                    foreach (TimeSeriesTypeOperationResult typeOperationResult in getTypeByIdResult.Value)
                    {
                        typeOperationResult.TimeSeriesType.Should().NotBeNull();
                        typeOperationResult.Error.Should().BeNull();
                        typeOperationResult.TimeSeriesType.Name.Should().StartWith(tsiTypeNamePrefix);
                        typeOperationResult.TimeSeriesType.Id.Should().NotBeNull();
                    }

                    return(null);
                }, MaxNumberOfRetries, s_retryDelay);
            }
            finally
            {
                // clean up
                try
                {
                    Response <TimeSeriesOperationError[]> deleteTypesResponse = await typesClient
                                                                                .DeleteByIdAsync(timeSeriesTypesProperties.Values)
                                                                                .ConfigureAwait(false);

                    // Assert that the response array does not have any error object set
                    deleteTypesResponse.Value.Should().OnlyContain((errorResult) => errorResult == null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Test clean up failed: {ex.Message}");
                    throw;
                }
            }
        }