diff --git a/CHANGELOG.md b/CHANGELOG.md index 73a1e90..c633b69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_nothing changed yet_ +### Changed + +- Made things `virtual` for mocking purposes in other projects ## [v0.1.1] - 2025-10-24 diff --git a/src/FritzCallMonitor/CallMonitorClient.cs b/src/FritzCallMonitor/CallMonitorClient.cs index 15d0282..2e8437c 100644 --- a/src/FritzCallMonitor/CallMonitorClient.cs +++ b/src/FritzCallMonitor/CallMonitorClient.cs @@ -51,12 +51,12 @@ namespace AMWD.Net.Api.Fritz.CallMonitor /// /// The event provides details using the parameter. /// - public event EventHandler? OnEvent; + public virtual event EventHandler? OnEvent; /// /// Gets or sets a logger instance. /// - public ILogger? Logger + public virtual ILogger? Logger { get => _logger; set @@ -69,7 +69,7 @@ namespace AMWD.Net.Api.Fritz.CallMonitor /// /// Releases all resources used by the current instance of the . /// - public void Dispose() + public virtual void Dispose() { if (_isDisposed) return; diff --git a/test/FritzCallMonitor.Tests/CallMonitorClientTest.cs b/test/FritzCallMonitor.Tests/CallMonitorClientTest.cs index c1a328c..c9f747b 100644 --- a/test/FritzCallMonitor.Tests/CallMonitorClientTest.cs +++ b/test/FritzCallMonitor.Tests/CallMonitorClientTest.cs @@ -21,6 +21,7 @@ namespace FritzCallMonitor.Tests private const string HOST = "localhost"; private const int PORT = 1012; + private readonly DateTime NOW = new(2025, 8, 25, 20, 15, 30, DateTimeKind.Local); private string _dateOffset; @@ -34,7 +35,7 @@ namespace FritzCallMonitor.Tests [TestInitialize] public void Initialize() { - var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now); + var offset = TimeZoneInfo.Local.GetUtcOffset(NOW); _dateOffset = offset < TimeSpan.Zero ? "-" + offset.ToString("hh\\:mm") : "+" + offset.ToString("hh\\:mm"); @@ -43,7 +44,7 @@ namespace FritzCallMonitor.Tests _readAsyncResponses = new Queue<(int, byte[])>(); - _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes("25.08.25 20:15:30;RING;2;012345678901;9876543;SIP0;\r\n"))); + _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes($"{NOW:dd.MM.yy HH:mm:ss};RING;2;012345678901;9876543;SIP0;\r\n"))); _readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty())); } @@ -184,7 +185,7 @@ namespace FritzCallMonitor.Tests { // Arrange _readAsyncResponses.Clear(); - _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes("25.08.25 20:15:30;RING;"))); + _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes($"{NOW:dd.MM.yy HH:mm:ss};RING;"))); _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes("2;012345678901;9876543;SIP0;\n"))); _readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty())); @@ -227,7 +228,7 @@ namespace FritzCallMonitor.Tests { // Arrange _readAsyncResponses.Clear(); - _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes("25.08.25 20:15:30;RING;2;012345678901;9876543;SIP0;\n25.08.25 20:15:30"))); + _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes($"{NOW:dd.MM.yy HH:mm:ss};RING;2;012345678901;9876543;SIP0;\n{NOW:dd.MM.yy HH:mm:ss}"))); _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes(";RING;2;012345678901;9876543;SIP0;\r\n"))); _readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty())); @@ -259,7 +260,7 @@ namespace FritzCallMonitor.Tests { // Arrange _readAsyncResponses.Clear(); - _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes("25.08.25 20:15:30;TEST;2;012345678901;9876543;SIP0;\n25.08.25 20:15:30"))); + _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes($"{NOW:dd.MM.yy HH:mm:ss};TEST;2;012345678901;9876543;SIP0;\n{NOW:dd.MM.yy HH:mm:ss}"))); _readAsyncResponses.Enqueue((0, Encoding.UTF8.GetBytes(";RING;2;012345678901;9876543;SIP0;\r\n"))); _readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty())); diff --git a/test/FritzCallMonitor.Tests/CallMonitorEventArgsTest.cs b/test/FritzCallMonitor.Tests/CallMonitorEventArgsTest.cs index 22aa531..3714f76 100644 --- a/test/FritzCallMonitor.Tests/CallMonitorEventArgsTest.cs +++ b/test/FritzCallMonitor.Tests/CallMonitorEventArgsTest.cs @@ -8,10 +8,12 @@ namespace FritzCallMonitor.Tests { private string _dateOffset; + private readonly DateTime NOW = new(2025, 8, 25, 20, 15, 30, DateTimeKind.Local); + [TestInitialize] public void Initialize() { - var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now); + var offset = TimeZoneInfo.Local.GetUtcOffset(NOW); _dateOffset = offset < TimeSpan.Zero ? "-" + offset.ToString("hh\\:mm") : "+" + offset.ToString("hh\\:mm"); @@ -21,7 +23,7 @@ namespace FritzCallMonitor.Tests public void ShouldParseRingEvent() { // Arrange - string line = "25.08.25 20:15:30;RING;2;012345678901;9876543;SIP0;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};RING;2;012345678901;9876543;SIP0;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); @@ -37,7 +39,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldParseConnectEvent() { - string line = "25.08.25 20:15:30;CONNECT;1;3;012345678901;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};CONNECT;1;3;012345678901;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); @@ -53,7 +55,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldParseDisconnectEvent() { - string line = "25.08.25 20:15:30;DISCONNECT;2;42;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};DISCONNECT;2;42;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); @@ -69,7 +71,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldParseCallEvent() { - string line = "25.08.25 20:15:30;CALL;4;7;9876543;012345678901;SIP0;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};CALL;4;7;9876543;012345678901;SIP0;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); @@ -93,7 +95,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldReturnNullOnUnknownEventType() { - string line = "25.08.25 20:15:30;UNKNOWN;2;012345678901;9876543;SIP0;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};UNKNOWN;2;012345678901;9876543;SIP0;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNull(result); } @@ -101,7 +103,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldReturnNullOnInvalidConnectionId() { - string line = "25.08.25 20:15:30;RING;abc;012345678901;9876543;SIP0;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};RING;abc;012345678901;9876543;SIP0;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNull(result); } @@ -109,7 +111,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldHandleInvalidLinePortInConnect() { - string line = "25.08.25 20:15:30;CONNECT;1;abc;012345678901;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};CONNECT;1;abc;012345678901;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); Assert.IsNull(result.LinePort); @@ -118,7 +120,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldHandleInvalidLinePortInCall() { - string line = "25.08.25 20:15:30;CALL;4;abc;9876543;012345678901;SIP0;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};CALL;4;abc;9876543;012345678901;SIP0;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); Assert.IsNull(result.LinePort); @@ -127,7 +129,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldHandleInvalidDurationInDisconnect() { - string line = "25.08.25 20:15:30;DISCONNECT;2;abc;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};DISCONNECT;2;abc;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); Assert.IsNull(result.Duration); @@ -136,7 +138,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldReturnNullOnTooFewColumns() { - string line = "25.08.25 20:15:30;RING;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};RING;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNull(result); } @@ -144,7 +146,7 @@ namespace FritzCallMonitor.Tests [TestMethod] public void ShouldParseWithExtraColumns() { - string line = "25.08.25 20:15:30;RING;2;012345678901;9876543;SIP0;EXTRA;COLUMN;"; + string line = $"{NOW:dd.MM.yy HH:mm:ss};RING;2;012345678901;9876543;SIP0;EXTRA;COLUMN;"; var result = CallMonitorEventArgs.Parse(line); Assert.IsNotNull(result); Assert.AreEqual("012345678901", result.ExternalNumber);