protected Proxies.Event.FilterType CreateSubscriptionFilter(IEnumerable <TopicInfo> topicInfos) { Proxies.Event.FilterType filter = new Proxies.Event.FilterType(); XmlDocument filterDoc = new XmlDocument(); XmlElement filterTopicElement = filterDoc.CreateTopicElement(); string topicPath = string.Empty; foreach (TopicInfo topicInfo in topicInfos) { string topicExpression = TopicInfo.CreateTopicPath(filterTopicElement, topicInfo); if (string.IsNullOrEmpty(topicPath)) { topicPath = topicExpression; } else { topicPath = string.Format("{0}|{1}", topicPath, topicExpression); } } filterTopicElement.InnerText = topicPath; filter.Any = new XmlElement[] { filterTopicElement }; return(filter); }
void CommonDoorPropertyEventStateChangeTestBis(Func <DoorInfo, bool> doorCapabilitiesTest, TopicInfo topicInfo, ValidateMessageFunction validateMessageFunction) { int actualTerminationTime = 60; if (_eventSubscriptionTimeout != 0) { actualTerminationTime = _eventSubscriptionTimeout; } int timeout = _operationDelay / 1000; RunTest( () => { //3. Get complete list of doors from the DUT (see Annex A.1). List <DoorInfo> fullDoorInfosList = GetDoorInfoList(); //4. Check that there is at least one Door with Capabilities.[CAPABILITIES FOR THE TEST]= “true”. // Otherwise skip other steps and go to the next test. List <DoorInfo> doorsList = null; if (doorCapabilitiesTest != null) { doorsList = fullDoorInfosList.Where(A => doorCapabilitiesTest(A)).ToList(); } else { doorsList = fullDoorInfosList; } Assert(doorsList.Any(), "No Doors with required Capabilities found, exit the test.", "Check there is appropriate door for test"); //5. ONVIF Client will select one random Door (token = Token1) with // Capabilities.DoorMonitor= “true”. // ToDo: may be change it to really random selection DoorInfo selectedDoor = doorsList[0]; // filter for current test Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); //6. ONVIF Client will invoke SubscribeRequest message with tns1:DoorControl/DoorPhysicalState Topic as Filter and an InitialTerminationTime of 60s to ensure that the SubscriptionManager is deleted after one minute. //7. Verify that the DUT sends a SubscribeResponse message. //8. Test Operator will invoke change of DoorPhysicalState property for Door with token = Token1. //9. Verify that DUT sends Notify message. string message = string.Format("{0} event is expected \r\n for the Door with token={{0}}", topicInfo.GetDescription()); DoorSelectionData data = new DoorSelectionData { SelectedToken = selectedDoor.token, MessageTemplate = message, Doors = doorsList.Select(D => new DoorSelectionData.DoorShortInfo() { Token = D.token, Name = D.Name }).ToList() }; string Message = string.Format("{0} event is expected \r\n for the Door with token = '{1}'", topicInfo.GetDescription(), selectedDoor.token); bool UseNotify = UseNotifyToGetEvents; Dictionary <NotificationMessageHolderType, XmlElement> notifications = null; CurrentSubsciption = null; try { CurrentSubsciption = new SubscriptionHandler(this, UseNotify, GetEventServiceAddress()); CurrentSubsciption.Subscribe(filter, actualTerminationTime); Operator.ShowMessage(Message); // Handler.WaitMessages( // timeout, // (n) => CheckMessagePropertyOperation(n, OnvifMessage.CHANGED), // SubscriptionHandler.WaitCondition.WC_ALL, // out notifications); var pullingCondition = new SubscriptionHandler.WaitFirstNotificationPollingCondition(timeout) { Filter = msg => CheckMessagePropertyOperation(msg, OnvifMessage.CHANGED) }; CurrentSubsciption.WaitMessages(1, pullingCondition, out notifications); } finally { Operator.HideMessage(); UnsubscribeCurrentSubsciption(); } Assert(null != notifications && notifications.Any(), string.Format("Message with PropertyOperation='Changed' for the door with token='{0}' has not been received.{1}WARNING: may be Operation delay is too low", data.SelectedToken, Environment.NewLine), "Check that the message for selected door has been received"); //10. Verify received Notify messages (correct value for UTC time, TopicExpression and // wsnt:Message). //11. Verify that TopicExpression is equal to [TOPIC] for // received Notify message. //12. Verify that notification contains Source.SimpleItem item with Name="DoorToken" // and Value= “Token1”. //13. Verify that notification contains Data.SimpleItem item with Name=[ITEMNAME] and // Value with type is equal to [TYPE]. BeginStep("Validate messages"); XmlNamespaceManager manager = CreateNamespaceManager(notifications.First().Value.OwnerDocument); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.Data = data.SelectedToken; settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; foreach (NotificationMessageHolderType m in notifications.Keys) { bool local = validateMessageFunction(m, settings, logger); ok = ok && local; } if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); }, () => { Operator.HideMessage(); //Operator.HideDoorSelectionMessage(); }); }