public void TestHandleUpdate() { NotificationManager notificationManager = null; UserCache userCache = null; try { // Setup the basics object syncRoot = new object(); int serverPort = 30001; int clientPort = 30002; userCache = new UserCache(); notificationManager = new NotificationManager(serverPort, clientPort, userCache, false); string buildKey1 = "buildkey1"; string buildKey2 = "buildkey2"; string username = "******"; string hostname = "localhost"; // Create a user that has one build building and is responsible for one other build User user = new User(username) { Hostname = hostname }; user.ActiveBuilds.Add(buildKey1); user.BuildsResponsibleFor.Add(buildKey2); // A dummy client which the notification manager will notify Listener listener = new Listener(IPAddress.Any, clientPort); Dictionary<RequestType, IRequest> requests = new Dictionary<RequestType, IRequest>(); listener.OnCommandReceived += (sender, args) => { requests.Add(((IRequest)sender).Type, (IRequest)sender); lock (syncRoot) { Monitor.Pulse(syncRoot); } }; listener.Start(); Assert.That(listener.Running, Is.True); // Raise an update for this user and wait until all events caused have been raised lock (syncRoot) { notificationManager.HandleUpdate(user, EventArgs.Empty); ////Monitor.Wait(syncRoot, 5000); Monitor.Wait(syncRoot, 5000); } listener.Stop(); Assert.That(listener.Running, Is.False); // Test Assert.That(requests.ContainsKey(RequestType.BuildActive)); BuildActiveRequest buildActiveRequest = (BuildActiveRequest)requests[RequestType.BuildActive]; Assert.That(buildActiveRequest.IsBuildsActive, Is.True); } finally { if (notificationManager != null) { notificationManager.Dispose(); } if (userCache != null) { userCache.Dispose(); } } }