Esempio n. 1
0
        protected override void VerifyEntry(XmlNode entry)
        {
            XmlNodeList categoryNodes = entry.SelectNodes("atom:category", this.FormatVerifier.XmlNamespaceManager);

            foreach (XmlNode categoryNode in categoryNodes)
            {
                XmlAttribute termAttrib = categoryNode.Attributes["term"];
                if (termAttrib == null)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("No term attribute found for Category node"));
                }

                /*else
                 * {
                 *  bool typeFound = false;
                 *  foreach (NodeType nodeType in _formatVerifier.Request.Workspace.Types.Where(t => t.ClrType.FullName == termAttrib.Value))
                 *  {
                 *      typeFound = true;
                 *      break;
                 *  }
                 *
                 *  if( !typeFound )
                 *      AstoriaTestLog.FailAndContinue(new TestFailedException("term attribute value (" + termAttrib.Value + ")is not valid type"));
                 * }*/
            }
        }
Esempio n. 2
0
 internal static Workspaces GetWorkspacesFilteredByTestProperties(Action <Workspace> beforeWorkspaceCreate)
 {
     if (_workspaceCreationFailed)
     {
         throw new TestFailedException("Workspaces failed on creation previously");
     }
     if (_filteredWorkspaces == null)
     {
         try
         {
             _filteredWorkspaces = CreateFilteredWorkspaces(AstoriaTestProperties.DataLayerProviderKinds, AstoriaTestProperties.MaxPriority, true, beforeWorkspaceCreate);
         }
         catch (System.Reflection.ReflectionTypeLoadException typeloadException)
         {
             _workspaceCreationFailed = true;
             AstoriaTestLog.WriteLine("LoaderExceptions:");
             foreach (Exception exc in typeloadException.LoaderExceptions)
             {
                 AstoriaTestLog.FailAndContinue(exc);
             }
             throw typeloadException;
         }
         catch (Exception exc)
         {
             _workspaceCreationFailed = true;
             throw;
         }
     }
     return(_filteredWorkspaces);
 }
Esempio n. 3
0
        protected override void VerifyEntry(XmlNode entry)
        {
            //TODO: Astoria always returns type="application/xml" so this section is incomplete wrt spec and assunes xml content

            XmlNodeList contentNodes = entry.SelectNodes("atom:content", this.FormatVerifier.XmlNamespaceManager);

            if (contentNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.3 Content element: is missing"));
            }
            else
            {
                XmlNode contentNode = contentNodes[0];

                bool srcFound = contentNode.Attributes["src"] != null;

                if (contentNode.Attributes["type"] != null && contentNode.Attributes["type"].Value != "application/xml")
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.3 Content element: type is not 'application/xml' (only supported value in v1 astoria)"));
                }

                if (contentNode.ChildNodes.Count != 1 && !srcFound)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.3.3 Content element: More than node found for conent root node."));
                }
            }
        }
Esempio n. 4
0
        public void VerifyClient(QueryModel qm)
        {
            WebDataCtxWrapper ctx = new WebDataCtxWrapper(new Uri(qm.Workspace.ServiceUri));

            ctx.Credentials = CredentialCache.DefaultNetworkCredentials;

            try
            {
                UriQueryBuilder ub   = new UriQueryBuilder(qm.Workspace, "");
                string          ruri = ub.Build(qm.QueryResult);

                string uriRel = ruri.Substring(ruri.LastIndexOf(".svc/") + 5);

                if ((ctx.BaseUri + "/" + uriRel).Length > 260)
                {
                    return;
                }
                AstoriaTestLog.WriteLineIgnore(ctx.BaseUri + "/" + uriRel);

                ResolveClientType(qm.Workspace, ctx, qm.ResultType);

                object enumerable = ExecuteQuery(ctx, qm.ResultType, uriRel, "sync");
                Verify(qm.Workspace, qm.QueryResult, (IEnumerable)enumerable, qm.ResType, null, qm.IsCount);
            }
            catch (Exception e)
            {
                AstoriaTestLog.FailAndContinue(e);
            }
        }
