Beispiel #1
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!
            }
        }
Beispiel #2
0
        private void VerifyLoadProperty(object entity, string propertyName, WebDataCtxWrapper Context)
        {
            Uri entityUri = null;

            if (Context.TryGetUri(entity, out entityUri))
            {
                Uri  navigationPropertyURI = new Uri(String.Format("{0}/{1}", entityUri.OriginalString, propertyName));;
                Type navPropType           = entity.GetType().GetProperty(propertyName).PropertyType;
                if (navPropType.IsGenericType)
                {
                    navPropType = navPropType.GetGenericArguments()[0];
                }
                WebDataCtxWrapper baselineCOntext = new WebDataCtxWrapper(Context.BaseUri);
                baselineCOntext.Credentials = CredentialCache.DefaultCredentials;
                QueryOperationResponse qoResponse = baselineCOntext.ExecuteOfT(navPropType, navigationPropertyURI) as QueryOperationResponse;
                IEnumerator            enumerator = qoResponse.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    object baselineEntity   = enumerator.Current;
                    Uri    navPropEntityURI = null;
                    if (baselineCOntext.TryGetUri(baselineEntity, out navPropEntityURI))
                    {
                        AstoriaTestLog.IsNotNull(Context.TryGetEntityOfT(navPropType, navPropEntityURI), "Could not find entity in Navigation property ");
                    }
                }
            }
        }
Beispiel #3
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");
        }
Beispiel #4
0
        public static void CompareMetadata(IEdmModel expectedItems, IEdmModel actualItems, bool isReflectionBasedProvider, string defaultEntityContainerName, ServiceContainer serviceContainer)
        {
            //
            //  Verify the metadata version is correct, the number of entity containers is 1, the entity
            //  container names match, and the number of entity types are the same
            //
            AstoriaTestLog.AreEqual(1.1, actualItems.GetEdmVersion(), "The metadata version was not correct");
            AstoriaTestLog.AreEqual(serviceContainer.Workspace.ContextTypeName, actualItems.EntityContainer.Name, "Entity Container names do not match");
            if (!isReflectionBasedProvider)
            {
                AstoriaTestLog.AreEqual(expectedItems.SchemaElements.OfType <IEdmEntityType>().Count(), actualItems.SchemaElements.OfType <IEdmEntityType>().Count(), "Entity Type Counts do not match");
            }

            foreach (IEdmOperationImport metadataExposedFunction in actualItems.EntityContainer.OperationImports())
            {
                AstoriaTestLog.TraceInfo("--> " + metadataExposedFunction.Name);
            }

            //
            //  For each entity type exposed through the metadata endpoint, verify the following
            //      1.  Verify it has an equivalent definition in the resource container
            //      2.  Verify the entity type name is correct
            //      3.  Verify that no navigation property is exposed in the entity type
            //      4.  Verify that the property count in the entity type
            //
            IEnumerable <ComplexType> rtTypeCollection = serviceContainer.AllTypes.Where(a => a.GetType().Name.Equals("ResourceType"));

            AstoriaTestLog.TraceInfo(rtTypeCollection.Count().ToString());

            foreach (IEdmEntityType metadataExposedEntityType in actualItems.SchemaElements.OfType <IEdmEntityType>())
            {
                ResourceType resourceContainerEntityType = serviceContainer.AllTypes.Where(b => b.GetType().Name.Equals("ResourceType") & (b.FullName.Equals(metadataExposedEntityType.FullName()))).FirstOrDefault() as ResourceType;
                if (resourceContainerEntityType == null)
                {
                    continue;
                }

                AstoriaTestLog.IsNotNull(resourceContainerEntityType, "Did not find entity type in resource container");
                AstoriaTestLog.AreEqual(resourceContainerEntityType.FullName, metadataExposedEntityType.FullName(), "Entity Type name mismatch");

                //
                //  Verify the name, type, and nullable attribute values
                //
                ResourceContainer rc = serviceContainer.ResourceContainers.Where(a => a.BaseType.Name.Equals(metadataExposedEntityType.Name)).FirstOrDefault();
                if (rc == null)
                {
                    continue;
                }
                int navCount = rc.BaseType.Properties.Cast <NodeProperty>().Cast <ResourceProperty>().Where(a => a.IsNavigation).Count();

                AstoriaTestLog.TraceInfo(rc.Name);
                AstoriaTestLog.TraceInfo(navCount.ToString());
                AstoriaTestLog.AreEqual(resourceContainerEntityType.Properties.Count - navCount, metadataExposedEntityType.Properties().Count(), "Edm Property count mismatch");
                foreach (IEdmProperty metadataExposedProperty in metadataExposedEntityType.Properties())
                {
                    string errorStringEntityTypeProperty = metadataExposedEntityType.FullName() + " : " + metadataExposedProperty.Name;

                    NodeProperty resourceContainerProperty = resourceContainerEntityType.Properties.Where(a => a.Name.Equals(metadataExposedProperty.Name)).FirstOrDefault();
                    AstoriaTestLog.IsNotNull(resourceContainerProperty, "Did not find property -->" + errorStringEntityTypeProperty + "<-- in resource container");
                    if (resourceContainerProperty == null)
                    {
                        continue;
                    }

                    if (metadataExposedProperty.Type.IsBinary())
                    {
                        if (AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.LinqToSql))
                        {
                            AstoriaTestLog.AreEqual("System.Data.Linq.Binary", resourceContainerProperty.Type.ClrType.FullName, errorStringEntityTypeProperty + " type is incorrect");
                        }
                        else
                        {
                            AstoriaTestLog.AreEqual("System.Byte[]", resourceContainerProperty.Type.ClrType.FullName, errorStringEntityTypeProperty + " type is incorrect");
                        }
                    }
                    else
                    {
                        AstoriaTestLog.AreEqual(metadataExposedProperty.Type.FullName(), resourceContainerProperty.Type.FullName, errorStringEntityTypeProperty + " type is incorrect");
                    }
                }
            }
        }
Beispiel #5
0
 // Mirror of MSTest methods
 public static void IsNotNull(object value)
 {
     AstoriaTestLog.IsNotNull(value, "");
 }