public void Construct() { var container = new Container(); var channel = new IntelChannel(channelName, container); Assert.AreEqual(channelName, channel.Name); Assert.AreEqual(container, channel.Container); Assert.AreEqual(IntelStatus.Stopped, channel.Status); Assert.IsFalse(channel.IsRunning); }
/// <summary> /// Initializes a new instance of the <see cref="IntelData" /> class /// </summary> /// <param name="intelText">the raw line of text from the log file</param> public IntelData(string intelText, string intelChannel, bool fromDMT = false) { RawIntelString = intelText; // text will be in the format [ 2017.05.01 18:24:28 ] Charname > blah, blah blah int start = intelText.IndexOf('>') + 1; int end = intelText.IndexOf(']'); IntelTime = DateTime.Parse(intelText.Substring(1, end - 1)); IntelString = intelText.Substring(start); Systems = new List <string>(); ClearNotification = false; IntelChannel = intelChannel.Insert(0, "("); IntelChannel = IntelChannel.Insert(IntelChannel.Length, ")"); }
public void DirectorySearch() { using (var sync = new AutoResetEvent(false)) { using (var directory = new TempDirectory()) { using (var channel = new IntelChannel(channelName)) { channel.Path = directory.FullName; channel.PropertyChanged += (sender, e) => { if (e.PropertyName == "LogFile") { sync.Set(); } }; // Make sure 'something' exists before the test var file1 = new TempFile(channelName, directory); using (file1.Open(FileMode.Create, FileAccess.Write, FileShare.Read)) { } // Start the component channel.Start(); // Make sure it is logging the appropriate file Assert.IsTrue(sync.WaitOne(5000), "Did not raise PropertyChanged for file1"); Assert.AreEqual(IntelStatus.Active, channel.Status); Assert.IsNotNull(channel.LogFile); Assert.AreEqual(file1.Name, channel.LogFile.Name, true); // Create a new file to monitor Thread.Sleep(2000); var file2 = new TempFile(channelName, directory); using (file2.Open(FileMode.Create, FileAccess.Write, FileShare.Read)) { } // Make sure it is logging the appropriate file Assert.IsTrue(sync.WaitOne(5000), "Did not raise PropertyChanged for file2"); Assert.AreEqual(IntelStatus.Active, channel.Status); Assert.IsNotNull(channel.LogFile); Assert.AreEqual(file2.Name, channel.LogFile.Name, true); } } } }
public void Dispose() { var channel = new IntelChannel(); channel.Dispose(); Assert.AreEqual(IntelStatus.Disposed, channel.Status); Assert.IsFalse(channel.IsRunning); }
public void Stop() { using (var channel = new IntelChannel(channelName)) { channel.Start(); Assert.IsTrue(channel.IsRunning); channel.Stop(); Assert.IsFalse(channel.IsRunning); Assert.AreEqual(IntelStatus.Stopped, channel.Status); } }
public void Start() { using (var channel = new IntelChannel(channelName)) { channel.Start(); Assert.IsTrue(channel.IsRunning); } }
public void PropertyChanged() { var sent = new PropertyChangedEventArgs("Status"); PropertyChangedEventArgs received = null; using (var channel = new IntelChannel()) { channel.PropertyChanged += (sender, e) => { Assert.IsNull(received, "PropertyChanged was raised multiple times."); Assert.AreEqual(channel, sender); received = e; }; channel.OnPropertyChanged(sent); Thread.Sleep(10); } Assert.AreEqual(sent, received); }
public void ParseLog() { var lines = new string[] { "[ 2013.04.29 23:54:10 ] Addemar > Drevas 6VDT-H nv", "[ 2013.04.29 23:54:38 ] Addemar > capsole", "[ 2013.04.29 23:54:48 ] Addemar > *pod", "[ 2013.04.29 23:55:03 ] Scilus > Drevas (Purifier*)", "t stryker > Gheos B17O-R NV", "[ 2013.04.30 00:04:54 ] Arayan Light > Kill: Drevas (Capsule) =)" }; var received = new List<IntelEventArgs>(); using (var file = new TempFile(channelName)) { using (var stream = file.Open(FileMode.Create, FileAccess.Write, FileShare.Read)) { using (var writer = new StreamWriter(stream, new UnicodeEncoding(false, false))) { writer.AutoFlush = true; writer.WriteLine(lines[0]); using (var channel = new IntelChannel(channelName)) { channel.IntelReported += (sender, e) => { lock (received) { received.Add(e); } }; channel.Start(); lock (channel.syncRoot) { channel.OpenFile(file.FileInfo); } Assert.IsNotNull(channel.LogFile); Assert.AreEqual(file.Name, channel.LogFile.Name, true); for (int line = 1; line < lines.Length; ++line) { if (line % 2 == 1) { writer.Write('\uFEFF'); } writer.WriteLine(lines[line]); } Thread.Sleep(10000); Assert.AreEqual(4, channel.IntelCount); } //using (var channel = channelMock.Object) { } //using (var writer = new StreamWriter(...)) { } //using (var stream = file.Open(...)) { } //using (var file = new TempFile()) { Assert.AreEqual(4, received.Count); Assert.IsFalse(received.Any(x => (x.Message.Contains("6VDT-H"))), "Should not have parsed " + lines[0]); Assert.IsTrue(received.Any(x => (x.Message == lines[1].Substring(23)) && (x.Timestamp == new DateTime(2013, 4, 29, 23, 54, 38, DateTimeKind.Utc)) && (x.Channel == channelName)), "Did not parse " + lines[1]); Assert.IsTrue(received.Any(x => (x.Message == lines[2].Substring(23)) && (x.Timestamp == new DateTime(2013, 4, 29, 23, 54, 48, DateTimeKind.Utc)) && (x.Channel == channelName)), "Did not parse " + lines[2]); Assert.IsTrue(received.Any(x => (x.Message == lines[3].Substring(23)) && (x.Timestamp == new DateTime(2013, 4, 29, 23, 55, 3, DateTimeKind.Utc)) && (x.Channel == channelName)), "Did not parse " + lines[3]); Assert.IsFalse(received.Any(x => (x.Message.Contains("B17O-R"))), "Should not have parsed " + lines[4]); Assert.IsTrue(received.Any(x => (x.Message == lines[5].Substring(23)) && (x.Timestamp == new DateTime(2013, 4, 30, 0, 4, 54, DateTimeKind.Utc)) && (x.Channel == channelName)), "Did not parse " + lines[5]); }
public void NameMissing() { using (var channel = new IntelChannel()) { channel.Start(); } }
public void IntelReported() { var sent = new IntelEventArgs("channel", DateTime.UtcNow, "message"); IntelEventArgs received = null; using (var channel = new IntelChannel()) { channel.IntelReported += (sender, e) => { Assert.IsNull(received, "IntelReported was raised multiple times."); Assert.AreEqual(channel, sender); received = e; }; channel.OnIntelReported(sent); Thread.Sleep(10); Assert.AreEqual(1, channel.IntelCount); } Assert.AreEqual(sent, received); }