Esempio n. 5
0
        public virtual void CompareSingleValue(object expected, bool stripQuotes, bool valueUri)
        {
            if (this.Resources == null && expected == null)
            {
                return;
            }

            PayloadSimpleProperty simpleProperty = this.Resources as PayloadSimpleProperty;

            if (simpleProperty == null)
            {
                AstoriaTestLog.FailAndThrow("Payload did not represent a single value");
            }

            if (expected == null)
            {
                if (!simpleProperty.IsNull)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("Compare failed - Expected: null, got: " + simpleProperty.Value));
                }
            }
            else
            {
                ComparePrimitiveValuesObjectAndString(expected, expected.GetType(), simpleProperty.Value, valueUri, this.Format, false);
            }
        }
Esempio n. 6
0
        public void Verify(string payload)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(payload);

            XmlNode authorNode = xmlDocument.SelectNodes("atom:author", _formatVerifier.XmlNamespaceManager)[0];

            // atom:author elements MUST contain exactly one atom:name element.
            XmlNodeList childNodes = authorNode.SelectNodes("atom:name", _formatVerifier.XmlNamespaceManager);

            if (childNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("3.2.1 atomPersonConstruct element: Not exactly 1 name node found for atomPersonConstruct."));
            }

            // atom:author elements MAY contain exactly one atom:uri element.
            childNodes = authorNode.SelectNodes("atom:uri", _formatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("3.2.1 atomPersonConstruct element: Greater than 1 uri node found for atomPersonConstruct."));
            }

            // atom:author elements MAY contain exactly one atom:email element.
            childNodes = authorNode.SelectNodes("atom:email", _formatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("3.2.1 atomPersonConstruct element: Greater than 1 email node found for atomPersonConstruct."));
            }
        }
Esempio n. 7
0
 public void VerifyClientLinq(QueryModel qm)
 {
     try
     {
         ExecuteLinq(qm.Workspace, qm.QueryResult, qm.ResContainer);
     }
     catch (Exception e)
     {
         AstoriaTestLog.FailAndContinue(e);
     }
 }
Esempio n. 8
0
 public static void ExecuteLinq(Workspace workspace, ExpNode q, ResourceContainer container)
 {
     try
     {
         ExecuteLinq(workspace, q, container, false, null);
     }
     catch (Exception e)
     {
         AstoriaTestLog.FailAndContinue(e);
     }
 }
Esempio n. 9
0
        public void Verify(AstoriaResponse response)
        {
            //AstoriaTestLog.TraceInfo(payload);

            try
            {
                JSONPayload jsonPayload = new JSONPayload(response);
            }
            catch (Exception e)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("Failed to parse JSON payload : " + e.ToString()));
            }
            //AstoriaTestLog.TraceInfo(jsonPayload.ToString());

            return;
        }
Esempio n. 10
0
        protected override void VerifyEntry(XmlNode entry)
        {
            // author contains one atomPersonConstruct - verify this

            XmlNodeList authorNodes = entry.SelectNodes("atom:author", this.FormatVerifier.XmlNamespaceManager);

            if (authorNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.3 Author element: count is not exactly 1"));
            }
            else
            {
                XmlNode authorNode = authorNodes[0];

                AtomPersonConstructVerifier atomPersonConstructVerifier = new AtomPersonConstructVerifier(this.FormatVerifier);
                atomPersonConstructVerifier.Verify(authorNode.OuterXml);
            }
        }
