|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.ObjectModel; |
| 6 | +using Microsoft.Azure.WebJobs.Script.Description; |
| 7 | +using Microsoft.Azure.WebJobs.Script.Diagnostics; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.Azure.WebJobs.Script.Tests |
| 11 | +{ |
| 12 | + public class FunctionInvokerBaseTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void LogInvocationMetrics_EmitsExpectedEvents() |
| 16 | + { |
| 17 | + var metrics = new TestMetricsLogger(); |
| 18 | + Collection<BindingMetadata> bindings = new Collection<BindingMetadata> |
| 19 | + { |
| 20 | + new BindingMetadata { Type = "httpTrigger" }, |
| 21 | + new BindingMetadata { Type = "blob", Direction = BindingDirection.In }, |
| 22 | + new BindingMetadata { Type = "blob", Direction = BindingDirection.Out }, |
| 23 | + new BindingMetadata { Type = "table", Direction = BindingDirection.In }, |
| 24 | + new BindingMetadata { Type = "table", Direction = BindingDirection.In } |
| 25 | + }; |
| 26 | + |
| 27 | + FunctionInvokerBase.LogInvocationMetrics(metrics, bindings); |
| 28 | + |
| 29 | + Assert.Equal(6, metrics.LoggedEvents.Count); |
| 30 | + Assert.Equal("function.invoke", metrics.LoggedEvents[0]); |
| 31 | + Assert.Equal("function.binding.httpTrigger", metrics.LoggedEvents[1]); |
| 32 | + Assert.Equal("function.binding.blob.In", metrics.LoggedEvents[2]); |
| 33 | + Assert.Equal("function.binding.blob.Out", metrics.LoggedEvents[3]); |
| 34 | + Assert.Equal("function.binding.table.In", metrics.LoggedEvents[4]); |
| 35 | + Assert.Equal("function.binding.table.In", metrics.LoggedEvents[5]); |
| 36 | + } |
| 37 | + |
| 38 | + private class TestMetricsLogger : IMetricsLogger |
| 39 | + { |
| 40 | + public TestMetricsLogger() |
| 41 | + { |
| 42 | + LoggedEvents = new Collection<string>(); |
| 43 | + } |
| 44 | + |
| 45 | + public Collection<string> LoggedEvents { get; } |
| 46 | + |
| 47 | + public void BeginEvent(MetricEvent metricEvent) |
| 48 | + { |
| 49 | + throw new NotImplementedException(); |
| 50 | + } |
| 51 | + |
| 52 | + public object BeginEvent(string eventName) |
| 53 | + { |
| 54 | + throw new NotImplementedException(); |
| 55 | + } |
| 56 | + |
| 57 | + public void EndEvent(object eventHandle) |
| 58 | + { |
| 59 | + throw new NotImplementedException(); |
| 60 | + } |
| 61 | + |
| 62 | + public void EndEvent(MetricEvent metricEvent) |
| 63 | + { |
| 64 | + throw new NotImplementedException(); |
| 65 | + } |
| 66 | + |
| 67 | + public void LogEvent(string eventName) |
| 68 | + { |
| 69 | + LoggedEvents.Add(eventName); |
| 70 | + } |
| 71 | + |
| 72 | + public void LogEvent(MetricEvent metricEvent) |
| 73 | + { |
| 74 | + throw new NotImplementedException(); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments