public static void ValidateSubscription(DateTime?terminationTime, DateTime currentTime,
                                                int requestedTerminationTime, Event.EndpointReferenceType subscription,
                                                AssertDelegate assert)
        {
            assert(terminationTime.HasValue, "TerminationTime is not specified",
                   "Check that TerminationTime is specified", null);
            if (requestedTerminationTime >= 0)
            {
                assert(currentTime.AddSeconds(requestedTerminationTime) <= terminationTime.Value,
                       "TerminationTime < CurrentTime + InitialTerminationTime",
                       "Validate CurrentTime and TerminationTime", null);
            }
            else
            {
                assert(currentTime < terminationTime.Value,
                       "TerminationTime <= CurrentTime",
                       "Validate CurrentTime and TerminationTime", null);
            }

            assert(subscription != null, "The DUT did not return SubscriptionReference",
                   "Check if the DUT returned SubscriptionReference", null);

            assert(subscription.Address != null && subscription.Address.Value != null,
                   "SubscriptionReference does not contain address",
                   "Check if SubscriptionReference contains address", null);

            assert(subscription.Address.Value.IsValidUrl(), "URL passed in SubscriptionReference is not valid",
                   "Check that URL specified is valid", null);
        }
        // todo unify with accesscontrol
        NotificationMessageHolderType[] MyReceiveMessagesNotify(
            Action action,
            int timeout,
            TestTool.Proxies.Event.FilterType filter,
            XmlDocument doc
            )
        {
            NotificationMessageHolderType[] NotificationMessage;
            System.DateTime       subscribeStarted      = System.DateTime.MaxValue;
            EndpointReferenceType subscriptionReference = null;
            Notify notify = null;

            try
            {
                subscriptionReference =
                    ReceiveMessages(filter,
                                    timeout,
                                    action,
                                    doc,
                                    out notify,
                                    out subscribeStarted);
                NotificationMessage = notify.NotificationMessage;
            }
            finally
            {
                Operator.HideMessage();
                ReleaseSubscription(subscribeStarted, subscriptionReference, timeout);
            }
            return(NotificationMessage);
        }
Example #3
0
 protected void AttachAddressing(System.ServiceModel.Description.ServiceEndpoint endpoint,
                                 TestTool.Proxies.Event.EndpointReferenceType endpointReference)
 {
     if (endpointReference.ReferenceParameters != null && endpointReference.ReferenceParameters.Any != null)
     {
         Utils.EndpointReferenceBehaviour behaviour = new EndpointReferenceBehaviour(endpointReference);
         endpoint.Behaviors.Add(behaviour);
     }
 }
Example #4
0
        /// <summary>
        /// Common event test
        /// </summary>
        /// <param name="topicInfo">Topic to be tested</param>
        /// <param name="validateTopic">Method of topic validation</param>
        /// <param name="getDataForValidation">Method for getting additional data for message validation</param>
        /// <param name="validateMessageFunction">Method for message validation</param>
        void CommonEventTest(TopicInfo topicInfo,
                             Action <XmlElement, TopicInfo> validateTopic,
                             Func <object> getDataForValidation,
                             ValidateMessageFunction validateMessageFunction)
        {
            EndpointReferenceType subscriptionReference = null;

            System.DateTime subscribeStarted = System.DateTime.MaxValue;

            int timeout = 60;

            RunTest(
                () =>
            {
                // Get topic description from the DUT.
                XmlElement topicElement = GetTopicElement(topicInfo);

                Assert(topicElement != null,
                       string.Format("Topic {0} not supported", topicInfo.GetDescription()),
                       "Check that the event topic is supported");


                object data = getDataForValidation();

                // Validate topic
                XmlElement messageDescription = topicElement.GetMessageDescription();
                validateTopic(messageDescription, topicInfo);

                // Create filter for test

                FilterInfo filter = CreateFilter(topicInfo, messageDescription);

                // subscribe
                XmlDocument doc       = new XmlDocument();
                Notify notify         = null;
                subscriptionReference = ReceiveMessages(filter, timeout, doc, out notify, out subscribeStarted);

                if (notify != null)
                {
                    ValidateMessages(notify.NotificationMessage, doc, topicInfo, data, validateMessageFunction);
                }
            },
                () =>
            {
                if (subscribeStarted != System.DateTime.MaxValue)
                {
                    if (subscriptionReference != null && _subscriptionManagerClient == null)
                    {
                        CreateSubscriptionManagerClient(subscriptionReference);
                    }
                    TimeSpan diff   = System.DateTime.Now - subscribeStarted;
                    int releaseTime = timeout * 1000 - (int)diff.TotalMilliseconds;
                    ReleaseSubscriptionManager(releaseTime);
                }
            });
        }
Example #5
0
        public static void ValidateSubscription(DateTime?terminationTime, DateTime currentTime,
                                                int requestedTerminationTime, Event.EndpointReferenceType subscription,
                                                AssertDelegate assert)
        {
            assert(terminationTime.HasValue, "TerminationTime is not specified",
                   "Check that TerminationTime is specified", null);

            bool intervalIsWrong = false;

            if (currentTime < DateTime.Parse("1970-01-01T00:00:00"))
            {
                intervalIsWrong = true;
            }

            if (currentTime > DateTime.Parse("2070-01-01T00:00:00"))
            {
                intervalIsWrong = true;
            }

            if (terminationTime.Value < DateTime.Parse("1970-01-01T00:00:00"))
            {
                intervalIsWrong = true;
            }

            if (terminationTime.Value > DateTime.Parse("2070-01-01T00:00:00"))
            {
                intervalIsWrong = true;
            }

            assert(!intervalIsWrong, "TerminationTime or CurrentTime is out of reasonable interval (less than 1970-01-01T00:00:00 or greater than 2070-01-01T00:00:00).",
                   "Check that TerminationTime and CurrentTime has reasonable values", null);

            if (requestedTerminationTime >= 0)
            {
                assert(currentTime.AddSeconds(requestedTerminationTime) <= terminationTime.Value,
                       "TerminationTime < CurrentTime + InitialTerminationTime",
                       "Validate CurrentTime and TerminationTime", null);
            }
            else
            {
                assert(currentTime < terminationTime.Value,
                       "TerminationTime <= CurrentTime",
                       "Validate CurrentTime and TerminationTime", null);
            }

            assert(subscription != null, "The DUT did not return SubscriptionReference",
                   "Check if the DUT returned SubscriptionReference", null);

            assert(subscription.Address != null && subscription.Address.Value != null,
                   "SubscriptionReference does not contain address",
                   "Check if SubscriptionReference contains address", null);

            assert(subscription.Address.Value.IsValidUrl(), "URL passed in SubscriptionReference is not valid",
                   "Check that URL specified is valid", null);
        }
Example #6
0
        public static EndpointReferenceType CreatePullPointSubscription(this IEventService s, FilterType Filter, string InitialTerminationTime, CreatePullPointSubscriptionSubscriptionPolicy SubscriptionPolicy, ref System.Xml.XmlElement[] Any, out System.DateTime CurrentTime, out DateTime?TerminationTime)
        {
            s.InitializeGuard();

            EndpointReferenceType r = null;

            XmlElement[]    localAny             = Any;
            System.DateTime localCurrentTime     = System.DateTime.MinValue;
            System.DateTime?localTerminationTime = null;

            s.Test.RunStep(() => r = s.ServiceClient.Port.CreatePullPointSubscription(Filter, InitialTerminationTime, SubscriptionPolicy, ref localAny, out localCurrentTime, out localTerminationTime), "Get Service Capabilities(Event)");
            CurrentTime            = localCurrentTime;
            TerminationTime        = localTerminationTime;

            return(r);
        }
        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);
            });
        }
        //[04.03.2013] AKS: added parameter message limit and functionality to check if number of notifications in response to PullMessages command
        //exceeds messageLimit
        protected NotificationMessageHolderType[] ReceiveMessagesPullPointFirstMessage(
            Action action,
            TestTool.Proxies.Event.FilterType filter,
            int messageLimit,
            XmlDocument doc)
        {
            EndpointReferenceType subscriptionReference = null;

            int timeout = _eventSubscriptionTimeout;
            int actualTerminationTime = timeout;

            System.DateTime subscribeStarted = System.DateTime.Now;
            NotificationMessageHolderType[] NotificationMessage = null;
            System.DateTime pullingDeadline         = System.DateTime.Now.AddSeconds(_operationDelay / 1000.0);
            System.DateTime TerminationExpectedTime = System.DateTime.Now.AddSeconds(timeout);
            try
            {
                actualTerminationTime = timeout;
                subscriptionReference = CreateStandardSubscription(filter, ref actualTerminationTime);

                Assert(null != subscriptionReference,
                       "Can't create pullpoint subscription",
                       "Check subscription result");

                /*if (subscriptionReference == null)
                 * {
                 *  goto ready;
                 * }*/
                CreatePullPointSubscriptionClient(subscriptionReference);

                string dump;
                //Operator.ShowMessage(message);
                action();
                int terminationTimeSeconds = 60;
                do
                {
                    DoRenewBeforePull(ref terminationTimeSeconds, ref TerminationExpectedTime);

                    NotificationMessage = GetMessages(subscriptionReference, false, true, false, 1, out dump);
                    if (System.DateTime.Now > pullingDeadline)
                    {
                        break;
                    }
                    if (NotificationMessage == null)
                    {
                        break;
                    }
                }while ((NotificationMessage != null) && (NotificationMessage.Length == 0));

                if ((NotificationMessage != null) && (NotificationMessage.Length == 0))
                {
                    NotificationMessage = null;
                }
                if (NotificationMessage != null)
                {
                    doc.LoadXml(dump);
                }
            }
            catch (Exception exc)
            {
                StepFailed(exc);
            }
            finally
            {
                Operator.HideMessage();
            }
ready:
            try
            {
                Assert(null != NotificationMessage && 0 != NotificationMessage.Length,
                       "No valid notification messages received",
                       "Check that DUT sent valid notification messages");

                //[04.03.2013] AKS: check if number of notifications in response to PullMessages command exceeds messageLimit
                Assert(null != NotificationMessage && messageLimit >= NotificationMessage.Length,
                       "Maximum number of messages exceeded",
                       string.Format("Check that DUT sent not more than {0} message(s)", messageLimit));
            }
            finally
            {
                ReleaseSubscription(subscribeStarted, subscriptionReference, TerminationExpectedTime);
            }
            return(NotificationMessage);
        }