Exemplo n.º 1
0
        private static void CompareEdmType(IEdmType edmEdmType, IEdmType dataWebEdmType, bool isReflectionBasedProvider, out int numberOfNavProps)
        {
            if (edmEdmType == null)
            {
                throw new ArgumentNullException("edmEdmType");
            }
            if (dataWebEdmType == null)
            {
                throw new ArgumentNullException("dataWebEdmType");
            }

            AstoriaTestLog.IsTrue(edmEdmType.TypeKind == EdmTypeKind.Entity ||
                                  edmEdmType.TypeKind == EdmTypeKind.Complex,
                                  "Only structural type expected - " + edmEdmType.TypeKind.ToString());

            AstoriaTestLog.IsTrue(edmEdmType.TypeKind == dataWebEdmType.TypeKind,
                                  "BuiltInTypeKind must be the name");

            if (edmEdmType.TypeKind == EdmTypeKind.Entity)
            {
                List <IEdmStructuralProperty> edmKeyMembers     = ((IEdmEntityType)edmEdmType).Key().ToList();
                List <IEdmStructuralProperty> dataWebKeyMembers = ((IEdmEntityType)dataWebEdmType).Key().ToList();

                AstoriaTestLog.IsTrue(edmKeyMembers.Count == dataWebKeyMembers.Count, "Key members count must match");
                foreach (IEdmStructuralProperty member1 in edmKeyMembers)
                {
                    // make sure the member with the same name in the key members list
                    // Other comparisions will be done in the member comparison
                    AstoriaTestLog.IsTrue(dataWebKeyMembers.Any(p => p.Name == member1.Name));
                }
            }

            CompareMembers((IEdmStructuredType)edmEdmType, (IEdmStructuredType)dataWebEdmType, isReflectionBasedProvider, out numberOfNavProps);
        }
Exemplo n.º 2
0
        private static void CompareMembers(IEdmStructuredType edmEdmType, IEdmStructuredType dataWebEdmType, bool isReflectionBasedProvider, out int totalNavProps)
        {
            // find the number of nav properties on this type (not the base type). This will help us to determine how many associations
            // be generated
            totalNavProps = edmEdmType.DeclaredProperties.OfType <IEdmNavigationProperty>().Count();
            AstoriaTestLog.IsTrue(edmEdmType.DeclaredProperties.Count() == dataWebEdmType.DeclaredProperties.Count(), "Number of members must match");

            foreach (IEdmProperty member1 in edmEdmType.DeclaredProperties)
            {
                IEdmProperty member2 = dataWebEdmType.FindProperty(member1.Name);
                AstoriaTestLog.IsNotNull(member2);

                // WCF DS server will always write DateTimeOffset as the data type, if the backend model has DateTime as the data type
                string edmMemberTypeName = member1.Type.FullName();
                if (edmMemberTypeName == "Edm.DateTime")
                {
                    AstoriaTestLog.IsTrue(member2.Type.FullName() == "Edm.DateTimeOffset", "For DateTime properties in the model, we should generate");
                }
                else
                {
                    AstoriaTestLog.IsTrue(edmMemberTypeName == member2.Type.FullName(), "Type must match");
                }

                AstoriaTestLog.IsTrue(member1.Type.IsNullable == member2.Type.IsNullable, "nullability must match");

                // TODO: if its a navigation, compare referential constraint!
            }
        }
Exemplo n.º 3
0
        public static void VerifySpecificResponseVersion(AstoriaResponse response, int major, int minor)
        {
            if (response.DataServiceVersion == null)
            {
                AstoriaTestLog.FailAndThrow("Data service version should always be specified in response");
            }

            AstoriaTestLog.IsTrue(response.DataServiceVersion.StartsWith(major + "." + minor),
                                  String.Format("Unexpected value in response's DataServiceVersion header: {0}, expected: {1}.{2}", response.DataServiceVersion, major, minor));
        }
Exemplo n.º 4
0
        public static void VerifyUnknownVerb(AstoriaResponse webResponse)
        {
            AstoriaTestLog.AreEqual(System.Net.HttpStatusCode.NotImplemented, webResponse.ActualStatusCode,
                                    "Unknown verbs should receive a 'Not Implemented' reply.");

            if (webResponse.ContentType != null)
            {
                AstoriaTestLog.IsTrue(webResponse.ContentType.StartsWith(SerializationFormatKinds.JsonMimeType, StringComparison.Ordinal),
                                      "Error messages should have no content type or an application/json content type.");
            }
        }
