//When ReceiverClient events private void OnReceiverClientEvent(object sender, DataEventArgs e) { foreach (var track in e.Tracks) { // Look for track in list of tracks in airspace var foundTrack = _airCraftsInAirspaceList.Find(ByTag(track.Tag)); Track trackToValidate = null; // If already in list - update speed and coordinates. if (foundTrack != null) { double trackSeconds = (track.Time.Minute * 60) + track.Time.Second; double foundTrackSeconds = (foundTrack.Time.Minute * 60) + foundTrack.Time.Second; // Workaround TimeSpan differenceTime = track.Time.Subtract(foundTrack.Time); var velocity = _trackCalculator.CalculateVelocity(foundTrack.XCoordinate, track.XCoordinate, foundTrack.YCoordinate, track.YCoordinate, foundTrack.Altitude, track.Altitude, 0, differenceTime.TotalSeconds); var compassCourse = _trackCalculator.CalculateCourse(foundTrack.XCoordinate, track.XCoordinate, foundTrack.YCoordinate, track.YCoordinate); var newTrack = new Track(foundTrack.Tag, track.XCoordinate, track.YCoordinate, track.Altitude, track.Time, velocity, compassCourse); _airCraftsInAirspaceList.Remove(foundTrack); _airCraftsInAirspaceList.Add(newTrack); trackToValidate = newTrack; } // If not in list - add it This should be tested - intellisense says expression is always true else if (foundTrack == null) { _airCraftsInAirspaceList.Add(track); trackToValidate = track; } // If outside airspace, remove it. bool inAirSpace = _monitoredAirspace.ValidateAirspace(trackToValidate); if (!inAirSpace) { _airCraftsInAirspaceList.Remove(trackToValidate); } } // Pass on Tracks in monitored airspace if not empty if (_airCraftsInAirspaceList.Count != 0) { var args = new ATMSEventArgs(); args.Tracks = _airCraftsInAirspaceList; // Raise event if somebody has "subscribed" to it DataReady?.Invoke(this, args); } }
[Test] // Add velocity e.g. public void OnReceiverClientEvent_ReceiveEventWithSameTrackTwice_TrackCorrectly() { DateTime nowTime = DateTime.Now; var firstTrack = new Track("123456", 80000, 82000, 15000, nowTime, 0, 0); DateTime futureTime = DateTime.Now; var secondTrack = new Track("123456", 81000, 83000, 16000, futureTime, 0, 0); var correctTrack = new Track("123456", 81000, 83000, 16000, futureTime, 100, 220); List <Track> list = new List <Track>(); list.Add(firstTrack); DataEventArgs argsToSend = new DataEventArgs(list); ATMSEventArgs receivedArgs = new ATMSEventArgs(); // Will save the latest received, should save list with only correctTrack. uut.DataReady += (sender, args) => { receivedArgs = args; }; // Return correct velocity and course stubTrackCalculator .CalculateCourse(80000, 81000, 82000, 83000) .Returns(220); stubTrackCalculator .CalculateVelocity(80000, 81000, 82000, 83000, 15000, 16000, Arg.Any <double>(), Arg.Any <double>()) .Returns(100); // Act // Run firstTrack through ATMS stubTransRecClient.DataReceivedEvent += Raise.EventWith(argsToSend); // Send secondTrack through ATMS list.RemoveRange(0, 1); list.Add(secondTrack); argsToSend.Tracks = list; stubTransRecClient.DataReceivedEvent += Raise.EventWith(argsToSend); Track resultTrack = receivedArgs.Tracks[0]; // Assert Assert.That(resultTrack.Tag, Is.EqualTo(correctTrack.Tag)); Assert.That(resultTrack.Altitude, Is.EqualTo(correctTrack.Altitude)); Assert.That(resultTrack.CompassCourse, Is.EqualTo(correctTrack.CompassCourse)); Assert.That(resultTrack.Time, Is.EqualTo(correctTrack.Time)); Assert.That(resultTrack.Velocity, Is.EqualTo(correctTrack.Velocity)); Assert.That(resultTrack.XCoordinate, Is.EqualTo(correctTrack.XCoordinate)); Assert.That(resultTrack.YCoordinate, Is.EqualTo(correctTrack.YCoordinate)); }