protected SearchRange DefineSearchRange(RecordingInformation recording) { DateTime start; DateTime end; DateTime minDate = DateTime.MaxValue; DateTime maxDate = DateTime.MinValue; foreach (TrackInformation trackInformation in recording.Track) { if (trackInformation.DataFrom < minDate) { minDate = trackInformation.DataFrom; } if (trackInformation.DataTo > maxDate) { maxDate = trackInformation.DataTo; } } start = recording.EarliestRecordingSpecified ? recording.EarliestRecording : minDate; end = recording.LatestRecordingSpecified ? recording.LatestRecording : maxDate; return(new SearchRange(start, end, start, end)); }
public void PlayabckAllStreamingControlMessagesTest() { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } return(false); }; _videoForm.OPTIONS = true; ReplayAllSequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording) }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }); }, () => { Cleanup(); }); }
public override RecordingInformation GetRecordingInformation(string RecordingToken) { RecordingInformation info = SearchStorage.Instance.Recordings.Where(R => R.RecordingToken == RecordingToken).FirstOrDefault(); return(info); }
RecordingInformation CreateMetadataRecording(int id) { RecordingInformation info = new RecordingInformation(); info.Content = string.Format("Recording{0}", id); info.EarliestRecordingSpecified = true; info.EarliestRecording = new System.DateTime(2012, 05, 12, 12 + id, 00, 00); info.LatestRecordingSpecified = true; info.LatestRecording = new System.DateTime(2012, 05, 12, 13 + id, 00, 00); info.RecordingStatus = RecordingStatus.Stopped; info.RecordingToken = string.Format("recording{0}", id); info.Source = new RecordingSourceInformation(); info.Source.SourceId = string.Format("Source{0}", id); info.Source.Name = string.Format("Source{0}", id); info.Source.Description = string.Format("Source {0}", id); info.Source.Address = string.Format("Address {0}", id); info.Source.Location = string.Format("Location {0}", id); List <TrackInformation> tracks = new List <TrackInformation>(); tracks.Add(new TrackInformation() { DataFrom = new System.DateTime(2012, 05, 12, 12 + id, 00, 00), DataTo = new System.DateTime(2012, 05, 12, 13 + id, 00, 00), TrackToken = "track1", TrackType = TrackType.Metadata, Description = "Metadata Track 01", }); info.Track = tracks.ToArray(); return(info); }
private void SimplePlaybackTest(bool reverse, TransportProtocol protocol, bool useVideo, bool useAudio, bool useMeta) { _handleLogMessage = (message) => { RtpPacket rtpPacket; if (HadleMessagePacket(message, out rtpPacket)) { byte payload = rtpPacket.Payload; List <RtpPacket> rtpPackets = _rtpPackets[payload]; if (rtpPackets.Count > 1) { RtpPacket prev = rtpPackets[rtpPackets.Count - 2]; RtpPacket curr = rtpPackets[rtpPackets.Count - 1]; if (!reverse && prev.IsNextInTime(prev)) { throw new VideoException("Error: wrong NTP timestamps order in packets"); } if (reverse && curr.IFrameStart && _lastIFrame.ContainsKey(payload) && _lastIFrame[payload] != curr && !curr.IsNextInRTPTime(_lastIFrame[payload])) { throw new VideoException("Error: wrong RTP timestamps order in iframe packets"); } if (reverse && curr.OrdinaryFrameStart && !prev.IsNextInRTPTime(curr)) { throw new VideoException("Error: wrong RTP timestamps order in GOP packets"); } } return(true); } return(false); }; RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, protocol); _videoForm.ReplayReverse = reverse; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(reverse ? recInfo.LatestRecording : recInfo.EarliestRecording), reverse ? "Scale: -1.0" : string.Empty }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }, useVideo, useAudio, useMeta); }, () => { Cleanup(); }); }
protected RecordingInformation GetRecordingInformation(string token) { RecordingInformation response = null; RunStep(() => { response = Client.GetRecordingInformation(token); }, "Get Recording Information"); return(response); }
RecordingInformation GetRecordingInformation(string token) { RecordingInformation info = null; Proxies.Onvif.SearchPortClient client = SearchClient; RunStep(() => { info = client.GetRecordingInformation(token); }, string.Format("Get recording information (token = '{0}')", token)); DoRequestDelay(); return(info); }
protected void ReplayPauseTest(bool withRange, bool useVideo, bool useAudio, bool useMeta) { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); int delta = 8; _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } if (withRange ? HadleMessagePause(message, recInfo.EarliestRecording.AddSeconds(delta)) : HadleMessagePause(message, null)) { return(true); } return(false); }; if (withRange) { _videoForm.ReplayPauseWait = delta - _videoForm.ReplayMaxDuration; RunStep(() => { LogStepEvent(string.Format("From: {0}", recInfo.EarliestRecording)); LogStepEvent(string.Format("To: {0}", recInfo.EarliestRecording.AddSeconds(delta))); }, "Set range"); } ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording) }) + MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY }), (withRange ? MakeFieldsSet(new string[] { RangeClockExact(recInfo.EarliestRecording.AddSeconds(delta)) }) : ""), (actionPlay, actionPause, actionTeardown) => { actionPlay(); actionPause(); Sleep(2000); actionPlay(); }, useVideo, useAudio, useMeta); }, () => { Cleanup(); }); }
private void VerifyMetadataSearchResult(List <FindMetadataResult> response, RecordingInformation recording, SearchRange recordingRange, bool ascendingOrder) { Assert(response != null, "No metadata was found", "Check that metadata list is not empty"); Assert(response.FirstOrDefault(r => r.RecordingToken != recording.RecordingToken) == null, "GetMetadataSearchResultsResponse contains results with invalid Recording token", "Check that recording token is valid for GetMetadataSearchResultsResponse"); bool ok = true; StringBuilder logger = new StringBuilder("Following tracks are invalid" + Environment.NewLine); foreach (var result in response) { if (recording.Track.FirstOrDefault(t => t.TrackToken == result.TrackToken) == null) { ok = false; logger.Append(string.Format(" TrackToken '{0}' is invalid{1}", result.TrackToken, Environment.NewLine)); } if (result.Time < recordingRange.Start) { ok = false; logger.Append( string.Format(" Track (TrackToken = '{0}') time (t = '{1}') is outside recording range{2}", result.TrackToken, result.Time, Environment.NewLine)); } } Assert(ok, logger.ToStringTrimNewLine(), "Check that tracks are valid for GetMetadataSearchResultsResponse"); Func <System.DateTime, System.DateTime, bool> condition = (t1, t2) => { return(t1 <= t2); }; if (ascendingOrder) { condition = (t1, t2) => { return(t1 >= t2); } } ; //bool ok = true; for (int i = 0; i < response.Count - 1; i++) { if (condition(response[i].Time, response[i + 1].Time)) { ok = false; break; } } Assert(ok, "DUT didn't return metadata search results in right order", "Check that DUT return metadata search results in right order"); }
/// <summary> /// /// </summary> /// <param name="list"></param> /// <param name="recordingToken"></param> void ValidatePTZPositionResults(IEnumerable <FindPTZPositionResult> list, RecordingInformation recording, System.DateTime startTime, System.DateTime endTime) { string recordingToken = recording.RecordingToken; StringBuilder sb = new StringBuilder(); BeginStep("Validate search results"); bool ok = true; bool asc = startTime < endTime; System.DateTime minTime = asc ? startTime : endTime; System.DateTime maxTime = asc ? endTime : startTime; foreach (FindPTZPositionResult result in list) { if (result.Time < minTime || result.Time > maxTime) { ok = false; sb.AppendFormat("Result for time {0} is out of expected interval ({1}; {2}){3}", result.Time.StdDateTimeToString(), minTime.StdDateTimeToString(), maxTime.StdDateTimeToString(), Environment.NewLine); } if (result.RecordingToken != recordingToken) { ok = false; sb.AppendFormat("Result for time {0} does not belong to recording {1}{2}", result.Time.StdDateTimeToString(), recordingToken, Environment.NewLine); } if (!string.IsNullOrEmpty(result.TrackToken) && recording.Track != null) { if (recording.Track.Where(T => T.TrackToken == result.TrackToken).FirstOrDefault() == null) { ok = false; sb.AppendFormat("Track with token '{0}', specified in result for time {1} does not belong to recording {2}{3}", result.TrackToken, result.Time.StdDateTimeToString(), recordingToken, Environment.NewLine); } } } if (!ok) { throw new AssertException(sb.ToStringTrimNewLine()); } StepPassed(); }
protected SearchRange DefineSearchRangeOutside(RecordingInformation recording) { SearchRange range = DefineSearchRange(recording); TimeSpan timeSpan = (range.End - range.Start); int delta = 1 + (int)timeSpan.TotalSeconds / 10; range.Start = range.Start.AddSeconds(-delta); range.End = range.End.AddSeconds(delta); return(range); }
RecordingInformation FindRecordingForTest() { RecordingInformation recording = null; RunStep(() => { recording = Client.GetRecordingInformation(_recordingToken); }, "Get Recording Information"); Assert(recording != null, "Recording not found", "Check that recording for test found"); Assert(recording.Track != null && recording.Track.Length > 0, "Recording has no tracks", "Check that recording has tracks"); return(recording); }
protected void ReplayStopOfPlayingTest(bool useVideo, bool useAudio, bool useMeta) { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } return(false); }; int delta = 4; RunStep(() => { LogStepEvent(string.Format("From: {0}", recInfo.EarliestRecording)); LogStepEvent(string.Format("To: {0}", recInfo.EarliestRecording.AddSeconds(delta))); }, "Set range"); ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording, recInfo.EarliestRecording.AddSeconds(delta)) }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }, useVideo, useAudio, useMeta); RunStep(() => { if (PacketsAfterTime(recInfo.EarliestRecording.AddSeconds(delta))) { throw new VideoException("Error: The received stream NTP timestamp is out of requested range (received NTP timestamp > end time of the requested range)"); } }, "Timestamp range check"); }, () => { Cleanup(); }); }
public void FindPtzPositionsSearchWithMaxMatchesTest() { string searchToken = string.Empty; SearchState state = SearchState.Completed; RunTest( () => { string keepAlive = string.Format("PT{0}S", _searchKeepAlive); RecordingInformation recording = FindRecordingForTest(); SearchRange range = DefineSearchRange(recording); System.DateTime start = range.Start; System.DateTime end = range.End; List <FindPTZPositionResult> results; PTZPositionFilter filter = new PTZPositionFilter(); filter.MinPosition = new PTZVector(); filter.MinPosition.PanTilt = new Vector2D() { x = -1, y = -1 }; filter.MaxPosition = new PTZVector(); filter.MaxPosition.PanTilt = new Vector2D() { x = 1, y = 1 }; SearchScope scope = new SearchScope(); scope.IncludedRecordings = new string[] { recording.RecordingToken }; searchToken = FindPTZPosition(start, end, scope, filter, 1, keepAlive); results = GetAllPtzSearchResults(searchToken, filter, null, null, "PT5S", out state); Assert(results != null && results.Count > 0, "No PTZ positions found", "Check that PTZ positions list is not empty"); Assert(results.Count == 1, string.Format("{0} PTZ positions found", results.Count), "Check that maxMatches parameter is not exceeded"); }, () => { if (state != SearchState.Completed) { ReleaseSearch(searchToken, _searchTimeout); } }); }
protected SearchRange DefineSearchRangeInside(RecordingInformation recording) { SearchRange range = DefineSearchRange(recording); TimeSpan timeSpan = (range.End - range.Start); double delta = (int)timeSpan.TotalMilliseconds / 10; range.Start = range.Start.AddMilliseconds(delta); range.End = range.End.AddMilliseconds(-delta); range.Earliest = range.Start; range.Latest = range.End; return(range); }
void ValidateEventsContext(RecordingInformation recording, string topic, IEnumerable <FindEventResult> results, Dictionary <FindEventResult, XmlElement> elements) { Func <FindEventResult, bool> eventCheck = (E => { bool topicMatches = CheckEventTopic(E, elements[E], topic, TNS1NAMESPACE); return(topicMatches); }); // select events List <FindEventResult> filtered = results.Where(eventCheck).ToList(); BeginStep(string.Format( "Check that all events with topic '{0}' relate to recording '{1}'", topic, recording.RecordingToken)); StringBuilder sb = new StringBuilder(); bool ok = true; // no other tracks foreach (FindEventResult result in filtered) { if (result.RecordingToken != recording.RecordingToken) { ok = false; sb.AppendFormat("Event with topic={0}, Time={1} relates to recording {2}{3}", topic, result.Time.StdDateTimeToString(), result.RecordingToken, Environment.NewLine); } if (recording.Track.Where(T => T.TrackToken == result.TrackToken).Count() == 0) { ok = false; sb.AppendFormat("Event with topic={0}, Time={1} relates to track {2}, which does not belong to recording {3}{4}", topic, result.Time.StdDateTimeToString(), result.TrackToken, recording.RecordingToken, Environment.NewLine); } } if (!ok) { throw new AssertException(sb.ToStringTrimNewLine()); } StepPassed(); }
public void PlayabckVideoStreamingImmediateHeaderTest() { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } return(false); }; int delta = 5; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording) }) + MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording.AddSeconds(delta)), "Immediate: yes" }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); Sleep(delta * 1000); actionPlay(); }); }, () => { Cleanup(); }); }
internal StepType GetRecordingInformationTest(out RecordingInformation target, out SoapException ex, out int Timeout, string RecordingToken) { StepType res = StepType.None; Timeout = 0; ex = null; target = null; bool passed = true; string logMessage = ""; string tmpCommandName = "GetRecordingInformation"; int tmpCommandNumber = GetRecordingInformation; //Get step list for command XmlNodeList m_testList = TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName); if (m_testList.Count != 0) { //Get current step XmlNode test = m_testList[CommandCount[tmpCommandNumber]]; #region Analyze request //RecordingToken CommonCompare.StringCompare("RequestParameters/RecordingToken", "RecordingToken", RecordingToken, ref logMessage, ref passed, test); #endregion //Analyze request //Generate response object targetObj; res = TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(RecordingInformation)); target = (RecordingInformation)targetObj; //Log message TestCommon.writeToLog(test, logMessage, passed); Increment(m_testList.Count, tmpCommandNumber); } else { throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode); } return(res); }
public void PlayabckVideoStreamingPauseWithRangeTest() { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } if (HadleMessagePause(message)) { return(true); } return(false); }; int delta = 8; _videoForm.ReplayPauseWait = delta - _videoForm.ReplayMaxDuration; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording) }) + MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY }), MakeFieldsSet(new string[] { RangeClockExact(recInfo.EarliestRecording.AddSeconds(delta)) }), (actionPlay, actionPause, actionTeardown) => { actionPlay(); actionPause(); Sleep(2000); actionPlay(); }); }, () => { _videoForm.ReplayPauseWait = 0; Cleanup(); }); }
protected void ReplayIFramesTest(bool useVideo, bool useAudio, bool useMeta) { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { RtpPacket rtpPacket; if (HadleMessagePacket(message, out rtpPacket)) { if (!rtpPacket.IFrame) { throw new VideoException("Error: only I-Frames allowed"); } return(true); } return(false); }; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording), "Frames: intra" }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }, useVideo, useAudio, useMeta); }, () => { Cleanup(); }); }
void DefineEventsSearchRange(RecordingInformation recording, out DateTime start, out DateTime end) { DateTime minDate = DateTime.MaxValue; DateTime maxDate = DateTime.MinValue; foreach (TrackInformation trackInformation in recording.Track) { if (trackInformation.DataFrom < minDate) { minDate = trackInformation.DataFrom; } if (trackInformation.DataTo > maxDate) { maxDate = trackInformation.DataTo; } } start = recording.EarliestRecordingSpecified ? recording.EarliestRecording : minDate; end = recording.LatestRecordingSpecified ? recording.LatestRecording : maxDate; }
FindEventResult GenerateTrackEvent(RecordingInformation recording, TrackInformation track) { FindEventResult eventResult = new FindEventResult(); eventResult.RecordingToken = recording.RecordingToken; if (track != null) { eventResult.TrackToken = track.TrackToken; } else { eventResult.TrackToken = ""; } eventResult.Event = new NotificationMessageHolderType(); //eventResult.Event.ProducerReference = new EndpointReferenceType(); //eventResult.Event.ProducerReference.Address = new AttributedURIType(){Value= "http://localhost/dut.asmx"}; eventResult.Event.Topic = new TopicExpressionType(); eventResult.Event.Topic.Dialect = "http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet"; return(eventResult); }
public void PlayabckVideoStreamingIFramesTest() { RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { if (!_rtpPackets[_rtpPackets.Count - 1].IFrame) { throw new VideoException("Error: only I-Frames allowed"); } return(true); } return(false); }; ReplaySequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording), "Frames: intra" }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }); }, () => { Cleanup(); }); }
public void FindEventsSearchWithMaxMatchesTest() { string searchToken = string.Empty; SearchState state = SearchState.Completed; RunTest( () => { string keepAlive = string.Format("PT{0}S", _searchKeepAlive); RecordingInformation recording = FindRecordingForTest(); DateTime start; DateTime end; DefineEventsSearchRange(recording, out start, out end); List <FindEventResult> results = new List <FindEventResult>(); EventFilter filter = new EventFilter(); SearchScope scope = new SearchScope(); scope.IncludedRecordings = new string[] { recording.RecordingToken }; searchToken = FindEvents(scope, filter, start, end, false, 1, keepAlive); results = GetAllEventsSearchResults(searchToken, null, null, "PT5S", null, out state); Assert(results != null && results.Count > 0, "No events found", "Check that events list is not empty"); Assert(results.Count == 1, string.Format("{0} events found", results.Count), "Check that maxMatches parameter is not exceeded"); }, () => { if (state != SearchState.Completed) { EndSearch(searchToken); } }); }
public void PlayabckAllStreamingControlMessagesTest() { #if true bool metadataSupported = Features.ContainsFeature(Feature.MetadataRecording); bool audioSupported = Features.ContainsFeature(Feature.AudioRecording); MediaPlaybackTest2(TransportProtocol.UDP, true, audioSupported, metadataSupported); #else RunTest(() => { RecordingInformation recInfo = GetRecordingParameters(); AdjustVideo(recInfo.RecordingToken, TransportProtocol.UDP); _handleLogMessage = (message) => { if (HadleMessagePacket(message)) { return(true); } return(false); }; _videoForm.OPTIONS = true; ReplayAllSequence( REQUIRE_ONVIF_REPLAY + CRLF, MakeFieldsSet(new string[] { REQUIRE_ONVIF_REPLAY, RangeClock(recInfo.EarliestRecording) }), "", (actionPlay, actionPause, actionTeardown) => { actionPlay(); }); }, () => { Cleanup(); }); #endif }
void ValidateRecordingEvents(RecordingInformation recording, IEnumerable <FindEventResult> results, Dictionary <FindEventResult, XmlElement> elements, bool checkEdges, bool forward) { // check sequence ValidateRecordingEventsSequence(recording, results, elements, checkEdges, forward); // no other recordings ValidateEventsContext(recording, "tns1:RecordingHistory/Track/State", results, elements); foreach (TrackInformation track in recording.Track) { if (track.DataTo > track.DataFrom) { ValidateTrackEvents(recording, track, results, elements, checkEdges, forward); } } ValidateEventsContext(recording, "tns1:RecordingHistory/Track/VideoParameters", results, elements); ValidateEventsContext(recording, "tns1:RecordingHistory/Track/AudioParameters", results, elements); }
protected RecordingInformation GetRecordingParameters() { RecordingInformation recInfo = null; RunStep(() => { recInfo = Client.GetRecordingInformation(_recordingToken); }, "Get Recording Information"); RunStep(() => { if (recInfo == null) { throw new AssertException("Recording not found"); } if (recInfo.Track == null || recInfo.Track.Length == 0) { throw new AssertException("Recording has no tracks"); } if (!recInfo.EarliestRecordingSpecified) { recInfo.EarliestRecording = recInfo.Track[0].DataFrom; } if (!recInfo.LatestRecordingSpecified) { recInfo.LatestRecording = recInfo.Track[0].DataTo; } LogStepEvent("Recording Token = " + recInfo.RecordingToken); LogStepEvent("Recording Start = " + recInfo.EarliestRecording.ToUniversalTime()); LogStepEvent("Recording End = " + recInfo.LatestRecording.ToUniversalTime()); }, "Check Recording"); return(recInfo); }
void CompareLists(IEnumerable <RecordingInformation> recordings1, IEnumerable <RecordingInformation> recordings2) { bool ok = true; StringBuilder logger = new StringBuilder(); List <string> common = new List <string>(); // check that all tokens from full list are present in list of found recordings foreach (RecordingInformation item in recordings1) { string token = item.RecordingToken; if (!recordings2.Any(RI => RI.RecordingToken == token)) { logger.AppendFormat("Recording with token {0} not found in second list{1}", item.RecordingToken, Environment.NewLine); ok = false; } else { common.Add(token); } } foreach (RecordingInformation item in recordings2) { string token = item.RecordingToken; if (!recordings1.Any(RI => RI.RecordingToken == token)) { logger.AppendFormat("Recording with token {0} not found in first list{1}", item.RecordingToken, Environment.NewLine); ok = false; } } // for common only foreach (RecordingInformation info1 in recordings1) { string token = info1.RecordingToken; if (!common.Contains(token)) { continue; } RecordingInformation info2 = recordings2.FirstOrDefault(RI => RI.RecordingToken == token); StringBuilder dump = new StringBuilder(string.Format("Information for recording with token '{0}' is different:{1}", token, Environment.NewLine)); bool localOk = true; if (info1.Content != info2.Content) { localOk = false; dump.AppendLine(" Content is different"); } if (info1.RecordingStatus != info2.RecordingStatus) { localOk = false; dump.AppendLine(" RecordingStatus is different"); } Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string> check = new Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string>( (specifiedSelector, valueSelector, fieldName) => { bool specified1 = specifiedSelector(info1); bool specified2 = specifiedSelector(info2); if (specified1 || specified2) { if (specified1 && specified2) { System.DateTime value1 = valueSelector(info1); System.DateTime value2 = valueSelector(info2); if (value1 != value2) { localOk = false; dump.AppendFormat(" {0} is different{1}", fieldName, Environment.NewLine); } } else { if (!specified1) { localOk = false; dump.AppendFormat(" {0} not specified for the first list{1}", fieldName, Environment.NewLine); } if (!specified2) { localOk = false; dump.AppendFormat(" {0} not specified for the second list{1}", fieldName, Environment.NewLine); } } } }); check(RI => RI.EarliestRecordingSpecified, RI => RI.EarliestRecording, "EarliestRecording"); check(RI => RI.LatestRecordingSpecified, RI => RI.LatestRecording, "LatestRecording"); RecordingSourceInformation source1 = info1.Source; RecordingSourceInformation source2 = info2.Source; if (source1 != null || source2 != null) { if (source1 != null && source2 != null) { Action <string, Func <RecordingSourceInformation, string> > checkStringAction = new Action <string, Func <RecordingSourceInformation, string> >( (name, fieldSelector) => { string value1 = fieldSelector(source1); string value2 = fieldSelector(source2); if (value1 != value2) { localOk = false; dump.AppendFormat(" Source.{0} field is different {1}", name, Environment.NewLine); } }); checkStringAction("Address", S => S.Address); checkStringAction("Description", S => S.Description); checkStringAction("Location", S => S.Location); checkStringAction("Name", S => S.Name); checkStringAction("SourceId", S => S.SourceId); } else { if (source1 == null) { dump.AppendLine(" RecordingSourceInformation is missing for the item from the first list{0}"); localOk = false; } if (source2 == null) { dump.AppendLine(" RecordingSourceInformation is missing for the item from the second list{0}"); localOk = false; } } } bool trackList1Ok = info1.Track != null && info1.Track.Length > 0; bool trackList2Ok = info2.Track != null && info2.Track.Length > 0; if (trackList1Ok || trackList2Ok) { if (trackList1Ok && trackList2Ok) { // compare track by track bool tracksOk = true; TrackInformation[] tracks1 = info1.Track; TrackInformation[] tracks2 = info2.Track; StringBuilder sb = new StringBuilder(); bool tokensOk = ArrayUtils.ValidateTokens(tracks1, TR => TR.TrackToken, sb); if (!tokensOk) { dump.AppendFormat(" List of tracks is not valid for item from the first list - not all checks will be performed{0}", Environment.NewLine); tracksOk = false; } sb = new StringBuilder(); tokensOk = ArrayUtils.ValidateTokens(tracks2, TR => TR.TrackToken, sb); if (!tokensOk) { dump.AppendFormat(" List of tracks is not valid for item from the second list - not all checks will be performed{0}", Environment.NewLine); tracksOk = false; } { List <string> commonTracks = new List <string>(); // compare tokens foreach (TrackInformation info in tracks1) { TrackInformation inf = tracks2.FirstOrDefault(T => T.TrackToken == info.TrackToken); if (inf == null) { tracksOk = false; // not found dump.AppendFormat(" Track with token {0} not found for recording from second list{1}", info.TrackToken, Environment.NewLine); } else { int cnt = tracks1.Count(T => T.TrackToken == info.TrackToken); if (cnt == 1) { commonTracks.Add(info.TrackToken); } } } foreach (TrackInformation info in tracks2) { TrackInformation inf = tracks1.FirstOrDefault(T => T.TrackToken == info.TrackToken); if (inf == null) { tracksOk = false; // not found dump.AppendFormat(" Track with token {0} not found for recording from first list{1}", info.TrackToken, Environment.NewLine); } } { // compare common foreach (TrackInformation trackInfo1 in tracks1) { string trackToken = trackInfo1.TrackToken; if (!commonTracks.Contains(trackToken)) { continue; } TrackInformation[] infos = tracks2.Where(T => T.TrackToken == trackToken).ToArray(); if (infos.Length != 1) { // error is added to log already continue; } TrackInformation trackInfo2 = infos[0]; // DataFrom, DataTo, Description, TrackType if (trackInfo1.Description != trackInfo2.Description) { tracksOk = false; dump.AppendFormat(" Description is different for tracks with token '{0}'{1}", trackToken, Environment.NewLine); } if (trackInfo1.TrackType != trackInfo2.TrackType) { tracksOk = false; dump.AppendFormat(" TrackType is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine); } if (trackInfo1.DataFrom != trackInfo2.DataFrom) { tracksOk = false; dump.AppendFormat(" DataFrom is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine); } if (trackInfo1.DataTo != trackInfo2.DataTo) { tracksOk = false; dump.AppendFormat(" DataTo is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine); } } } } localOk = localOk && tracksOk; } else { if (!trackList1Ok) { dump.AppendFormat(" Track list is missing for the item from the first list{0}", Environment.NewLine); localOk = false; } if (!trackList2Ok) { dump.AppendFormat(" Track list is missing for the item from the first list{0}", Environment.NewLine); localOk = false; } } } if (!localOk) { logger.Append(dump.ToString()); ok = false; } } Assert(ok, logger.ToStringTrimNewLine(), "Check that all recordings are returned"); }
public void FindEventsForwardSearchTest() { string searchToken = string.Empty; SearchState state = SearchState.Completed; RunTest( () => { string keepAlive = string.Format("PT{0}S", _searchKeepAlive); RecordingInformation recording = FindRecordingForTest(); DateTime start; DateTime end; DefineEventsSearchRange(recording, out start, out end); List <FindEventResult> results = new List <FindEventResult>(); Dictionary <FindEventResult, XmlElement> elements1 = new Dictionary <FindEventResult, XmlElement>(); Dictionary <FindEventResult, XmlElement> elements2 = new Dictionary <FindEventResult, XmlElement>(); Dictionary <FindEventResult, XmlElement> elements = elements1; EventFilter filter = new EventFilter(); SearchScope scope = new SearchScope(); scope.IncludedRecordings = new string[] { recording.RecordingToken }; Action <DateTime, DateTime> validateAction = new Action <DateTime, DateTime>( (startTime, endTime) => { state = SearchState.Completed; searchToken = FindEvents(scope, filter, startTime, endTime, false, null, keepAlive); Dictionary <FindEventResult, XmlDocument> rawResults = new Dictionary <FindEventResult, XmlDocument>(); results = GetAllEventsSearchResults(searchToken, null, null, "PT5S", rawResults, out state); Assert(results != null && results.Count > 0, "No events found", "Check that events list is not empty"); ValidateMessages(results); GetMessageElements(results, rawResults, elements); ValidateRecordingEvents(recording, results, elements); ValidateOrder(results, startTime, endTime); }); validateAction(start, end); List <FindEventResult> results1 = new List <FindEventResult>(); results1.AddRange(results); elements = elements2; validateAction(end, start); List <FindEventResult> results2 = new List <FindEventResult>(); results2.AddRange(results); // compare lists CompareLists(results1, results2, elements1, elements2, "list received for StartPoint < EndPoint", "list received for StartPoint > EndPoint"); }, () => { if (state != SearchState.Completed) { EndSearch(searchToken); } }); }
void ValidateTrackEvents(RecordingInformation recording, TrackInformation track, IEnumerable <FindEventResult> results, Dictionary <FindEventResult, XmlElement> elements, bool checkEdges, bool forward) { Func <FindEventResult, bool> eventCheck = E => CheckEventTopic(E, elements[E], "tns1:RecordingHistory/Track/State", TNS1NAMESPACE); IEnumerable <FindEventResult> filtered = results.Where(E => eventCheck(E) && E.TrackToken == track.TrackToken).OrderBy(E => E.Time); bool dataPresentOk = true; bool?lastDataPresent = null; if (checkEdges) { //If checkEdges == true => It is expected that searchInterval includes the entire recording //In this case IsRecording == true for event with min Time(first) and false for event with max Time(last) //By spec, check only event with min Time lastDataPresent = false; // checkEdges = false means that interval is narrowed and virtual events are sent // in this case 1 event is OK Assert(filtered.Count() >= 2, string.Format("Not enough events with topic=tns1:RecordingHistory/Track/State, RecordingToken='{0}' for track '{1}' found in the response", recording.RecordingToken, track.TrackToken), string.Format("Check that at least two events with topic tns1:RecordingHistory/Track/State are present for track '{0}'", track.TrackToken)); } StringBuilder dump = new StringBuilder(); bool first = true; foreach (FindEventResult ev in filtered) { bool topicMatches = CheckEventTopic(ev, elements[ev], "tns1:RecordingHistory/Track/State", TNS1NAMESPACE); if (!topicMatches) { continue; } bool f = first; first = false; XmlElement message = ev.Event.Message; string value = GetSimpleItem(message, "IsDataPresent"); if (value == null) { dataPresentOk = false; dump.AppendFormat("IsDataPresent value not found for event with RecordingToken='{0}', Time='{1}'{2}", ev.RecordingToken, ev.Time.StdDateTimeToString(), Environment.NewLine); } else { bool dataPresent = false; bool attrOk = true; try { dataPresent = XmlConvert.ToBoolean(value); } catch (Exception) { attrOk = false; } if (!attrOk) { dataPresentOk = false; dump.AppendFormat("IsDataPresent value for event with RecordingToken='{0}', Time='{1}' is incorrect ({2}){3}", ev.RecordingToken, ev.Time.StdDateTimeToString(), value, Environment.NewLine); } else { if (ev.StartStateEvent) { continue; } if (lastDataPresent.HasValue) { if (dataPresent == lastDataPresent) { dataPresentOk = false; if (f) { dump.AppendFormat("IsDataPresent value for first event with RecordingToken='{0}', Time='{1}' is false {2}", ev.RecordingToken, ev.Time.StdDateTimeToString(), Environment.NewLine); } else { dump.AppendFormat("IsDataPresent value for event with RecordingToken='{0}', Time='{1}' is {2} while previous is also {2}{3}", ev.RecordingToken, ev.Time.StdDateTimeToString(), dataPresent, Environment.NewLine); } } } lastDataPresent = dataPresent; } } } Assert(dataPresentOk, dump.ToStringTrimNewLine(), "Check that IsDataPresent values in events are correct"); }