Esempio n. 11
0
        public static void VerifyLinq(Workspace workspace, ExpNode q, IQueryable results)
        {
            //verify if the results are ok before building the URI
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            foreach (object element in results)
            {
                list.Add(element);
            }


            //UriQueryBuilder ub = new UriQueryBuilder(workspace, "");
            // string ruri = ub.Build(q);

            //System.Uri uri = new Uri(workspace.ServiceUri);
            // string uriRel = ruri.Substring(ruri.IndexOf("/") + 1);
            // AstoriaTestLog.WriteLineIgnore(uri.ToString() + uriRel);

            AstoriaRequest request = workspace.CreateRequest(q);

            request.Format = SerializationFormatKind.Atom;

            try
            {
                AstoriaResponse response = request.GetResponse();
                //response.VerifyHttpStatusCodeOk(response.StatusCode);

                CommonPayload payload = response.CommonPayload;
                if (payload.Value != null)
                {
                    payload.CompareValue(results, false, false);
                }
                else
                {
                    payload.Compare(results);
                }

                //AstoriaTestLog.AreEqual(response.ContentType, SerializationFormatKinds.ContentTypeFromKind(response.OriginalRequest.SerializationKind),
                //"Content-Type does not match Accept header request");
            }
            catch (Exception e)
            {
                AstoriaTestLog.FailAndContinue(e);
            }
        }
Esempio n. 12
0
        protected override void VerifyEntry(XmlNode entry)
        {
            XmlNodeList linkNodes = entry.SelectNodes("atom:link", this.FormatVerifier.XmlNamespaceManager);

            foreach (XmlNode linkNode in linkNodes)
            {
                XmlAttribute hrefAttrib = linkNode.Attributes["href"];
                if (hrefAttrib == null)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.7.1: No href attribute found for link element"));
                }

                XmlAttribute relAttrib = linkNode.Attributes["rel"];
                if (relAttrib != null)
                {
                    if (relAttrib.Value != "self" && relAttrib.Value != "edit" && !relAttrib.Value.Contains("http:"))
                    {
                        AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.7.2: wrong value for rel attrib of link element."));
                    }
                }
            }
        }
Esempio n. 13
0
        protected override void VerifyEntry(XmlNode entry)
        {
            XmlNodeList titleNodes = entry.SelectNodes("atom:title", this.FormatVerifier.XmlNamespaceManager);

            if (titleNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.14 Title Element: More than 1 element"));
            }

            else if (titleNodes.Count == 1)
            {
                XmlNode titleNode = titleNodes[0];

                XmlAttribute typeAttrib = titleNode.Attributes["type"];
                if (typeAttrib != null)
                {
                    if (typeAttrib.Value != "text" && typeAttrib.Value != "xhtml" && typeAttrib.Value != "html")
                    {
                        AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.14: Title element has invalid type value"));
                    }
                }
            }
        }
Esempio n. 14
0
        public static void LogFailure(AstoriaResponse response, Exception ex, bool shouldThrow)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Response verification failed");
            builder.AppendLine("----------------------------------------");
            response.Request.LogRequest(builder, true, true);
            builder.AppendLine("----------------------------------------");
            response.LogResponse(builder, true, true);
            builder.AppendLine("----------------------------------------");

            string log = builder.ToString();

            ex = new TestFailedException(log, null, null, ex);
            if (shouldThrow)
            {
                throw ex;
            }
            else
            {
                AstoriaTestLog.FailAndContinue(ex);
            }
        }
Esempio n. 15
0
        protected override void VerifyEntry(XmlNode entry)
        {
            XmlNodeList updatedNodes = entry.SelectNodes("atom:updated", this.FormatVerifier.XmlNamespaceManager);

            if (updatedNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.15 Updated Element: More than 1 element"));
            }

            else if (updatedNodes.Count == 1)
            {
                XmlNode updatedNode = updatedNodes[0];

                string dateValue = updatedNode.InnerXml;
                try
                {
                    DateTime d = XmlConvert.ToDateTime(dateValue, XmlDateTimeSerializationMode.Unspecified);
                }
                catch
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.2.15 Updated Element: invalid date format."));
                }
            }
        }
