Skip to content

Commit bb88235

Browse files
committed
switch to datetime
1 parent 36b2ec0 commit bb88235

File tree

9 files changed

+24
-25
lines changed

9 files changed

+24
-25
lines changed

Packrat/Fennec.Tests/Integration/QueryConditionTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ private async Task SeedDatabase()
1313
var traceCollection = Database.GetCollection<SingleTrace>("singleTraces");
1414
var traces = new SingleTrace[]
1515
{
16-
new(DateTimeOffset.Now, DataProtocol.Udp, FlowProtocol.Ipfix, false,
16+
new(DateTime.Now, DataProtocol.Udp, FlowProtocol.Ipfix, false,
1717
new SingleTraceEndpoint(IPAddress.Parse("1.1.1.1"), 20),
1818
new SingleTraceEndpoint(IPAddress.Parse("1.1.1.2"), 30), 100, 20),
19-
new(DateTimeOffset.Now, DataProtocol.Tcp, FlowProtocol.Netflow9, true,
19+
new(DateTime.Now, DataProtocol.Tcp, FlowProtocol.Netflow9, true,
2020
new SingleTraceEndpoint(IPAddress.Parse("2.1.1.1"), 20),
2121
new SingleTraceEndpoint(IPAddress.Parse("2.1.1.2"), 30), 100, 20),
22-
new(DateTimeOffset.Now, DataProtocol.Tcp, FlowProtocol.Netflow5, false,
22+
new(DateTime.Now, DataProtocol.Tcp, FlowProtocol.Netflow5, false,
2323
new SingleTraceEndpoint(IPAddress.Parse("3.1.1.1"), 10),
2424
new SingleTraceEndpoint(IPAddress.Parse("3.1.1.2"), 50), 100, 20)
2525
};
@@ -40,7 +40,7 @@ public async Task FiltersByDuplicates()
4040
var service = new TraceRepository(Database, null!, null!);
4141

4242
// Act
43-
var traces = await service.AggregateTraces(conditions, DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
43+
var traces = await service.AggregateTraces(conditions, DateTime.MinValue, DateTime.MaxValue);
4444

4545
// Assert
4646
Assert.True(traces.Count == 2);
@@ -61,7 +61,7 @@ public async Task FiltersByPort()
6161
var service = new TraceRepository(Database, null!, null!);
6262

6363
// Act
64-
var traces = await service.AggregateTraces(conditions, DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
64+
var traces = await service.AggregateTraces(conditions, DateTime.MinValue, DateTime.MaxValue);
6565

6666
// Assert
6767
Assert.True(traces.Count == 1);
@@ -83,7 +83,7 @@ public async Task FiltersByDuplicateAndPort()
8383
var service = new TraceRepository(Database, null!, null!);
8484

8585
// Act
86-
var traces = await service.AggregateTraces(conditions, DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
86+
var traces = await service.AggregateTraces(conditions, DateTime.MinValue, DateTime.MaxValue);
8787

8888
// Assert
8989
Assert.True(traces.Count == 1);

Packrat/Fennec.Tests/Integration/TraceRepositoryTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TraceRepositoryTests : MongoDbFactory
2222
DataProtocol = DataProtocol.Tcp,
2323
FlowProtocol = FlowProtocol.Ipfix,
2424
Duplicate = false,
25-
Timestamp = DateTimeOffset.Now - TimeSpan.FromHours(1)
25+
Timestamp = DateTime.Now - TimeSpan.FromHours(1)
2626
},
2727

2828
new SingleTrace
@@ -34,7 +34,7 @@ public class TraceRepositoryTests : MongoDbFactory
3434
DataProtocol = DataProtocol.Tcp,
3535
FlowProtocol = FlowProtocol.Ipfix,
3636
Duplicate = false,
37-
Timestamp = DateTimeOffset.Now
37+
Timestamp = DateTime.Now
3838
}
3939
};
4040

@@ -53,7 +53,7 @@ public async Task CorrectlyAggregatesTraces()
5353

5454
// Act
5555
var traces = await service.AggregateTraces(
56-
new QueryConditions(), DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
56+
new QueryConditions(), DateTime.MinValue, DateTime.MaxValue);
5757

5858
// Assert
5959
Assert.True(traces.Count == 1);

Packrat/Fennec.Tests/Repositories/GraphRepositoryTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private static ITraceRepository GetMockTraceRepository(List<AggregateTrace> samp
1414
{
1515
var mockTraceRepository = Substitute.For<ITraceRepository>();
1616
mockTraceRepository
17-
.AggregateTraces(Arg.Any<QueryConditions>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>())
17+
.AggregateTraces(Arg.Any<QueryConditions>(), Arg.Any<DateTime>(), Arg.Any<DateTime>())
1818
.Returns(Task.FromResult(sampleTraces));
1919
return mockTraceRepository;
2020
}
@@ -23,8 +23,8 @@ private static ITraceRepository GetMockTraceRepository(List<AggregateTrace> samp
2323
public async Task GenerateGraph_WithEmptyLayout_ShouldProcessCorrectly()
2424
{
2525
// Arrange
26-
var from = DateTimeOffset.UtcNow.AddDays(-1);
27-
var to = DateTimeOffset.UtcNow;
26+
var from = DateTime.UtcNow.AddDays(-1);
27+
var to = DateTime.UtcNow;
2828
var emptyLayout = new Layout("") { Layers = new List<ILayer>() };
2929

3030
var sampleTraces = new List<AggregateTrace>
@@ -71,8 +71,8 @@ public async Task GenerateGraph_WithEmptyLayout_ShouldProcessCorrectly()
7171
public async Task GenerateGraph_WithEmptyLayout_ReturnsSame()
7272
{
7373
// Arrange
74-
var from = DateTimeOffset.UtcNow.AddDays(-1);
75-
var to = DateTimeOffset.UtcNow;
74+
var from = DateTime.UtcNow.AddDays(-1);
75+
var to = DateTime.UtcNow;
7676
var emptyLayout = new Layout("") { Layers = new List<ILayer>() };
7777

7878
var sampleTraces = new List<AggregateTrace>

Packrat/Fennec.Tests/Services/DuplicateFlaggingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Fennec.Tests.Services;
1111
public class DuplicateFlaggingTests
1212
{
1313
private static readonly TraceImportInfo ImportInfo = new(
14-
DateTimeOffset.Now, IPAddress.Parse("192.168.0.1"),
14+
DateTime.Now, IPAddress.Parse("192.168.0.1"),
1515
IPAddress.Parse("10.10.20.1"), 10,
1616
IPAddress.Parse("10.10.30.1"), 20,
1717
10, 10, DataProtocol.Tcp, FlowProtocol.Ipfix);

Packrat/Fennec/Controllers/GraphController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Fennec.Controllers;
1010

11-
public record GraphRequest(DateTimeOffset From, DateTimeOffset To, bool RemoveDisconnectedNodes = true);
11+
public record GraphRequest(DateTime From, DateTime To, bool RemoveDisconnectedNodes = true);
1212

1313
public record GraphStatistics(long TotalHostCount, long TotalByteCount, long TotalPacketCount, long TotalTraceCount);
1414

Packrat/Fennec/Database/Domain/SingleTrace.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private SingleTraceEndpoint()
5454
/// </summary>
5555
public class SingleTrace
5656
{
57-
public SingleTrace(DateTimeOffset timestamp, DataProtocol dataProtocol, FlowProtocol flowProtocol, bool duplicate,
57+
public SingleTrace(DateTime timestamp, DataProtocol dataProtocol, FlowProtocol flowProtocol, bool duplicate,
5858
SingleTraceEndpoint source,
5959
SingleTraceEndpoint destination, ulong byteCount, ulong packetCount)
6060
{
@@ -81,7 +81,7 @@ public SingleTrace()
8181
/// Time when this information was received.
8282
/// </summary>
8383
[BsonElement("timestamp")]
84-
public DateTimeOffset Timestamp { get; set; }
84+
public DateTime Timestamp { get; set; }
8585

8686
/// <summary>
8787
/// Information about the source of the communication between two devices.

Packrat/Fennec/Database/TraceRepository.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public interface ITraceRepository
2424
/// Aggregate all traces in the database by their source and destination <see cref="IPAddress" /> and port.
2525
/// </summary>
2626
/// <returns></returns>
27-
public Task<List<AggregateTrace>> AggregateTraces(QueryConditions conditions, DateTimeOffset start,
28-
DateTimeOffset end);
27+
public Task<List<AggregateTrace>> AggregateTraces(QueryConditions conditions, DateTime start,
28+
DateTime end);
2929
}
3030

3131
public record TraceImportInfo(
32-
DateTimeOffset ReadTime,
32+
DateTime ReadTime,
3333
IPAddress ExporterIp,
3434
IPAddress SrcIp,
3535
ushort SrcPort,
@@ -135,8 +135,7 @@ public async Task ImportTraceImportInfo(IEnumerable<TraceImportInfo> traceImport
135135
await Task.WhenAll(tasks);
136136
}
137137

138-
public async Task<List<AggregateTrace>> AggregateTraces(QueryConditions conditions, DateTimeOffset start,
139-
DateTimeOffset end)
138+
public async Task<List<AggregateTrace>> AggregateTraces(QueryConditions conditions, DateTime start, DateTime end)
140139
{
141140
var filter = BuildQueryConditions(conditions);
142141
return await _traces

Packrat/Fennec/Parsers/IpFixParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private TraceImportInfo CreateTraceImportInfo(dynamic record, UdpReceiveResult r
114114
{
115115
// TODO: change readTime to flow duration or include both maybe --> more info for frontend
116116
var properties = (IDictionary<string, object>)record;
117-
var readTime = DateTimeOffset.UtcNow; // TODO: handle flows with ex. 2 packets total duration 0.000000000 ms
117+
var readTime = DateTime.UtcNow; // TODO: handle flows with ex. 2 packets total duration 0.000000000 ms
118118
var exporterIp = result.RemoteEndPoint.Address;
119119

120120
// Yes! These double casts are necessary. Don't ask me why.

Packrat/Fennec/Parsers/NetFlow9Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private IEnumerable<TraceImportInfo> CreateTraceImportInfoList(NetflowView view,
112112
private TraceImportInfo CreateTraceImportInfo(dynamic record, UdpReceiveResult result)
113113
{
114114
var properties = (IDictionary<string, object>)record;
115-
var readTime = DateTimeOffset.UtcNow;
115+
var readTime = DateTime.UtcNow;
116116
var exporterIp = result.RemoteEndPoint.Address;
117117

118118
var srcIp = properties.TryGetValue("IPv4SourceAddress", out var property)

0 commit comments

Comments
 (0)