Exemplo n.º 5
0
        public static void CompareMetadata(IEdmModel expectedItems, IEdmModel actualItems, bool isReflectionBasedProvider, string defaultEntityContainerName)
        {
            // Check if the version is equal
            // TODO: Remove old versions of EDM and EDMX
            //AstoriaTestLog.AreEqual(expectedItems.GetEdmVersion(), actualItems.GetEdmVersion(), "Edm version did not match");

            int totalNavProps = 0;

            foreach (var edmType in expectedItems.SchemaElements.OfType <IEdmSchemaType>())
            {
                if (edmType.TypeKind == EdmTypeKind.Primitive)
                {
                    continue;
                }

                IEdmSchemaType dataWebEdmType = null;

                // For reflection based providers, there might be more than one container in the original schema
                // and hence the metadata maynot contain all the types;
                if (null == (dataWebEdmType = actualItems.FindType(edmType.FullName())))
                {
                    if (TypeIsOrphaned(edmType, expectedItems))
                    {
                        // Type is unused, so it's OK if it's not there.
                        continue;
                    }

                    continue;
                }

                int numberOfNavProps = 0;
                CompareEdmType(edmType, dataWebEdmType, isReflectionBasedProvider, out numberOfNavProps);
                totalNavProps += numberOfNavProps;
            }

            if (isReflectionBasedProvider)
            {
                AstoriaTestLog.IsTrue(totalNavProps == actualItems.SchemaElements.OfType <IEdmStructuredType>().SelectMany(t => t.DeclaredProperties).OfType <IEdmNavigationProperty>().Count(),
                                      "Number of association must be equal to number of nav properties in the model");
            }

            CompareEntityContainer(expectedItems.EntityContainer, actualItems.EntityContainer);
        }
Exemplo n.º 6
0
        private static void CompareEntityContainer(IEdmEntityContainer edmEntityContainer, IEdmEntityContainer dataWebEntityContainer)
        {
            AstoriaTestLog.AreEqual(edmEntityContainer.FullName(), dataWebEntityContainer.FullName());

            int numberOfEntitySets = 0;

            foreach (IEdmEntitySet entitySetBase in edmEntityContainer.EntitySets())
            {
                // compare the entity set base
                IEdmEntitySet dataWebEntitySetBase = dataWebEntityContainer.FindEntitySet(entitySetBase.Name);

                AstoriaTestLog.IsNotNull(dataWebEntitySetBase);
                AstoriaTestLog.AreEqual(entitySetBase.Name, dataWebEntitySetBase.Name);
                AstoriaTestLog.AreEqual(entitySetBase.EntityType().FullName(), dataWebEntitySetBase.EntityType().FullName());

                ++numberOfEntitySets;
            }

            AstoriaTestLog.IsTrue(numberOfEntitySets == dataWebEntityContainer.EntitySets().Count(), "Number of baseEntitySets must match");
        }