Esempio n. 16
0
        public virtual void ForEachResourceType(Action <ResourceType, ResourceContainer, Workspace> someAction, bool workspaceShouldUpdate)
        {
            Func <ResourceType, bool> typeHasConcurrencyTokens = (resourceType) =>
            {
                bool hasConcurrencyTokens = false;
                foreach (ResourceProperty property in resourceType.Properties.OfType <ResourceProperty>())
                {
                    if (property.Facets.ConcurrencyMode == ConcurrencyMode.Fixed)
                    {
                        hasConcurrencyTokens = true;
                        break;
                    }
                }
                return(hasConcurrencyTokens);
            };

            foreach (Workspace workspace in this)
            {
                bool doneProcessing = false;
                DataServiceMetadata.LoadServiceMetadata(workspace.ServiceUri);
                if (workspaceShouldUpdate && !workspace.Settings.SupportsUpdate)
                {
                    throw (new TestSkippedException("Workspace does not support updating"));
                }
                foreach (ResourceContainer container in workspace.ServiceContainer.ResourceContainers)
                {
                    foreach (ResourceType resourceType in
                             container.ResourceTypes.Where(rType => (!workspaceShouldUpdate || rType.IsInsertable) && typeHasConcurrencyTokens(rType)))
                    {
                        try
                        {
                            //Filter only types which have base types , if required
                            if (!SkipType(resourceType, workspaceShouldUpdate))
                            {
                                doneProcessing = true;
                                someAction(resourceType, container, workspace);
                            }
                        }
                        catch (OptimisticConcurrencyException oException)
                        {
                            throw oException;
                        }
                        catch (Exception exception)
                        {
                            if (!(exception is OptimisticConcurrencyException))
                            {
                                AstoriaTestLog.FailAndContinue(exception);
                            }
                        }
                        if (doneProcessing)
                        {
                            break;
                        }
                    }
                    if (doneProcessing)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 17
0
        private static string ParseResponseErrorXML(AstoriaResponse response, bool inStream)
        {
            string payloadString = response.Payload;

            ServiceError serviceError = new ServiceError();

            XmlNode error = null;

            if (inStream)
            {
                Match match = XmlInStreamErrorRegex.Match(payloadString);
                if (!match.Success)
                {
                    AstoriaTestLog.TraceLine(payloadString);
                    AstoriaTestLog.FailAndThrow("Payload did not contain expected in-stream error");
                }
                payloadString = match.Groups[1].Value;

                // if there was a namespace prefix, we need to inject a wrapping element with the namespace defined
                //
                if (!string.IsNullOrEmpty(match.Groups[2].Value))
                {
                    payloadString = "<wrapper xmlns:" + match.Groups[2].Value + "=\"" + AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace + "\">" +
                                    payloadString +
                                    "</wrapper>";
                }
                else
                {
                    // just for consistency later when we pull out the <error> tag
                    //
                    payloadString = "<wrapper>" + payloadString + "</wrapper>";
                }
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return(null);
                }

                // pull out the <error> tag, assuming that there is a <wrapper> tag around it
                //
                error = xmlDoc.FirstChild.FirstChild;
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return(null);
                }

                error = xmlDoc.FirstChild.NextSibling;
            }

            if (error != null)
            {
                XmlNode code       = error.FirstChild;
                XmlNode message    = code.NextSibling;
                XmlNode innerError = message.NextSibling;

                serviceError.code    = code.InnerXml;
                serviceError.message = message.InnerXml;
                if (message.Attributes["xml:lang"] != null)
                {
                    serviceError.language = message.Attributes["xml:lang"].Value;
                }
                else
                {
                    serviceError.language = null;
                }

                if (innerError != null)
                {
                    XmlNode innerMessage    = null;
                    XmlNode innerType       = null;
                    XmlNode innerStackTrace = null;

                    innerMessage = innerError.FirstChild;
                    if (innerMessage != null)
                    {
                        serviceError.InnerServiceError.message = innerMessage.InnerXml;
                        innerType = innerMessage.NextSibling;
                        if (innerType != null)
                        {
                            serviceError.InnerServiceError.type = innerType.InnerXml;
                            innerStackTrace = innerType.NextSibling;
                            if (innerStackTrace != null)
                            {
                                serviceError.InnerServiceError.stacktrace = innerStackTrace.InnerXml;
                            }
                        }
                    }
                }
            }

            return(serviceError.message);
        }
Esempio n. 18
0
        public void Verify(AstoriaResponse response)
        {
            string payload = response.Payload;

            XmlNodeList childNodes = null;

            XmlNode xmlData = FormatVerifyUtils.FindFirstChild(payload);

            if (xmlData.Name == "feed")
            {
                /* atom:feed elements MUST contain one or more atom:author elements,
                 *  unless all of the atom:feed element's child atom:entry elements
                 *  contain at least one atom:author element.
                 */
                childNodes = xmlData.SelectNodes("atom:author", _formatVerifier.XmlNamespaceManager);
                XmlNodeList entries = xmlData.SelectNodes("atom:entry", _formatVerifier.XmlNamespaceManager);

                if (childNodes.Count == 0)
                {
                    if (entries.Count > 0)
                    {
                        foreach (XmlNode node in entries)
                        {
                            XmlNode authorNode = node.SelectSingleNode("atom:author[1]", _formatVerifier.XmlNamespaceManager);
                            if (authorNode == null)
                            {
                                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: No author node in entry of feed without author node."));
                            }
                        }
                    }
                    else
                    {
                        AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: No author node in feed with no entries."));
                    }
                }

                // atom:feed elements MUST NOT contain more than one atom:generator element.
                childNodes = xmlData.SelectNodes("atom:generator", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count > 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 generator node found for feed."));
                }

                // atom:feed elements MUST NOT contain more than one atom:icon element.
                childNodes = xmlData.SelectNodes("atom:icon", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count > 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 icon node found for feed."));
                }

                // atom:feed elements MUST NOT contain more than one atom:logo element.
                childNodes = xmlData.SelectNodes("atom:logo", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count > 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 logo node found for feed."));
                }

                // atom:feed elements MUST contain exactly one atom:id element
                childNodes = xmlData.SelectNodes("atom:id", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count != 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 id node found for feed."));
                }

                /* atom:feed elements SHOULD contain one atom:link element with a rel
                 *  attribute value of "self".  This is the preferred URI for
                 *  retrieving Atom Feed Documents representing this Atom feed.
                 *
                 * atom:feed elements MUST NOT contain more than one atom:link
                 *  element with a rel attribute value of "alternate" that has the
                 *  same combination of type and hreflang attribute values.
                 */
                int selfLinkCount = 0, altLinkCount = 0;
                childNodes = xmlData.SelectNodes("atom:link", _formatVerifier.XmlNamespaceManager);
                foreach (XmlNode node in childNodes)
                {
                    if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "self")
                    {
                        selfLinkCount++;
                    }
                    else if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "alternate")
                    {
                        altLinkCount++;
                    }
                }

                AstoriaTestLog.AreEqual(1, selfLinkCount, "4.1.1 Feed element: Not exactly 1 self link node found for feed");
                AstoriaTestLog.AreEqual(false, altLinkCount > 1, "4.1.1 Feed element: More than 1 alternate link node found for feed");

                // atom:feed elements MUST NOT contain more than one atom:rights element.
                childNodes = xmlData.SelectNodes("atom:rights", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count > 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 rights node found for feed."));
                }

                // atom:feed elements MUST NOT contain more than one atom:subtitle element.
                childNodes = xmlData.SelectNodes("atom:subtitle", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count > 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: More than 1 subtitle node found for feed."));
                }

                // atom:feed elements MUST contain exactly one atom:title element.
                childNodes = xmlData.SelectNodes("atom:title", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count != 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 title node found for feed."));
                }

                // atom:feed elements MUST contain exactly one atom:updated element.
                childNodes = xmlData.SelectNodes("atom:updated", _formatVerifier.XmlNamespaceManager);
                if (childNodes.Count != 1)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.1 Feed element: Not exactly 1 updated node found for feed."));
                }
            }
        }
