static async Task Main(string[] args) { using (var serviceProvider = new ServiceCollection() .AddLogging(cfg => cfg.AddConsole()) .Configure <LoggerFilterOptions>(cfg => cfg.MinLevel = LogLevel.Debug) .BuildServiceProvider()) { var logger = serviceProvider.GetService <ILogger <Program> >(); try { var capFilePath = @".\DemoFiles\Demo.cap"; var(ok, nmf) = await NetMonFileFactory.TryParseNetMonFileAsync(capFilePath, CancellationToken.None, logger); if (ok) { nmf.FramePackets.ToList().ForEach(frame => Console.WriteLine($"{frame.Index} {frame.Header}, {frame.Data}")); } } catch (Exception ex) { logger.LogError(ex, "Ooops ..."); } } Console.WriteLine("Press any key to close..."); Console.ReadKey(); }
public async Task Should_parse_0_ADS_Write_Control_Request_Response_FramePackets() { var testFile = @".\TestData\Valid_Test_Data.cap"; var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.AreEqual(netMonFile.FramePackets.Where(packet => packet.Data.AmsHeader.IsRequest && packet.Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Write_Control).Count(), 0); Assert.AreEqual(netMonFile.FramePackets.Where(packet => packet.Data.AmsHeader.IsResponse && packet.Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Write_Control).Count(), 0); }
public async Task Should_throw_FileNotFoundException() { var testFile = @".\TestData\invalidFilePath.cap"; FileInfo fi = new FileInfo(testFile); await Assert.ThrowsExceptionAsync <FileNotFoundException>(() => NetMonFileFactory.ParseNetMonFileAsync(testFile, CancellationToken.None, null)); await Assert.ThrowsExceptionAsync <FileNotFoundException>(() => NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, null)); }
public async Task Should_parse_all_710_FramePackets() { var testFile = @".\TestData\Valid_Test_Data.cap"; var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.AreEqual(netMonFile.FramePackets.Count(), 710); netMonFile.FramePackets.ToList().ForEach(packet => Assert.IsTrue(packet.Data.AmsHeader.IsValid)); }
public async Task Should_parse_52_ADS_Device_Notification_RequestFramePackets() { var testFile = @".\TestData\Valid_Test_Data.cap"; var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.AreEqual(netMonFile.FramePackets.Where(packet => packet.Data.AmsHeader.IsRequest && packet.Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Device_Notification).Count(), 52); Assert.AreEqual(netMonFile.FramePackets.Where(packet => packet.Data.AmsHeader.IsResponse && packet.Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Device_Notification).Count(), 0); // there is no response! }
private void ParseNetMonFile(string path) { // we have to sync here var(ok, packets) = NetMonFileFactory.TryParseNetMonFileAsync(new FileInfo(path), CancellationToken.None, null).GetAwaiter().GetResult(); if (ok) { BehaviorList = ConvertToBehaviorList(packets); } }
public async Task Should_throw_ArgumentNullException() { string nullString = null; FileInfo fi = null; await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => NetMonFileFactory.ParseNetMonFileAsync(nullString, CancellationToken.None, null)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => NetMonFileFactory.ParseNetMonFileAsync(string.Empty, CancellationToken.None, null)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, null)); }
public async Task Should_log_invalid_Ams_Header_version_3_in_Cap_File() { var loggerMock = new Mock <ILogger <NetMonFile> >(); FileInfo fi = new FileInfo(@".\TestData\Invalid_Ams_Header_DataLength.cap"); var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, loggerMock.Object); var expectedException = new FormatException($"Parsed AmsHeader is not valid, Data_Length=255 not allowed."); Assert.IsNull(netMonFile); loggerMock.VerifyLoggingException($"[ParseCapFile] Error while parsing file \"{fi.Name}\".", expectedException); }
public async Task Should_log_invalid_Ams_Header_AmsCommandId_in_Cap_File() { var loggerMock = new Mock <ILogger <NetMonFile> >(); FileInfo fi = new FileInfo(@".\TestData\Invalid_Ams_Header_AmsCommandId.cap"); var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, loggerMock.Object); var expectedException = new Exception("Fatal Error, no valid constructor found."); Assert.IsNull(netMonFile); loggerMock.VerifyLoggingException($"[ParseCapFile] Error while parsing file \"{fi.Name}\".", expectedException); }
public async Task Should_log_invalid_Header_GMBU_in_Cap_File() { var loggerMock = new Mock <ILogger <NetMonFile> >(); FileInfo fi = new FileInfo(@".\TestData\Invalid_Header_GMBU.cap"); var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, loggerMock.Object); var expectedException = new FormatException($"Is not a valid NetMon 2.x file format."); Assert.IsNull(netMonFile); loggerMock.VerifyLoggingException($"[ParseCapFile] Error while parsing file \"{fi.Name}\".", expectedException); }
public async Task Should_add_one_ReadIndicationBehavior_to_BehaviorList_from_NetMonFile() { var capFilePath = @".\TestFiles\ReadRequestPort10k.cap"; var(ok, nmf) = await NetMonFileFactory.TryParseNetMonFileAsync(capFilePath, CancellationToken.None, null); Assert.IsTrue(ok); var rpe = new ReplayExtension(nmf); Assert.IsNotNull(rpe.BehaviorList); Assert.AreEqual(rpe.BehaviorList.Count(), 1); Assert.IsInstanceOfType(rpe.BehaviorList.First(), typeof(ReadIndicationBehavior)); }
public async Task Should_parse_two_FramePackets_ReadRequest_ReadResponse_from_FileInfo() { FileInfo fi = new FileInfo(@".\TestData\Valid_ReadRequest.cap"); var netMonFile = await NetMonFileFactory.ParseNetMonFileAsync(fi, CancellationToken.None, null); Assert.IsTrue(netMonFile.FramePackets.Count() == 2); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.IsValid); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Read); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.IsRequest); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.IsValid); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Read); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.IsResponse); }
public async Task Should_fail_TryParse_two_FramePackets_ReadRequest_ReadResponse_from_FileInfo() { FileInfo fi = new FileInfo(@".\TestData\Invalid_ReadRequest.cap"); var(ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(fi, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); fi = new FileInfo(@".\TestData\FileDoesNotExist.cap"); (ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(fi, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); }
public async Task Should_fail_TryParse_two_FramePackets_ReadRequest_ReadResponse_from_string() { var testFile = @".\TestData\Invalid_ReadRequest.cap"; var(ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); testFile = @".\TestData\FileDoesNotExist.cap"; (ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); }
public async Task Should_TryParse_two_FramePackets_ReadRequest_ReadResponse_from_string() { var testFile = @".\TestData\Valid_ReadRequest.cap"; var(ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(testFile, CancellationToken.None, null); Assert.IsTrue(ok); Assert.IsTrue(netMonFile.FramePackets.Count() == 2); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.IsValid); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Read); Assert.IsTrue(netMonFile.FramePackets.ElementAt(0).Data.AmsHeader.IsRequest); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.IsValid); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.AmsCommandId == Lib.TcAds.AmsCommandId.ADS_Read); Assert.IsTrue(netMonFile.FramePackets.ElementAt(1).Data.AmsHeader.IsResponse); }
public async Task Should_fail_TryParse_two_FramePackets_with_invalid_arguments() { var(ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(pathToCap : null, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); (ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(string.Empty, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); (ok, netMonFile) = await NetMonFileFactory.TryParseNetMonFileAsync(fi : null, CancellationToken.None, null); Assert.IsFalse(ok); Assert.IsNull(netMonFile); }