Exemplo n.º 7
0
        public static void Verify(Workspace w, ExpNode q, IEnumerable results, ResourceType resType, ComplexType cType, bool bCount)
        {
            long count = 0;

            if (bCount)
            {
                object[] args    = new object[] { results };
                Type     qorType = typeof(QueryOperationResponseWrapper <>).MakeGenericType(resType.ClientClrType);
                object   qor     = Activator.CreateInstance(qorType, args);

                PropertyInfo pi = qor.GetType().GetProperty("GetTotalCount");
                object       i  = pi.GetValue(qor, new object[] { });

                count = (long)i;

                LinqQueryBuilder lb = new LinqQueryBuilder(w);
                lb.CountingMode = true;
                lb.Build(q);

                object baselineElementsCount = CommonPayload.CreateList(lb.QueryResult).Count;
                AstoriaTestLog.IsTrue(count == Convert.ToInt64(baselineElementsCount), "Count is different.Count is " + count.ToString() + ". Baseline count is " + baselineElementsCount.ToString());
            }

            LinqQueryBuilder linqBuilder = new LinqQueryBuilder(w);

            linqBuilder.Build(q);

            IQueryable baselines = linqBuilder.QueryResult;

            IEnumerator b = null;

            IEnumerator r = null;

            try
            {
                b = TrustedMethods.IQueryableGetEnumerator(baselines);
                r = results.GetEnumerator();
            }
            catch (InvalidOperationException invalidOperation)
            {
                if (!AstoriaTestProperties.IsRemoteClient)
                {
                    throw invalidOperation;
                }
            }

            PropertyInfo propertyInfo    = null;
            Object       expectedResult1 = null;
            Object       expectedResult2 = null;

            try
            {
                while (b.MoveNext() && r.MoveNext())
                {
                    if (b.Current == null)
                    {
                        return;
                    }

                    if (r.Current == null)
                    {
                        throw new TestFailedException("Less results than expected");
                    }
                    //skip verification for Binary data type for Linq to Sql
                    if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && b.Current is System.Byte[])
                    {
                        return;
                    }

                    if (b.Current is System.Byte[])
                    {
                        byte[] newBase = (byte[])b.Current;
                        byte[] newAct  = (byte[])r.Current;

                        if (newBase.Length != newAct.Length)
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
#if !ClientSKUFramework
                    else if (b.Current is System.Data.Linq.Binary)
                    {
                        System.Data.Linq.Binary newBase = (System.Data.Linq.Binary)b.Current;
                        System.Data.Linq.Binary newAct  = new System.Data.Linq.Binary((byte[])r.Current);

                        if (newBase.Length != newAct.Length)
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
#endif

                    else if (b.Current is System.Xml.Linq.XElement)
                    {
                        if (b.Current.ToString() != r.Current.ToString())
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
                    else
                    {
                        if (!b.Current.Equals(r.Current))
                        {
                            if (cType != null)
                            {
                                foreach (ResourceProperty property in cType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        propertyInfo    = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyInfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyInfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            #if !ClientSKUFramework
                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
                                            #endif


                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (ResourceProperty property in resType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        //skip verification for Binary data type for Linq to Sql
                                        if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && property.Type.Name == "LinqToSqlBinary")
                                        {
                                            return;
                                        }

                                        propertyInfo    = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyinfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyinfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }

                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            #if !ClientSKUFramework
                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
                                            #endif
                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AstoriaTestLog.WriteLine(e.ToString());
                throw;
            }
        }
Exemplo n.º 8
0
        /// <summary>Sends the current request to the server.</summary>
        public override void SendRequest()
        {
            if (this.ServiceType == null)
            {
                throw new InvalidOperationException("DataServiceType or ServiceType property should be set for in-process requests.");
            }

            // Set up an in-process host.
            host = new TestServiceHost2();
            host.RequestAcceptCharSet = this.AcceptCharset;
            host.RequestHttpMethod    = this.HttpMethod;
            host.RequestPathInfo      = this.RequestUriString;
            host.RequestStream        = this.RequestStream;
            host.RequestContentType   = this.RequestContentType;
            host.RequestContentLength = this.RequestContentLength;
            host.RequestIfMatch       = this.IfMatch;
            host.RequestIfNoneMatch   = this.IfNoneMatch;
            host.RequestMaxVersion    = this.RequestMaxVersion;
            foreach (var header in this.RequestHeaders)
            {
                host.RequestHeaders.Add(header.Key, header.Value);
            }

            host.RequestVersion = this.RequestVersion;

            if (this.Accept != null)
            {
                host.RequestAccept = this.Accept;
            }

            // An important side-effect of the following line of code is to
            // clean the TestArguments static for tests which don't use it.
            BaseTestWebRequest.LoadSerializedTestArguments(ArgumentsToString(this.TestArguments));
            try
            {
                // Create a data service instance and hook into the processing directly - only GET supported right now.
                Type serviceType = this.ServiceType;
                try
                {
                    object serviceInstance = Activator.CreateInstance(serviceType);

                    MethodInfo attachMethod = serviceType.GetMethod("AttachHost");
                    attachMethod.Invoke(serviceInstance, new object[] { host });

                    MethodInfo method = serviceType.GetMethod("ProcessRequest", Type.EmptyTypes);
                    method.Invoke(serviceInstance, null);

                    this.responseStream = GetResponseStream(host);
                }
                catch (TargetInvocationException invocationException)
                {
                    this.responseStream = GetResponseStream(host);
                    if (invocationException.InnerException != null)
                    {
                        if (BaseTestWebRequest.SaveOriginalStackTrace &&
                            invocationException.InnerException.Data != null)
                        {
                            invocationException.InnerException.Data["OriginalStackTrace"] = invocationException.InnerException.StackTrace;
                        }

                        throw invocationException.InnerException;
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if (this.RequestStream != null)
                    {
                        AstoriaTestLog.IsTrue(this.RequestStream.CanRead, "request stream must be open");
                    }

                    if (this.responseStream != null)
                    {
                        AstoriaTestLog.IsTrue(this.responseStream.CanRead, "response stream must be open");
                    }
                }
            }
            finally
            {
                LoadSerializedTestArguments(null);
            }
        }
Exemplo n.º 9
0
 public static void IsTrue(bool condition)
 {
     AstoriaTestLog.IsTrue(condition, "");
 }