Esempio n. 19
0
        protected override void VerifyEntry(XmlNode entry)
        {
            XmlNodeList childNodes = null;

            /* atom:entry elements MUST contain one or more atom:author elements,
             *  unless the atom:entry contains an atom:source element that
             *  contains an atom:author element or, in an Atom Feed Document, the
             *  atom:feed element contains an atom:author element itself.
             */
            childNodes = entry.SelectNodes("atom:author", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count == 0)
            {
                bool        authorFound = false;
                XmlNodeList sources     = entry.SelectNodes("atom:source", this.FormatVerifier.XmlNamespaceManager);
                if (sources.Count == 1)
                {
                    XmlNodeList authors = sources[0].SelectNodes("atom:author", this.FormatVerifier.XmlNamespaceManager);
                    if (authors.Count != 0)
                    {
                        authorFound = true;
                    }
                }

                if (!authorFound)
                {
                    XmlNode parent = entry.ParentNode;

                    if (parent.Name == "feed")
                    {
                        XmlNodeList authors = parent.SelectNodes("atom:author", this.FormatVerifier.XmlNamespaceManager);
                        if (authors.Count != 0)
                        {
                            authorFound = true;
                        }
                    }
                }

                if (!authorFound)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: No author element found for entry"));
                }
            }

            // atom:entry elements MUST NOT contain more than one atom:content element.
            childNodes = entry.SelectNodes("atom:content", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: More than 1 content node found for entry."));
            }

            // atom:entry elements MUST contain exactly one atom:id element.
            childNodes = entry.SelectNodes("atom:id", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: Not exactly 1 id node found for entry."));
            }

            /* atom:entry elements that contain no child atom:content element
             *  MUST contain at least one atom:link element with a rel attribute
             *  value of "alternate".
             */
            childNodes = entry.SelectNodes("atom:content", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count == 0)
            {
                bool relAltAttribFound = false;

                childNodes = entry.SelectNodes("atom:link", this.FormatVerifier.XmlNamespaceManager);
                foreach (XmlNode node in childNodes)
                {
                    if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "alternate")
                    {
                        relAltAttribFound = true;
                    }
                }

                if (!relAltAttribFound)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: No link node with rel='alternate' found for entry with no content."));
                }
            }

            /*  atom:entry elements MUST NOT contain more than one atom:link
             *  element with a rel attribute value of "alternate" that has the
             *  same combination of type and hreflang attribute values.
             */
            childNodes = entry.SelectNodes("atom:link", this.FormatVerifier.XmlNamespaceManager);

            int relAltLinkCount = 0;

            foreach (XmlNode node in childNodes)
            {
                if (node.Attributes["rel"] != null && node.Attributes["rel"].Value == "alternate")
                {
                    relAltLinkCount++;
                }
            }

            if (relAltLinkCount > 1)
            {
                //TODO: track and compare type and hreflang attribs
            }

            // atom:entry elements MUST NOT contain more than one atom:published element.
            childNodes = entry.SelectNodes("atom:published", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: More than 1 published node found for entry."));
            }

            // atom:entry elements MUST NOT contain more than one atom:rights element.
            childNodes = entry.SelectNodes("atom:rights", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: More than 1 rights node found for entry."));
            }

            // atom:entry elements MUST NOT contain more than one atom:source element.
            childNodes = entry.SelectNodes("atom:source", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: More than 1 source node found for entry."));
            }

            /*  atom:entry elements MUST contain an atom:summary element in either
             *  of the following cases:
             *      -  the atom:entry contains an atom:content that has a "src"
             *          attribute (and is thus empty).
             *      -  the atom:entry contains content that is encoded in Base64;
             *          i.e., the "type" attribute of atom:content is a MIME media type
             *          but is not an XML media type [<a href="./rfc3023" title='"XML Media Types"'>RFC3023</a>], does not
             *          begin with "text/", and does not end with "/xml" or "+xml".
             */
            bool contentWithSrcFound = false, contentWithBase64Found = false;

            childNodes = entry.SelectNodes("atom:content", this.FormatVerifier.XmlNamespaceManager);
            foreach (XmlNode node in childNodes)
            {
                if (node.Attributes["src"] != null)
                {
                    contentWithSrcFound = true;
                    break;
                }
            }

            childNodes = entry.SelectNodes("atom:content", this.FormatVerifier.XmlNamespaceManager);
            foreach (XmlNode node in childNodes)
            {
                if (node.Attributes["type"] != null && !(node.Attributes["type"].Value.EndsWith("/xml") ||
                                                         node.Attributes["type"].Value.EndsWith("+xml") || node.Attributes["type"].Value.StartsWith("text/")))
                {
                    contentWithBase64Found = true;
                    break;
                }
            }

            if (contentWithSrcFound || contentWithBase64Found)
            {
                XmlNodeList summaryNodes = entry.SelectNodes("atom:summary", this.FormatVerifier.XmlNamespaceManager);
                if (summaryNodes.Count == 0)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: No summary node found with Base64 or src'd content for entry."));
                }
            }

            // atom:entry elements MUST NOT contain more than one atom:summary element.
            childNodes = entry.SelectNodes("atom:summary", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count > 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: More than 1 summary node found for entry."));
            }

            // atom:entry elements MUST contain exactly one atom:title element.
            childNodes = entry.SelectNodes("atom:title", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: Not exactly 1 title node found for entry."));
            }

            // atom:entry elements MUST contain exactly one atom:updated element.
            childNodes = entry.SelectNodes("atom:title", this.FormatVerifier.XmlNamespaceManager);
            if (childNodes.Count != 1)
            {
                AstoriaTestLog.FailAndContinue(new TestFailedException("4.1.2 Entry element: Not exactly 1 updated node found for entry."));
            }
        }
