Exemplo n.º 1
0
        public void CanSetServiceTimeout_Mocked()
        {
            string preferHeader = null;
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            // TimeSpan? networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
                //networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new Uri("https://api.loganalytics.io"), new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", TimeSpan.FromDays(1), options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            //Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
Exemplo n.º 2
0
        public void CanSetServiceTimeout_Mocked()
        {
            string   preferHeader    = null;
            TimeSpan?networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
        public async Task UsesDefaultEndpoint()
        {
            var mockTransport = MockTransport.FromMessageCallback(_ => new MockResponse(200).SetContent("{}"));

            var client = new MetricsQueryClient(new MockCredential(), new MetricsQueryClientOptions()
            {
                Transport = mockTransport
            });

            await client.QueryAsync("rid", new string[] {});

            StringAssert.StartsWith("https://management.azure.com", mockTransport.SingleRequest.Uri.ToString());
        }
        public async Task UsesDefaultAuthScope(string scope, string expectedScope)
        {
            var mockTransport = MockTransport.FromMessageCallback(_ => new MockResponse(200).SetContent("{}"));

            Mock <MockCredential> mock = new() { CallBase = true };

            string[] scopes = null;
            mock.Setup(m => m.GetTokenAsync(It.IsAny <TokenRequestContext>(), It.IsAny <CancellationToken>()))
            .Callback <TokenRequestContext, CancellationToken>((c, _) => scopes = c.Scopes)
            .CallBase();

            var client = new MetricsQueryClient(mock.Object, new MetricsQueryClientOptions()
            {
                Transport = mockTransport,
                Audience  = scope == null ? (MetricsQueryClientAudience?)null : new MetricsQueryClientAudience(scope)
            });

            await client.QueryAsync("", new string[] {});

            Assert.AreEqual(new[] { expectedScope }, scopes);
        }