Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a6c3df5d17 | |||
| 452fe47969 | |||
| 8f71e4dbe4 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
_nothing changed yet_
|
_No changes_
|
||||||
|
|
||||||
|
|
||||||
|
## [v0.1.2] - 2025-11-08
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Public elements are now `virtual` to allow mocking in unit tests
|
||||||
|
|
||||||
|
|
||||||
## [v0.1.1] - 2025-10-24
|
## [v0.1.1] - 2025-10-24
|
||||||
@@ -36,7 +43,8 @@ _Inital release_
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Unreleased]: https://github.com/AM-WD/FritzCallMonitor/compare/v0.1.1...HEAD
|
[Unreleased]: https://github.com/AM-WD/FritzCallMonitor/compare/v0.1.2...HEAD
|
||||||
|
|
||||||
|
[v0.1.2]: https://github.com/AM-WD/FritzCallMonitor/compare/v0.1.1...v0.1.2
|
||||||
[v0.1.1]: https://github.com/AM-WD/FritzCallMonitor/compare/v0.1.0...v0.1.1
|
[v0.1.1]: https://github.com/AM-WD/FritzCallMonitor/compare/v0.1.0...v0.1.1
|
||||||
[v0.1.0]: https://github.com/AM-WD/FritzCallMonitor/commits/v0.1.0
|
[v0.1.0]: https://github.com/AM-WD/FritzCallMonitor/commits/v0.1.0
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ namespace AMWD.Net.Api.Fritz.CallMonitor
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The event provides details using the <see cref="CallMonitorEventArgs"/> parameter.
|
/// The event provides details using the <see cref="CallMonitorEventArgs"/> parameter.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public event EventHandler<CallMonitorEventArgs>? OnEvent;
|
public virtual event EventHandler<CallMonitorEventArgs>? OnEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a logger instance.
|
/// Gets or sets a logger instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ILogger? Logger
|
public virtual ILogger? Logger
|
||||||
{
|
{
|
||||||
get => _logger;
|
get => _logger;
|
||||||
set
|
set
|
||||||
@@ -69,7 +69,7 @@ namespace AMWD.Net.Api.Fritz.CallMonitor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Releases all resources used by the current instance of the <see cref="CallMonitorClient"/>.
|
/// Releases all resources used by the current instance of the <see cref="CallMonitorClient"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
if (_isDisposed)
|
if (_isDisposed)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ using (var client = new CallMonitorClient(host, port))
|
|||||||
switch (e.Event)
|
switch (e.Event)
|
||||||
{
|
{
|
||||||
case EventType.Ring:
|
case EventType.Ring:
|
||||||
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Incoming Call from {e.CallerNumber} to {e.CalleeNumber}");
|
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Incoming Call from {e.ExternalNumber} to {e.InternalNumber}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EventType.Connect:
|
case EventType.Connect:
|
||||||
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Call connected to {e.CallerNumber}");
|
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Call connected to {e.ExternalNumber}");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EventType.Disconnect:
|
case EventType.Disconnect:
|
||||||
@@ -31,7 +31,7 @@ using (var client = new CallMonitorClient(host, port))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EventType.Call:
|
case EventType.Call:
|
||||||
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Outgoing Call from {e.CalleeNumber} to {e.CallerNumber}");
|
Console.WriteLine($"{e.Timestamp:yyyy-MM-dd HH:mm:ss} | #{e.ConnectionId} | Outgoing Call from {e.InternalNumber} to {e.ExternalNumber}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
|
|
||||||
private const string HOST = "localhost";
|
private const string HOST = "localhost";
|
||||||
private const int PORT = 1012;
|
private const int PORT = 1012;
|
||||||
|
private readonly DateTime NOW = new(2025, 8, 25, 20, 15, 30, DateTimeKind.Local);
|
||||||
|
|
||||||
private string _dateOffset;
|
private string _dateOffset;
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
|
var offset = TimeZoneInfo.Local.GetUtcOffset(NOW);
|
||||||
_dateOffset = offset < TimeSpan.Zero
|
_dateOffset = offset < TimeSpan.Zero
|
||||||
? "-" + offset.ToString("hh\\:mm")
|
? "-" + offset.ToString("hh\\:mm")
|
||||||
: "+" + offset.ToString("hh\\:mm");
|
: "+" + offset.ToString("hh\\:mm");
|
||||||
@@ -43,7 +44,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
|
|
||||||
_readAsyncResponses = new Queue<(int, byte[])>();
|
_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<byte>()));
|
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +185,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_readAsyncResponses.Clear();
|
_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((0, Encoding.UTF8.GetBytes("2;012345678901;9876543;SIP0;\n")));
|
||||||
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
||||||
|
|
||||||
@@ -227,7 +228,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_readAsyncResponses.Clear();
|
_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((0, Encoding.UTF8.GetBytes(";RING;2;012345678901;9876543;SIP0;\r\n")));
|
||||||
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_readAsyncResponses.Clear();
|
_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((0, Encoding.UTF8.GetBytes(";RING;2;012345678901;9876543;SIP0;\r\n")));
|
||||||
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
_readAsyncResponses.Enqueue((Timeout.Infinite, Array.Empty<byte>()));
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ namespace FritzCallMonitor.Tests
|
|||||||
{
|
{
|
||||||
private string _dateOffset;
|
private string _dateOffset;
|
||||||
|
|
||||||
|
private readonly DateTime NOW = new(2025, 8, 25, 20, 15, 30, DateTimeKind.Local);
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
|
var offset = TimeZoneInfo.Local.GetUtcOffset(NOW);
|
||||||
_dateOffset = offset < TimeSpan.Zero
|
_dateOffset = offset < TimeSpan.Zero
|
||||||
? "-" + offset.ToString("hh\\:mm")
|
? "-" + offset.ToString("hh\\:mm")
|
||||||
: "+" + offset.ToString("hh\\:mm");
|
: "+" + offset.ToString("hh\\:mm");
|
||||||
@@ -21,7 +23,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
public void ShouldParseRingEvent()
|
public void ShouldParseRingEvent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
|
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
@@ -37,7 +39,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldParseConnectEvent()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
|
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
@@ -53,7 +55,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldParseDisconnectEvent()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
|
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
@@ -69,7 +71,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldParseCallEvent()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
|
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
@@ -93,7 +95,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldReturnNullOnUnknownEventType()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNull(result);
|
Assert.IsNull(result);
|
||||||
}
|
}
|
||||||
@@ -101,7 +103,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldReturnNullOnInvalidConnectionId()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNull(result);
|
Assert.IsNull(result);
|
||||||
}
|
}
|
||||||
@@ -109,7 +111,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldHandleInvalidLinePortInConnect()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
Assert.IsNull(result.LinePort);
|
Assert.IsNull(result.LinePort);
|
||||||
@@ -118,7 +120,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldHandleInvalidLinePortInCall()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
Assert.IsNull(result.LinePort);
|
Assert.IsNull(result.LinePort);
|
||||||
@@ -127,7 +129,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldHandleInvalidDurationInDisconnect()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
Assert.IsNull(result.Duration);
|
Assert.IsNull(result.Duration);
|
||||||
@@ -136,7 +138,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldReturnNullOnTooFewColumns()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNull(result);
|
Assert.IsNull(result);
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ namespace FritzCallMonitor.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void ShouldParseWithExtraColumns()
|
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);
|
var result = CallMonitorEventArgs.Parse(line);
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(result);
|
||||||
Assert.AreEqual("012345678901", result.ExternalNumber);
|
Assert.AreEqual("012345678901", result.ExternalNumber);
|
||||||
|
|||||||
Reference in New Issue
Block a user