Esempio n. 20
0
        protected override void WorkspaceCallback(Workspace workspace)
        {
            if (workspace.DataLayerProviderKind == DataLayerProviderKind.NonClr)
            {
#if !ClientSKUFramework
                // do this NOW instead of later, so that we can refer to these settings
                (workspace as NonClrWorkspace).DefineClrProperties();
#endif
            }

            Dictionary <string, string[]> tokensMap = new Dictionary <string, string[]>();
            tokensMap.Add("DefectBug", new string[] { "Number" });
            tokensMap.Add("Owner", new string[] { "LastName" });
            tokensMap.Add("Run", new string[] { "Purpose" });
            tokensMap.Add("Task", new string[] { "Deleted", "Investigates" });
            tokensMap.Add("OwnerDetail", new string[] { "Level" });
            tokensMap.Add("ProjectBug", new string[] { "Number" });
            tokensMap.Add("NonDefaultMappings",
                          new string[] { "c_int_AS_decimal", "c_smallint_AS_decimal", "c_smalldatetime_AS_datetime" });
            tokensMap.Add("AllTypes",
                          new string[] { "c2_int", "c3_smallint", "c4_tinyint", "c5_bit", "c6_datetime", "c7_smalldatetime",
                                         "c8_decimal_28_4_", "c9_numeric_28_4_", "c10_real", "c11_float", "c12_money",
                                         "c13_smallmoney", /*"c14_varchar_512_", "c15_char_512_",*/ "c26_smallint",
                                         "c27_tinyint", "c28_bit", "c46_uniqueidentifier", "c47_bigint" });
            tokensMap.Add("Vehicle", new string[] { "Make", "Model", "Year" });
            tokensMap.Add("Test1s", new string[] { "Name" }); // for deep expand where top type has no etag
            tokensMap.Add("Run2s", new string[] { "Name" });
            tokensMap.Add("Student", new string[] { "FirstName", "MiddleName", "LastName", "Major" });
            tokensMap.Add("College", new string[] { "Name", "City", "State" });
            tokensMap.Add("Config", new string[] { "Arch" });
            //tokensMap.Add("DeepTree_C", new string[] { "C_Int" });
            tokensMap.Add("LabOwners", new string[] { "Changed" });

            foreach (ResourceType type in workspace.ServiceContainer.ResourceTypes.Where(rt => rt.Name.StartsWith("DataKey_")))
            {
                tokensMap.Add(type.Name, type.Properties
                              .OfType <ResourceProperty>()
                              .Where(p => p.PrimaryKey == null && !p.IsNavigation && !p.IsComplexType)
                              .Select(p => p.Name)
                              .ToArray());
            }

            foreach (KeyValuePair <string, string[]> pair in tokensMap)
            {
                ResourceType type = workspace.ServiceContainer.ResourceTypes.SingleOrDefault(t => t.Name == pair.Key);
                if (type == null)
                {
                    // look through the basetypes
                    type = workspace.ServiceContainer.ResourceTypes.SingleOrDefault(t => t.BaseType != null && t.BaseType.Name == pair.Key);
                    if (type == null)
                    {
                        AstoriaTestLog.FailAndContinue(new TestWarningException("Could not find type '" + pair.Key + "'"));
                        continue;
                    }
                    type = type.BaseType as ResourceType;
                }

                // ensure that we put the property names in the order they are in the service container
                List <string> propertyNames  = new List <string>();
                List <string> etagProperties = pair.Value.ToList();
                foreach (var property in type.Properties.OfType <ResourceProperty>())
                {
                    var propertyName = property.Name;
                    if (etagProperties.Contains(propertyName))
                    {
                        propertyNames.Add(propertyName);
                        etagProperties.Remove(propertyName);

                        if (workspace.DataLayerProviderKind == DataLayerProviderKind.NonClr && !property.Facets.Nullable)
                        {
                            // due to an issue with the provider not enforcing non-nullability on weakly-backed properties,
                            // if the property is non-nullable make sure its strongly backed
                            property.Facets.IsClrProperty = true;
                            type.Facets.IsClrType         = true;
                            foreach (var derived in type.DerivedTypes)
                            {
                                derived.Facets.IsClrType = true;
                            }
                        }
                    }
                }

                if (etagProperties.Any())
                {
                    throw new TestWarningException(string.Format("Could not find properties on type '{0}': {1}", type.Name, string.Join(", ", etagProperties.ToArray())));
                }

                type.Facets.Add(NodeFacet.Attribute(new ConcurrencyAttribute(type, propertyNames)));
            }

            List <ServiceOperation> serviceOperations = new List <ServiceOperation>();
            foreach (ResourceContainer container in workspace.ServiceContainer.ResourceContainers)
            {
                // no MEST yet for service ops!!
                if (workspace.ServiceContainer.ResourceContainers.Any(c => c != container && c.BaseType == container.BaseType))
                {
                    continue;
                }

                ServiceOperation serviceOp = Resource.ServiceOperation("Get" + container.Name, container, container.BaseType, container.ResourceTypes.ToArray());

                string fullTypeName = container.BaseType.Namespace + "." + container.BaseType.Name;
#if !ClientSKUFramework
                if (workspace.DataLayerProviderKind == DataLayerProviderKind.NonClr && !container.BaseType.Facets.IsClrType)
                {
                    fullTypeName = typeof(NonClr.RowEntityType).FullName;
                }
#endif
                serviceOp.ServiceOpCode = string.Join(Environment.NewLine, new string[]
                {
                    "[WebGet]",
                    "public IQueryable<" + fullTypeName + "> " + serviceOp.Name + "()",
                    "{",
                    "     return GetEntitySet<" + fullTypeName + ">(\"" + container.Name + "\");",
                    "}"
                });
#if !ClientSKUFramework
                serviceOp.ServiceOperationResultKind = Microsoft.OData.Service.Providers.ServiceOperationResultKind.QueryWithMultipleResults;
#endif
                serviceOp.ExpectedTypeName = fullTypeName;
                serviceOperations.Add(serviceOp);
            }

            workspace.ServiceContainer.AddNodes(serviceOperations);
            workspace.AddServiceOperationCode();
        }