void ConfigurationEventTest( TopicInfo topicInfo, Action <XmlElement, TopicInfo> validateTopic, ValidateConfigurationMessageFunction validateMessageFunction, string sourceTokenSimpleItem, Action <string> validateConfigurationFunction) { EndpointReferenceType subscriptionReference = null; System.DateTime subscribeStarted = System.DateTime.MaxValue; int timeout = 60; RunTest( () => { // Get topic description from the DUT. XmlElement topicElement = GetTopicElement(topicInfo); BeginStep("Check if the event topic is supported"); if (topicElement == null) { LogStepEvent(string.Format("Topic {0} not supported", topicInfo.GetDescription())); } StepPassed(); if (topicElement == null) { return; } XmlElement messageDescription = topicElement.GetMessageDescription(); validateTopic(messageDescription, topicInfo); // filter for current test TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); string message = string.Format("{0} event is expected!", topicInfo.GetDescription()); Notify notify = null; XmlDocument doc = new XmlDocument(); try { subscriptionReference = ReceiveMessages(filter, timeout, () => Operator.ShowMessage(message), doc, out notify, out subscribeStarted); } finally { Operator.HideMessage(); } Assert(notify.NotificationMessage.Length == 1, string.Format("{0} messages received - unable to check actual configuration", notify.NotificationMessage.Length), "Check that exactly one notification is received"); BeginStep("Validate message"); XmlNamespaceManager manager = CreateNamespaceManager(doc); Dictionary <NotificationMessageHolderType, XmlElement> notifications = GetRawElements(notify.NotificationMessage, doc, manager, true); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; NotificationMessageHolderType m = notify.NotificationMessage[0]; ok = validateMessageFunction(m, notifications[m], manager, logger); if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); // validateMessageFunction should return false, if this simple item is missing string token = m.Message.GetMessageSourceSimpleItems()[sourceTokenSimpleItem]; validateConfigurationFunction(token); }, () => { Operator.HideMessage(); ReleaseSubscription(subscribeStarted, subscriptionReference, timeout); }); }
void ConfigurationEventTestBis( TopicInfo topicInfo, Action <XmlElement, TopicInfo> validateTopic, ValidateConfigurationMessageFunction validateMessageFunction, string sourceTokenSimpleItem, Action <string> validateConfigurationFunction) { int actualTerminationTime = 60; if (_eventSubscriptionTimeout != 0) { actualTerminationTime = _eventSubscriptionTimeout; } int timeout = _operationDelay / 1000; RunTest( () => { // Get topic description from the DUT. XmlElement topicElement = GetTopicElement(topicInfo); Assert(null != topicElement, string.Format("Topic {0} not supported", topicInfo.GetDescription()), "Check if the event topic is supported"); XmlElement messageDescription = topicElement.GetMessageDescription(); validateTopic(messageDescription, topicInfo); // filter for current test TestTool.Proxies.Event.FilterType filter = CreateSubscriptionFilter(topicInfo); string message = string.Format("{0} event is expected!", topicInfo.GetDescription()); bool UseNotify = UseNotifyToGetEvents; Dictionary <NotificationMessageHolderType, XmlElement> notifications = null; SubscriptionHandler Handler = null; try { Handler = new SubscriptionHandler(this, UseNotify, GetEventServiceAddress()); Handler.Subscribe(filter, actualTerminationTime); Operator.ShowMessage(message); var pullingCondition = new SubscriptionHandler.WaitFirstNotificationPollingCondition(timeout); Handler.WaitMessages(1, pullingCondition, out notifications); } finally { Operator.HideMessage(); SubscriptionHandler.Unsubscribe(Handler); } Assert(null != notifications && notifications.Any(), string.Format("No notification messages are received.{0}WARNING: may be Operation delay is too low", Environment.NewLine), "Check that DUT sent any notification messages"); Assert(notifications.Count == 1, string.Format("{0} messages received - unable to check actual configuration", notifications.Count), "Check that exactly one notification is received"); BeginStep("Validate message"); XmlNamespaceManager manager = CreateNamespaceManager(notifications.First().Value.OwnerDocument); StringBuilder logger = new StringBuilder(); bool ok = true; MessageCheckSettings settings = new MessageCheckSettings(); settings.ExpectedTopic = topicInfo; settings.RawMessageElements = notifications; settings.NamespaceManager = manager; NotificationMessageHolderType m = notifications.Keys.First(); ok = validateMessageFunction(m, notifications[m], manager, logger); if (!ok) { throw new AssertException(logger.ToStringTrimNewLine()); } StepPassed(); // validateMessageFunction should return false, if this simple item is missing string token = m.Message.GetMessageSourceSimpleItems()[sourceTokenSimpleItem]; validateConfigurationFunction(token); }, () => { }); }