|
| 1 | +// Copyright 2020 New Relic, Inc. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | + |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using MultiFunctionApplicationHelpers; |
| 8 | +using NewRelic.Agent.IntegrationTestHelpers; |
| 9 | +using NewRelic.Agent.IntegrationTestHelpers.Models; |
| 10 | +using NewRelic.Testing.Assertions; |
| 11 | +using Xunit; |
| 12 | +using Xunit.Abstractions; |
| 13 | + |
| 14 | +namespace NewRelic.Agent.IntegrationTests.Api |
| 15 | +{ |
| 16 | + public abstract class TransactionNameTests<TFixture> : NewRelicIntegrationTest<TFixture> where TFixture : ConsoleDynamicMethodFixture |
| 17 | + { |
| 18 | + protected readonly TFixture Fixture; |
| 19 | + |
| 20 | + public TransactionNameTests(TFixture fixture, ITestOutputHelper output) : base(fixture) |
| 21 | + { |
| 22 | + Fixture = fixture; |
| 23 | + Fixture.TestLogger = output; |
| 24 | + |
| 25 | + Fixture.AddCommand("ApiCalls TestSetTransactionName TestGroup OriginalName,NewName"); |
| 26 | + |
| 27 | + Fixture.Actions |
| 28 | + ( |
| 29 | + setupConfiguration: () => |
| 30 | + { |
| 31 | + var configModifier = new NewRelicConfigModifier(Fixture.DestinationNewRelicConfigFilePath); |
| 32 | + configModifier.SetOrDeleteDistributedTraceEnabled(true); |
| 33 | + configModifier.SetLogLevel("finest"); |
| 34 | + } |
| 35 | + ); |
| 36 | + |
| 37 | + Fixture.Initialize(); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void TestSetTransactionName() |
| 42 | + { |
| 43 | + var setNameLines = Fixture.AgentLog.TryGetLogLines(AgentLogBase.TransactionLinePrefix + "Setting transaction name to.*?"); |
| 44 | + Assert.Equal(2, setNameLines.Count()); |
| 45 | + |
| 46 | + Assert.NotNull(Fixture.AgentLog.TryGetTransactionEvent("OtherTransaction/TestGroup/NewName")); |
| 47 | + Assert.Null(Fixture.AgentLog.TryGetTransactionEvent("OtherTransaction/TestGroup/OriginalName")); |
| 48 | + |
| 49 | + // Note the trailing space is necessary here, or we'll find "Ignoring transaction_segment_term with invalid prefix" which is unrelated |
| 50 | + var notConnectedLogLine = Fixture.AgentLog.TryGetLogLine(AgentLogBase.TransactionLinePrefix + "Ignoring transaction name "); |
| 51 | + Assert.Null(notConnectedLogLine); |
| 52 | + |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + [NetFrameworkTest] |
| 57 | + public class TransactionNameTestsFW : TransactionNameTests<ConsoleDynamicMethodFixtureFWLatest> |
| 58 | + { |
| 59 | + public TransactionNameTestsFW(ConsoleDynamicMethodFixtureFWLatest fixture, ITestOutputHelper output) |
| 60 | + : base(fixture, output) |
| 61 | + { |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + [NetCoreTest] |
| 66 | + public class TransactionNameTestsCore : TransactionNameTests<ConsoleDynamicMethodFixtureCoreLatest> |
| 67 | + { |
| 68 | + public TransactionNameTestsCore(ConsoleDynamicMethodFixtureCoreLatest fixture, ITestOutputHelper output) |
| 69 | + : base(fixture, output) |
| 70 | + { |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments