Esempio n. 1
0
        public async Task <IReadOnlyList <DaxFormatterResponse> > FormatAsync(IEnumerable <string> expressions, CancellationToken cancellationToken = default)
        {
            var request  = DaxFormatterMultipleRequest.GetFrom(_application, _version, expressions);
            var response = await _formatter.FormatAsync(request, cancellationToken).ConfigureAwait(false);

            return(response);
        }
Esempio n. 2
0
        private static async Task FormatMultipleRequests()
        {
            var formatter = new DaxFormatterClient();

            var request = new DaxFormatterMultipleRequest
            {
                DatabaseName = "MyDatabaseName",
                ServerName   = "MyServerName",

                ListSeparator              = ',',
                DecimalSeparator           = '.',
                MaxLineLength              = DaxFormatterLineStyle.LongLine,
                SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,

                ServerMode     = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
                ServerType     = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
                ServerEdition  = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
                ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
            };

            request.Dax.AddRange(DaxMultipleExpressions);

            var responses = await formatter.FormatAsync(request);

            foreach (var response in responses)
            {
                Console.WriteLine(response.Formatted);
            }
        }
        private static JsonElement GetJsonProperty(DaxFormatterMultipleRequest request, string propertyName)
        {
            var json     = JsonSerializer.Serialize(request);
            var document = JsonDocument.Parse(json);
            var property = document.RootElement.GetProperty(propertyName);

            return(property);
        }
Esempio n. 4
0
        public async Task <IReadOnlyList <DaxFormatterResponse> > FormatAsync(DaxFormatterMultipleRequest request, CancellationToken cancellationToken = default)
        {
            request.CallerApp     = _application;
            request.CallerVersion = _version;

            var response = await _formatter.FormatAsync(request, cancellationToken).ConfigureAwait(false);

            return(response);
        }
        public void DaxFormatterMultipleRequest_SensitiveDatabaseNameIsProtected()
        {
            var expected = "6341a49658aeebdfbcc648aea92b6005b393d3f89205cf56166c5626c80b9863";

            var request = new DaxFormatterMultipleRequest()
            {
                DatabaseName = "MyDatabaseName1"
            };

            Assert.Equal(expected, request.DatabaseName);
        }
        public void DaxFormatterMultipleRequest_SensitiveServerNameIsProtected()
        {
            var expected = "f4139cb312e198bedebf0d71198c27db761f5c4cab73da7dd2faea2672d082af";

            var request = new DaxFormatterMultipleRequest()
            {
                ServerName = "MyServerName1"
            };

            Assert.Equal(expected, request.ServerName);
        }
Esempio n. 7
0
        public async Task DaxFormatterClient_FormatAsync_MultipleRequestFails(string expression, int repeat, int expectedErrorLine, int expectedErrorColumn)
        {
            var expressions = Enumerable.Repeat(expression, repeat);
            var request     = new DaxFormatterMultipleRequest();

            request.Dax.AddRange(expressions);

            var response = await _fixture.Client.FormatAsync(request);

            AssertMultipleFails(response, repeat, expectedErrorLine, expectedErrorColumn);
        }
Esempio n. 8
0
        public async Task DaxFormatterClient_FormatAsync_MultipleRequestSucceded(string expression, string expectedExpression, int repeat)
        {
            var expressions = Enumerable.Repeat(expression, repeat);
            var request     = new DaxFormatterMultipleRequest();

            request.Dax.AddRange(expressions);

            var response = await _fixture.Client.FormatAsync(request);

            AssertMultipleSucceded(response, expectedExpression, repeat);
        }
        public void DaxFormatterMultipleRequest_SkipSpaceAfterFunctionNameSerialization(DaxFormatterSpacingStyle spacingStyle, bool expectedSpacingStyle)
        {
            var request = new DaxFormatterMultipleRequest
            {
                SkipSpaceAfterFunctionName = spacingStyle
            };

            var property            = GetJsonProperty(request, nameof(DaxFormatterMultipleRequest.SkipSpaceAfterFunctionName));
            var currentSpacingStyle = property.GetBoolean();

            Assert.Equal(expectedSpacingStyle, currentSpacingStyle);
        }
        public void DaxFormatterMultipleRequest_MaxLineLengthSerialization(DaxFormatterLineStyle lineStyle, int expectedLineStyle)
        {
            var request = new DaxFormatterMultipleRequest
            {
                MaxLineLength = lineStyle
            };

            var property         = GetJsonProperty(request, nameof(DaxFormatterMultipleRequest.MaxLineLength));
            var currentLineStyle = property.GetInt32();

            Assert.Equal(expectedLineStyle, currentLineStyle);
        }
        public void DaxFormatterMultipleRequest_ServerTypeSerialization(ServerType serverType, string expectedServerType)
        {
            var request = new DaxFormatterMultipleRequest
            {
                ServerType = serverType
            };

            var property          = GetJsonProperty(request, nameof(DaxFormatterMultipleRequest.ServerType));
            var currentServerType = property.GetString();

            Assert.Equal(expectedServerType, currentServerType);
        }
Esempio n. 12
0
        public async Task <IReadOnlyList <DaxFormatterResponse> > FormatAsync(DaxFormatterMultipleRequest request, CancellationToken cancellationToken)
        {
            await _formatSemaphore.WaitAsync();

            try
            {
                var message = await FormatAsyncInternal(request, cancellationToken);

                var result = JsonSerializer.Deserialize <IReadOnlyList <DaxFormatterResponse> >(message, _serializerOptions);

                return(result);
            }
            finally
            {
                _formatSemaphore.Release();
            }
        }
        public void DaxFormatterMultipleRequest_DaxIsNotNull()
        {
            var request = new DaxFormatterMultipleRequest();

            Assert.NotNull(request.Dax);
        }