Skip to content

Commit a001672

Browse files
committed
Unit test fixes
1 parent c2da07a commit a001672

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

tests/Agent/UnitTests/Core.UnitTest/Logging/LoggerTests.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ public void Error_Exception_CallsSerilogLoggerError()
157157
[Test]
158158
public void ErrorFormat_CallsSerilogLoggerError()
159159
{
160+
Mock.Arrange(() => _serilogLogger.IsEnabled(Arg.IsAny<LogEventLevel>())).Returns(true);
161+
160162
_logger.ErrorFormat(_testFormat, _testArgs);
161-
Mock.Assert(() => _serilogLogger.Error(Arg.AnyString), Occurs.Once());
163+
Mock.Assert(() => _serilogLogger.Error(Arg.AnyString, Arg.IsAny<object[]>()), Occurs.Once());
162164
}
163165

164166
// Warn methods
@@ -180,8 +182,10 @@ public void Warn_Exception_CallsSerilogLoggerWarning()
180182
[Test]
181183
public void WarnFormat_CallsSerilogLoggerWarning()
182184
{
185+
Mock.Arrange(() => _serilogLogger.IsEnabled(Arg.IsAny<LogEventLevel>())).Returns(true);
186+
183187
_logger.WarnFormat(_testFormat, _testArgs);
184-
Mock.Assert(() => _serilogLogger.Warning(Arg.AnyString), Occurs.Once());
188+
Mock.Assert(() => _serilogLogger.Warning(Arg.AnyString, Arg.IsAny<object[]>()), Occurs.Once());
185189
}
186190

187191
// Info methods
@@ -203,9 +207,10 @@ public void Info_Exception_CallsSerilogLoggerInformation()
203207
[Test]
204208
public void InfoFormat_CallsSerilogLoggerInformation()
205209
{
210+
Mock.Arrange(() => _serilogLogger.IsEnabled(Arg.IsAny<LogEventLevel>())).Returns(true);
206211

207212
_logger.InfoFormat(_testFormat, _testArgs);
208-
Mock.Assert(() => _serilogLogger.Information(Arg.AnyString), Occurs.Once());
213+
Mock.Assert(() => _serilogLogger.Information(Arg.AnyString, Arg.IsAny<object[]>()), Occurs.Once());
209214
}
210215

211216
// Debug methods
@@ -227,8 +232,10 @@ public void Debug_Exception_CallsSerilogLoggerDebug()
227232
[Test]
228233
public void DebugFormat_CallsSerilogLoggerDebug()
229234
{
235+
Mock.Arrange(() => _serilogLogger.IsEnabled(Arg.IsAny<LogEventLevel>())).Returns(true);
236+
230237
_logger.DebugFormat(_testFormat, _testArgs);
231-
Mock.Assert(() => _serilogLogger.Debug(Arg.AnyString), Occurs.Once());
238+
Mock.Assert(() => _serilogLogger.Debug(Arg.AnyString, Arg.IsAny<object[]>()), Occurs.Once());
232239
}
233240
[TearDown]
234241
public void TearDown()

tests/Agent/UnitTests/Core.UnitTest/NewRelic.Agent.Core.Config.FromLegacy/BootstrapConfigTest.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public void TestInvalidServiceAttribute()
2727
ConfigurationLoader.InitializeFromXml(bogusConfigXml, configSchemaSource);
2828

2929
var errorMessage = Type.GetType("Mono.Runtime") == null ?
30-
"An error occurred parsing newrelic.config - The 'bogus' attribute is not declared." :
31-
"An error occurred parsing newrelic.config - XmlSchema error: Attribute declaration was not found for bogus";
30+
"The 'bogus' attribute is not declared" :
31+
"XmlSchema error: Attribute declaration was not found for bogus";
3232
Assert.IsTrue(logging.HasMessageThatContains(errorMessage));
3333
}
3434
}
@@ -53,9 +53,7 @@ public void TestMissingOrEmptyConfigXsd()
5353

5454
// While this error message is somewhat cryptic, in an actual agent run it would be
5555
// preceeded by a warning message regarding failure to read the schema file contents from disk
56-
var errorMessage = Type.GetType("Mono.Runtime") == null ?
57-
"An error occurred parsing newrelic.config - Root element is missing." :
58-
"An error occurred parsing newrelic.config - Root element is missing.";
56+
var errorMessage = "Root element is missing";
5957
Assert.IsTrue(logging.HasMessageThatContains(errorMessage));
6058
}
6159
}

tests/Agent/UnitTests/Core.UnitTest/ThreadProfiling.FromLegacy/ThreadProfilingBucketTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void verify_UpdateTree_handles_null_StackInfo_argument()
6161
{
6262
ThreadProfilingBucket bucket = new ThreadProfilingBucket(new MockThreadProfilingService());
6363
bucket.UpdateTree(null);
64-
Assert.IsTrue(logging.HasMessageBeginingWith("fids passed to UpdateTree is null"));
64+
Assert.IsTrue(logging.HasMessageBeginningWith("fids passed to UpdateTree is null"));
6565
}
6666
}
6767

tests/Agent/UnitTests/Core.UnitTest/Wrapper/AgentWrapperApi/AgentWrapperApiTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void EndTransaction_ShouldNotLogResponseTimeAlreadyCaptured()
225225
{
226226
_agent.CurrentTransaction.End();
227227

228-
var foundResponseTimeAlreadyCapturedMessage = logging.HasMessageBeginingWith("Transaction has already captured the response time.");
228+
var foundResponseTimeAlreadyCapturedMessage = logging.HasMessageBeginningWith("Transaction has already captured the response time.");
229229
Assert.False(foundResponseTimeAlreadyCapturedMessage);
230230
}
231231
}

tests/Agent/UnitTests/NewRelic.Agent.TestUtilities/Logging.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Runtime.InteropServices;
87
using System.Text;
98
using NewRelic.Agent.Core.Logging;
109
using Serilog.Events;
@@ -66,7 +65,7 @@ public override string ToString()
6665
/// </summary>
6766
/// <param name="segment"></param>
6867
/// <returns></returns>
69-
public bool HasMessageBeginingWith(string segment) => _inMemorySink.LogEvents.Any(item => item.RenderMessage().StartsWith(segment));
68+
public bool HasMessageBeginningWith(string segment) => _inMemorySink.LogEvents.Any(item => item.RenderMessage().StartsWith(segment));
7069

7170
/// <summary>
7271
/// checks for messages that begins with a segment

0 commit comments

Comments
 (0)