Renamed Buffers utility class to BufferManager. Added "Sample Configuration.config...
[lwes-dotnet/github-mirror.git] / Org.Lwes.Tests / EventListenerTests.cs
blobc614717a04edc86b1c599eaa8d1945c35411927b
1 namespace Org.Lwes.Tests
3 using System;
4 using System.Net;
5 using System.Threading;
7 using Microsoft.VisualStudio.TestTools.UnitTesting;
9 using Org.Lwes.Emitter;
10 using Org.Lwes.Listener;
12 [TestClass]
13 public class EventListenerTests
15 #region Fields
17 bool _done;
18 Event _receivedEvent;
20 #endregion Fields
22 #region Methods
24 [TestMethod]
25 public void AccessDefaultListener()
27 var e = new
29 EventName = "UserLogin",
30 Attributes = new
32 UserName = new { Name = "username", Token = TypeToken.STRING, Value = "bob" },
33 Password = new { Name = "password", Token = TypeToken.UINT64, Value = 0xfeedabbadeadbeefUL },
34 ClientIP = new { Name = "clientIP", Token = TypeToken.IP_ADDR, Value = IPAddress.Parse("127.0.0.1") },
35 Successful = new { Name = "successful", Token = TypeToken.BOOLEAN, Value = false }
39 IEventListener listener = EventListener.CreateDefault();
40 Assert.IsNotNull(listener);
41 listener.OnEventArrival += new HandleEventArrival(listener_OnEventArrival);
43 IEventEmitter emitter = EventEmitter.CreateDefault();
44 Assert.IsNotNull(emitter);
46 // Create the event...
47 Event _sourceEvent = new Event(e.EventName)
48 .SetValue(e.Attributes.UserName.Name, e.Attributes.UserName.Value)
49 .SetValue(e.Attributes.Password.Name, e.Attributes.Password.Value)
50 .SetValue(e.Attributes.ClientIP.Name, e.Attributes.ClientIP.Value)
51 .SetValue(e.Attributes.Successful.Name, e.Attributes.Successful.Value);
53 long time_out_ticks = DateTime.Now.Ticks + TimeSpan.FromSeconds(20).Ticks;
55 while (!_done && DateTime.Now.Ticks < time_out_ticks)
57 emitter.Emit(_sourceEvent);
58 Thread.Sleep(1000);
61 Assert.IsTrue(_done, "Should have received an event");
62 Assert.AreEqual(_sourceEvent[e.Attributes.UserName.Name].GetValue<string>(), _receivedEvent[e.Attributes.UserName.Name].GetValue<string>());
63 Assert.AreEqual(_sourceEvent[e.Attributes.Password.Name].GetValue<ulong>(), _receivedEvent[e.Attributes.Password.Name].GetValue<ulong>());
64 Assert.AreEqual(_sourceEvent[e.Attributes.ClientIP.Name].GetValue<IPAddress>(), _receivedEvent[e.Attributes.ClientIP.Name].GetValue<IPAddress>());
65 Assert.AreEqual(_sourceEvent[e.Attributes.Successful.Name].GetValue<bool>(), _receivedEvent[e.Attributes.Successful.Name].GetValue<bool>());
66 Console.Write(_receivedEvent.ToString());
69 void listener_OnEventArrival(IEventListener sender, Event ev)
71 _done = true;
72 _receivedEvent = ev;
75 #endregion Methods