Exemplo n.º 1
0
        public void TestResponseCreatedHandler(string headerName)
        {
            var    store    = new EventStore();
            var    provider = MockTelemetryProvider.Create(store) as MockTelemetryProvider;
            var    module   = new AzModule(new MockCommandRuntime(), store, provider);
            string id       = Guid.NewGuid().ToString();
            var    response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            response.Headers.Add(headerName, id);
            var request = new HttpRequestMessage {
                Method = HttpMethod.Get, RequestUri = new Uri("https://microsoft.azure.com/subscriptions")
            };

            request.Headers.Add(headerName, id);
            var data = new EventData {
                Id = Events.CmdletProcessRecordAsyncStart, RequestMessage = request, ResponseMessage = response
            };
            var signalEvents = new List <EventArgs>();

            // Create a QOS record
            module.OnProcessRecordAsyncStart(Events.CmdletProcessRecordAsyncStart, CancellationToken.None, () => data,
                                             (nid, token, getEventData) => ProcessSignal(signalEvents, nid, token, getEventData), id, null, "", id).GetAwaiter().GetResult();
            data.Id = Events.ResponseCreated;
            module.OnResponseCreated(Events.ResponseCreated, CancellationToken.None, () => data,
                                     (nid, token, getEventData) => ProcessSignal(signalEvents, nid, token, getEventData), id).GetAwaiter().GetResult();
            Assert.True(provider.ContainsKey(id));
            var qos = provider[id];

            Assert.NotNull(qos);
            Assert.Equal(id, qos.ClientRequestId);
            provider.Clear();
        }
Exemplo n.º 2
0
        public void TestExceptionHandler()
        {
            // setup
            var store        = new EventStore();
            var provider     = MockTelemetryProvider.Create(store) as MockTelemetryProvider;
            var module       = new AzModule(new MockCommandRuntime(), store, provider);
            var signalEvents = new List <EventArgs>();

            // No headers in response
            string id       = Guid.NewGuid().ToString();
            var    response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            var    request  = new HttpRequestMessage {
                Method = HttpMethod.Get, RequestUri = new Uri("https://microsoft.azure.com/subscriptions")
            };
            var data = new EventData {
                Id = Events.CmdletProcessRecordAsyncStart, RequestMessage = request, ResponseMessage = response
            };

            module.OnProcessRecordAsyncStart(Events.CmdletProcessRecordAsyncStart, CancellationToken.None, () => data,
                                             (nid, token, getEventData) => ProcessSignal(signalEvents, nid, token, getEventData), id, null, "", id).GetAwaiter().GetResult();
            data.Id = Events.CmdletException;
            module.OnCmdletException(Events.CmdletException, CancellationToken.None, () => data,
                                     (nid, token, getEventData) => ProcessSignal(signalEvents, nid, token, getEventData), id, new HttpRequestException("Sample exception")).GetAwaiter().GetResult();
            Assert.True(provider.ContainsKey(id));
            var qos = provider[id];

            Assert.NotNull(qos);
            Assert.NotNull(qos.Exception);
            Assert.Equal("Sample exception", qos.Exception.Message);
            Assert.False(qos.IsSuccess);
            provider.Clear();
        }