public void Visit_DbLikeExpression_creates_equivalent_legacy_DbLikeExpression()
        {
            var propertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Name");

            var stringTypeUsage =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            var likeExpression = propertyExpression.Like(stringTypeUsage.Constant("foo"), stringTypeUsage.Constant("bar"));

            var legacyLikeExpression =
                _legacyDbExpressionConverter.Visit(likeExpression) as LegacyCommandTrees.DbLikeExpression;

            Assert.NotNull(legacyLikeExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Like, legacyLikeExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Property, legacyLikeExpression.Argument.ExpressionKind);
            Assert.Equal("foo", (string)((LegacyCommandTrees.DbConstantExpression)legacyLikeExpression.Pattern).Value);
            Assert.Equal("bar", (string)((LegacyCommandTrees.DbConstantExpression)legacyLikeExpression.Escape).Value);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyLikeExpression.ResultType, likeExpression.ResultType);
        }
        public void Visit_DbSkipExpression_creates_equivalent_legacy_DbSkipExpression()
        {
            var scanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var idProperty =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Id");

            var skipExpression =
                scanExpression
                .BindAs("Table")
                .Skip(new[] { idProperty.ToSortClause() }, DbExpressionBuilder.Constant(42));

            var legacySkipExpression =
                _legacyDbExpressionConverter.Visit(skipExpression) as LegacyCommandTrees.DbSkipExpression;

            Assert.NotNull(legacySkipExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Skip, legacySkipExpression.ExpressionKind);
            Assert.Equal("Table", legacySkipExpression.Input.VariableName);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacySkipExpression.Input.Expression.ExpressionKind);
            Assert.Equal(
                "Id",
                ((LegacyCommandTrees.DbPropertyExpression)legacySkipExpression.SortOrder.Single().Expression).Property.Name);
            Assert.Equal(42, ((LegacyCommandTrees.DbConstantExpression)legacySkipExpression.Count).Value);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacySkipExpression.ResultType, skipExpression.ResultType);
        }
        public void Visit_DbCrossJoinExpression_creates_equivalent_DbCrossJoinExpression()
        {
            var bindings =
                new[]
            {
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan()
                .BindAs("table1"),
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "OtherEntitiesSet")
                .Scan()
                .BindAs("table2")
            };

            var crossJoinExpression = DbExpressionBuilder.CrossJoin(bindings);

            var legacyCrossJoinExpression =
                _legacyDbExpressionConverter.Visit(crossJoinExpression) as LegacyCommandTrees.DbCrossJoinExpression;

            Assert.NotNull(legacyCrossJoinExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.CrossJoin, legacyCrossJoinExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyCrossJoinExpression.Inputs[0].Expression.ExpressionKind);
            Assert.Equal("EntitiesSet", ((LegacyCommandTrees.DbScanExpression)legacyCrossJoinExpression.Inputs[0].Expression).Target.Name);
            Assert.Equal("table1", legacyCrossJoinExpression.Inputs[0].VariableName);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyCrossJoinExpression.Inputs[1].Expression.ExpressionKind);
            Assert.Equal(
                "OtherEntitiesSet", ((LegacyCommandTrees.DbScanExpression)legacyCrossJoinExpression.Inputs[1].Expression).Target.Name);
            Assert.Equal("table2", legacyCrossJoinExpression.Inputs[1].VariableName);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyCrossJoinExpression.ResultType, crossJoinExpression.ResultType);
        }
        public void Visit_DbFitlerExpression_creates_equivalent_legacy_DbFilterExpression()
        {
            var scanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var filterExpression =
                scanExpression
                .BindAs("Table")
                .Filter(
                    DbExpressionBuilder.Constant(911).Equal(DbExpressionBuilder.Constant(911)));

            var legacyFilterExpression =
                _legacyDbExpressionConverter.Visit(filterExpression) as LegacyCommandTrees.DbFilterExpression;

            Assert.NotNull(legacyFilterExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Filter, legacyFilterExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyFilterExpression.Input.Expression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Equals, legacyFilterExpression.Predicate.ExpressionKind);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyFilterExpression.ResultType, filterExpression.ResultType);
        }
        public void Visit_DbSortExpression_creates_equivalent_legacy_DbSortExpression()
        {
            var scanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var idProperty =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Id");

            var nameProperty =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Name");

            var sortExpression =
                scanExpression
                .BindAs("Table")
                .Sort(
                    new[]
            {
                idProperty.ToSortClause(),
                nameProperty.ToSortClause("testCollationAscending"),
                nameProperty.ToSortClauseDescending(),
                nameProperty.ToSortClauseDescending("testCollationDescending")
            });

            var legacySortExpression =
                _legacyDbExpressionConverter.Visit(sortExpression) as LegacyCommandTrees.DbSortExpression;

            Assert.NotNull(legacySortExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Sort, legacySortExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacySortExpression.Input.Expression.ExpressionKind);
            Assert.Equal("Table", legacySortExpression.Input.VariableName);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacySortExpression.Input.VariableType, sortExpression.Input.VariableType);

            Assert.Equal(4, legacySortExpression.SortOrder.Count);
            Assert.True(
                legacySortExpression.SortOrder.All(
                    e => e.Expression.ExpressionKind == LegacyCommandTrees.DbExpressionKind.Property));
            Assert.True(legacySortExpression.SortOrder[0].Ascending);
            Assert.Empty(legacySortExpression.SortOrder[0].Collation);
            Assert.True(legacySortExpression.SortOrder[1].Ascending);
            Assert.Equal("testCollationAscending", legacySortExpression.SortOrder[1].Collation);
            Assert.False(legacySortExpression.SortOrder[2].Ascending);
            Assert.Empty(legacySortExpression.SortOrder[2].Collation);
            Assert.False(legacySortExpression.SortOrder[3].Ascending);
            Assert.Equal("testCollationDescending", legacySortExpression.SortOrder[3].Collation);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacySortExpression.ResultType, sortExpression.ResultType);
        }
        public void Visit_DbIntersectExpression_creates_equivalent_legacy_DbIntersectExpression()
        {
            var left  = DbExpressionBuilder.NewCollection(new DbExpression[] { DbExpressionBuilder.Constant(42) });
            var right = DbExpressionBuilder.NewCollection(new DbExpression[] { DbExpressionBuilder.Constant(24) });

            var intersectExpression = left.Intersect(right);

            var legacyIntersectExpression =
                _legacyDbExpressionConverter.Visit(intersectExpression) as LegacyCommandTrees.DbIntersectExpression;

            Assert.NotNull(legacyIntersectExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Intersect, legacyIntersectExpression.ExpressionKind);

            Assert.Equal(
                42,
                ((LegacyCommandTrees.DbConstantExpression)
                     ((LegacyCommandTrees.DbNewInstanceExpression)legacyIntersectExpression.Left).Arguments.Single())
                .Value);

            Assert.Equal(
                24,
                ((LegacyCommandTrees.DbConstantExpression)
                     ((LegacyCommandTrees.DbNewInstanceExpression)legacyIntersectExpression.Right).Arguments.Single())
                .Value);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyIntersectExpression.ResultType, intersectExpression.ResultType);
        }
        public void GetFacetDescriptions_returns_correct_facets_for_all_primitive_types()
        {
            var storeTypes =
                ProviderManifestWrapper
                .GetStoreTypes()
                .OrderBy(t => t.Name)
                .ToArray();

            var legacyStoreTypes =
                LegacyProviderManifest
                .GetStoreTypes()
                .OrderBy(t => t.Name)
                .ToArray();

            for (var i = 0; i < storeTypes.Length; i++)
            {
                var facetDescriptions =
                    ProviderManifestWrapper.GetFacetDescriptions(storeTypes[i]).OrderBy(f => f.FacetName).ToArray();
                var legacyFacetDescriptions =
                    LegacyProviderManifest.GetFacetDescriptions(legacyStoreTypes[i]).OrderBy(f => f.FacetName).ToArray();

                Assert.Equal(facetDescriptions.Length, legacyFacetDescriptions.Length);

                for (var j = 0; j < facetDescriptions.Count(); j++)
                {
                    TypeUsageVerificationHelper.VerifyFacetDescriptionsEquivalent(facetDescriptions[j], legacyFacetDescriptions[j]);
                }
            }
        }
        public void Visit_DbPropertyExpression_creates_equivalent_legacy_DbPropertyExpression()
        {
            var propertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Id");

            var legacyPropertyExpression =
                _legacyDbExpressionConverter.Visit(propertyExpression) as LegacyCommandTrees.DbPropertyExpression;

            Assert.NotNull(legacyPropertyExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Property, legacyPropertyExpression.ExpressionKind);
            Assert.Equal(
                LegacyCommandTrees.DbExpressionKind.VariableReference,
                legacyPropertyExpression.Instance.ExpressionKind);
            Assert.Equal(
                "Table",
                ((LegacyCommandTrees.DbVariableReferenceExpression)legacyPropertyExpression.Instance)
                .VariableName);
            Assert.Equal("Id", legacyPropertyExpression.Property.Name);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyPropertyExpression.Property.TypeUsage, propertyExpression.Property.TypeUsage);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyPropertyExpression.ResultType, propertyExpression.ResultType);
        }
        public void Visit_DbNewInstanceExpression_rowtype_creates_equivalent_legacy_DbNewInstanceExpression()
        {
            var propertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Id");

            var newInstanceExpressionRowType =
                DbExpressionBuilder.NewRow(
                    new[]
            {
                new KeyValuePair <string, DbExpression>("Id", propertyExpression),
                new KeyValuePair <string, DbExpression>("Const", DbExpressionBuilder.Constant(42))
            });

            var legacyNewInstanceExpressionRowType =
                _legacyDbExpressionConverter.Visit(newInstanceExpressionRowType) as
                LegacyCommandTrees.DbNewInstanceExpression;

            Assert.NotNull(legacyNewInstanceExpressionRowType);
            Assert.Equal(
                LegacyCommandTrees.DbExpressionKind.NewInstance,
                legacyNewInstanceExpressionRowType.ExpressionKind);
            Assert.Equal(2, legacyNewInstanceExpressionRowType.Arguments.Count);
            Assert.IsType <LegacyCommandTrees.DbPropertyExpression>(legacyNewInstanceExpressionRowType.Arguments[0]);
            Assert.IsType <LegacyCommandTrees.DbConstantExpression>(legacyNewInstanceExpressionRowType.Arguments[1]);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyNewInstanceExpressionRowType.ResultType, newInstanceExpressionRowType.ResultType);
        }
        public void GetEdmType_returns_correct_type_usages_for_specific_String_type_usages()
        {
            foreach (var isUnicode in new[] { true, false })
            {
                foreach (var isFixedLength in new[] { true, false })
                {
                    TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                        LegacyProviderManifest.GetEdmType(
                            LegacyProviderManifest.GetStoreType(
                                LegacyMetadata.TypeUsage.CreateStringTypeUsage(LegacyEdmPrimitiveTypes["String"], isUnicode, isFixedLength))),
                        ProviderManifestWrapper.GetEdmType(
                            ProviderManifestWrapper.GetStoreType(
                                TypeUsage.CreateStringTypeUsage(EdmPrimitiveTypes["String"], isUnicode, isFixedLength))));

                    TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                        LegacyProviderManifest.GetEdmType(
                            LegacyProviderManifest.GetStoreType(
                                LegacyMetadata.TypeUsage.CreateStringTypeUsage(
                                    LegacyEdmPrimitiveTypes["String"], isUnicode, isFixedLength, maxLength: 1000))),
                        ProviderManifestWrapper.GetEdmType(
                            ProviderManifestWrapper.GetStoreType(
                                TypeUsage.CreateStringTypeUsage(EdmPrimitiveTypes["String"], isUnicode, isFixedLength, maxLength: 1000))));
                }
            }
        }
Ejemplo n.º 11
0
        public void GetEdmType_returns_correct_default_type_usages_for_all_primitive_types()
        {
            var storeTypes = ProviderManifestWrapper.GetStoreTypes().ToDictionary(t => t.Name, t => t);

            foreach (var legacyStoreType in LegacyProviderManifest.GetStoreTypes())
            {
                TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                    LegacyProviderManifest.GetEdmType(LegacyMetadata.TypeUsage.CreateDefaultTypeUsage(legacyStoreType)),
                    ProviderManifestWrapper.GetEdmType(TypeUsage.CreateDefaultTypeUsage(storeTypes[legacyStoreType.Name])));
            }
        }
        private void ConvertAndVerifyJoinExpressions(
            Func <DbExpressionBinding, DbExpressionBinding, DbExpression, DbJoinExpression> createJoinExpression)
        {
            var leftScanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var leftPropertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("leftTable")
                .Property("Id");

            var rightScanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "OtherEntitiesSet")
                .Scan();

            var rightPropertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "OtherEntities"))
                .Variable("rightTable")
                .Property("Id");

            var joinExpression =
                createJoinExpression(
                    leftScanExpression.BindAs("leftTable"),
                    rightScanExpression.BindAs("rightTable"),
                    leftPropertyExpression.Equal(rightPropertyExpression));

            var legacyJoinExpression =
                _legacyDbExpressionConverter.Visit(joinExpression) as LegacyCommandTrees.DbJoinExpression;

            Assert.NotNull(legacyJoinExpression);
            Assert.Equal((int)joinExpression.ExpressionKind, (int)legacyJoinExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyJoinExpression.Left.Expression.ExpressionKind);
            Assert.Equal("EntitiesSet", ((LegacyCommandTrees.DbScanExpression)legacyJoinExpression.Left.Expression).Target.Name);
            Assert.Equal("leftTable", legacyJoinExpression.Left.VariableName);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyJoinExpression.Right.Expression.ExpressionKind);
            Assert.Equal("OtherEntitiesSet", ((LegacyCommandTrees.DbScanExpression)legacyJoinExpression.Right.Expression).Target.Name);
            Assert.Equal("rightTable", legacyJoinExpression.Right.VariableName);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Equals, legacyJoinExpression.JoinCondition.ExpressionKind);
            var comparisonExpression = (LegacyCommandTrees.DbComparisonExpression)legacyJoinExpression.JoinCondition;

            Assert.Equal("Entities", ((LegacyCommandTrees.DbPropertyExpression)comparisonExpression.Left).Property.DeclaringType.Name);
            Assert.Equal("OtherEntities", ((LegacyCommandTrees.DbPropertyExpression)comparisonExpression.Right).Property.DeclaringType.Name);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyJoinExpression.ResultType, joinExpression.ResultType);
        }
Ejemplo n.º 13
0
 public void GetStoreType_returns_correct_default_type_usages_for_all_primitive_types()
 {
     // SqlProvider does not support SByte
     foreach (var legacyEdmPrimitiveType in LegacyEdmPrimitiveTypes.Where(t => t.Key != "SByte"))
     {
         TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
             LegacyProviderManifest.GetStoreType(
                 LegacyMetadata.TypeUsage.CreateDefaultTypeUsage(legacyEdmPrimitiveType.Value)),
             ProviderManifestWrapper.GetStoreType(
                 TypeUsage.CreateDefaultTypeUsage(EdmPrimitiveTypes[legacyEdmPrimitiveType.Key])));
     }
 }
        public void Visit_DbNullExpression_creates_equivalent_legacy_DbNullExpression()
        {
            var nullExpression =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)).Null();

            var legacyNullExpression =
                _legacyDbExpressionConverter.Visit(nullExpression) as LegacyCommandTrees.DbNullExpression;

            Assert.NotNull(legacyNullExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Null, legacyNullExpression.ExpressionKind);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyNullExpression.ResultType, nullExpression.ResultType);
        }
        public void Visit_DbNotExpression_creates_equivalent_legacy_DbNotExpression()
        {
            var notExpression = DbExpressionBuilder.True.Not();

            var legacyNotExpression =
                _legacyDbExpressionConverter.Visit(notExpression) as LegacyCommandTrees.DbNotExpression;

            Assert.NotNull(legacyNotExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Not, legacyNotExpression.ExpressionKind);
            Assert.True((bool)((LegacyCommandTrees.DbConstantExpression)legacyNotExpression.Argument).Value);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyNotExpression.ResultType, notExpression.ResultType);
        }
Ejemplo n.º 16
0
        public void GetStoreType_returns_correct_type_usages_for_specific_Time_type_usages()
        {
            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateTimeTypeUsage(LegacyEdmPrimitiveTypes["Time"], precision: null)),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateTimeTypeUsage(EdmPrimitiveTypes["Time"], precision: null)));

            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateTimeTypeUsage(LegacyEdmPrimitiveTypes["Time"], precision: 6)),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateTimeTypeUsage(EdmPrimitiveTypes["Time"], precision: 6)));
        }
Ejemplo n.º 17
0
        public void GetStoreType_returns_correct_type_usages_for_specific_Binary_type_usages()
        {
            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateBinaryTypeUsage(LegacyEdmPrimitiveTypes["Binary"], isFixedLength: false)),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateBinaryTypeUsage(EdmPrimitiveTypes["Binary"], isFixedLength: false)));

            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateBinaryTypeUsage(LegacyEdmPrimitiveTypes["Binary"], isFixedLength: true)),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateBinaryTypeUsage(EdmPrimitiveTypes["Binary"], isFixedLength: true)));
        }
Ejemplo n.º 18
0
        public void GetStoreType_returns_correct_type_usages_for_specific_Decimal_type_usages()
        {
            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateDecimalTypeUsage(LegacyEdmPrimitiveTypes["Decimal"])),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateDecimalTypeUsage(EdmPrimitiveTypes["Decimal"])));

            TypeUsageVerificationHelper.VerifyTypeUsagesEquivalent(
                LegacyProviderManifest.GetStoreType(
                    LegacyMetadata.TypeUsage.CreateDecimalTypeUsage(LegacyEdmPrimitiveTypes["Decimal"], precision: 6, scale: 10)),
                ProviderManifestWrapper.GetStoreType(
                    TypeUsage.CreateDecimalTypeUsage(EdmPrimitiveTypes["Decimal"], precision: 6, scale: 10)));
        }
        public void Visit_DbParameterRefExpression_creates_equivalent_legacy_DbParameterRefExpression()
        {
            var paramRefExpression =
                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))
                .Parameter("foo");

            var legacyParamRefExpression =
                _legacyDbExpressionConverter.Visit(paramRefExpression) as LegacyCommandTrees.DbParameterReferenceExpression;

            Assert.NotNull(legacyParamRefExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.ParameterReference, legacyParamRefExpression.ExpressionKind);
            Assert.Equal("foo", legacyParamRefExpression.ParameterName);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyParamRefExpression.ResultType, paramRefExpression.ResultType);
        }
        public void Visit_DbCastExpression_creates_equivalent_legacy_DbCastExpression()
        {
            var castExpression =
                DbExpressionBuilder.Constant(42).CastTo(
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Decimal)));

            var legacyCastExpression =
                _legacyDbExpressionConverter.Visit(castExpression) as LegacyCommandTrees.DbCastExpression;

            Assert.NotNull(legacyCastExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Cast, legacyCastExpression.ExpressionKind);
            Assert.Equal(42, (int)((LegacyCommandTrees.DbConstantExpression)legacyCastExpression.Argument).Value);
            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyCastExpression.ResultType, castExpression.ResultType);
        }
        public void Visit_DbOrExpression_creates_equivalent_legacy_DbOrExpression()
        {
            var orExpression =
                DbExpressionBuilder.False
                .Or(DbExpressionBuilder.True);

            var legacyOrExpression =
                _legacyDbExpressionConverter.Visit(orExpression) as LegacyCommandTrees.DbOrExpression;

            Assert.NotNull(legacyOrExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Or, legacyOrExpression.ExpressionKind);
            Assert.False((bool)((LegacyCommandTrees.DbConstantExpression)legacyOrExpression.Left).Value);
            Assert.True((bool)((LegacyCommandTrees.DbConstantExpression)legacyOrExpression.Right).Value);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyOrExpression.ResultType, orExpression.ResultType);
        }
        public void Visit_DbScanExpression_creates_equivalent_legacy_DbScanExpression()
        {
            var scanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var legacyScanExpression =
                _legacyDbExpressionConverter.Visit(scanExpression) as LegacyCommandTrees.DbScanExpression;

            Assert.NotNull(legacyScanExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Scan, legacyScanExpression.ExpressionKind);
            Assert.Equal(scanExpression.Target.Name, legacyScanExpression.Target.Name);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyScanExpression.ResultType, scanExpression.ResultType);
        }
        Visit_DbVariableReferenceExpression_creates_equivalent_legacy_DbVariableReferenceExpression_for_CSpace_type()
        {
            var variableReference =
                TypeUsage
                .CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))
                .Variable("variable");

            var legacyVariableReference =
                _legacyDbExpressionConverter.Visit(variableReference) as
                LegacyCommandTrees.DbVariableReferenceExpression;

            Assert.NotNull(legacyVariableReference);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.VariableReference, legacyVariableReference.ExpressionKind);
            Assert.Equal(variableReference.VariableName, legacyVariableReference.VariableName);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyVariableReference.ResultType, variableReference.ResultType);
        }
        private void ConvertAndVerifyArithmeticExpression(DbArithmeticExpression arithmeticExpression)
        {
            var legacyArithmeticExpression =
                _legacyDbExpressionConverter.Visit(arithmeticExpression) as LegacyCommandTrees.DbArithmeticExpression;

            Assert.NotNull(arithmeticExpression);

            Assert.Equal((int)arithmeticExpression.ExpressionKind, (int)legacyArithmeticExpression.ExpressionKind);
            Assert.Equal(arithmeticExpression.Arguments.Count, legacyArithmeticExpression.Arguments.Count);
            Assert.True(
                arithmeticExpression.Arguments.Zip(
                    legacyArithmeticExpression.Arguments,
                    (e1, e2) => ((DbConstantExpression)e1).Value == ((LegacyCommandTrees.DbConstantExpression)e2).Value)
                .All(r => r));

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyArithmeticExpression.ResultType, arithmeticExpression.ResultType);
        }
        public void Visit_DbProjectExpression_creates_equivalent_legacy_DbProjectExpression()
        {
            var scanExpression =
                _storeItemCollection
                .GetEntityContainer("AdventureWorksModelStoreContainer")
                .EntitySets.Single(e => e.Name == "EntitiesSet")
                .Scan();

            var propertyExpression =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("Table")
                .Property("Id");

            var newInstanceExpression =
                DbExpressionBuilder.NewRow(
                    new[]
            {
                new KeyValuePair <string, DbExpression>("Id", propertyExpression),
                new KeyValuePair <string, DbExpression>("Const", DbExpressionBuilder.Constant(42))
            });

            var projectExpression =
                scanExpression
                .BindAs("Table")
                .Project(newInstanceExpression);

            var legacyProjectExpression =
                _legacyDbExpressionConverter.Visit(projectExpression) as LegacyCommandTrees.DbProjectExpression;

            Assert.NotNull(legacyProjectExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Project, legacyProjectExpression.ExpressionKind);
            Assert.Equal(
                LegacyCommandTrees.DbExpressionKind.NewInstance,
                legacyProjectExpression.Projection.ExpressionKind);
            Assert.Equal(projectExpression.Input.VariableName, legacyProjectExpression.Input.VariableName);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyProjectExpression.Input.VariableType, projectExpression.Input.VariableType);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyProjectExpression.ResultType, projectExpression.ResultType);
        }
        private void ConvertAndVerifyComparisonExpression(DbComparisonExpression comparisonExpression)
        {
            var legacyComparisonExpression =
                _legacyDbExpressionConverter.Visit(comparisonExpression) as LegacyCommandTrees.DbComparisonExpression;

            Assert.NotNull(legacyComparisonExpression);
            Assert.Equal((int)comparisonExpression.ExpressionKind, (int)legacyComparisonExpression.ExpressionKind);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Constant, legacyComparisonExpression.Left.ExpressionKind);
            Assert.Equal(
                ((DbConstantExpression)comparisonExpression.Left).Value,
                ((LegacyCommandTrees.DbConstantExpression)legacyComparisonExpression.Left).Value);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Constant, legacyComparisonExpression.Right.ExpressionKind);
            Assert.Equal(
                ((DbConstantExpression)comparisonExpression.Right).Value,
                ((LegacyCommandTrees.DbConstantExpression)legacyComparisonExpression.Right).Value);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyComparisonExpression.ResultType, comparisonExpression.ResultType);
        }
        Visit_DbVariableReferenceExpression_creates_equivalent_legacy_DbVariableReferenceExpression_for_SSpace_type()
        {
            var variableReference =
                TypeUsage
                .CreateDefaultTypeUsage(
                    _storeItemCollection.GetItems <EntityType>().Single(e => e.Name == "Entities"))
                .Variable("variable");

            var legacyVariableReference =
                _legacyDbExpressionConverter.Visit(variableReference) as
                LegacyCommandTrees.DbVariableReferenceExpression;

            Assert.NotNull(legacyVariableReference);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.VariableReference, legacyVariableReference.ExpressionKind);
            Assert.Equal(variableReference.VariableName, legacyVariableReference.VariableName);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyVariableReference.ResultType, variableReference.ResultType);
        }
        public void Visit_DbElementExpression_creates_equivalent_legacy_DbElementExpression()
        {
            var elementExpression =
                DbExpressionBuilder.NewCollection(new DbExpression[] { DbExpressionBuilder.Constant(42) })
                .Element();

            var legacyElementExpression
                = _legacyDbExpressionConverter.Visit(elementExpression) as LegacyCommandTrees.DbElementExpression;

            Assert.NotNull(legacyElementExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Element, legacyElementExpression.ExpressionKind);
            Assert.Equal(
                42,
                (((LegacyCommandTrees.DbConstantExpression)
                      ((LegacyCommandTrees.DbNewInstanceExpression)legacyElementExpression.Argument).Arguments.Single())
                 .Value));

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyElementExpression.ResultType, elementExpression.ResultType);
        }
Ejemplo n.º 29
0
        public void GetStoreTypes_returns_all_store_types_correctly()
        {
            var storeTypes =
                new LegacyDbProviderManifestWrapper(LegacyProviderManifest)
                .GetStoreTypes()
                .OrderBy(t => t.Name)
                .ToArray();

            var legacyStoreTypes =
                LegacyProviderManifest
                .GetStoreTypes()
                .OrderBy(t => t.Name)
                .ToArray();

            Assert.Equal(storeTypes.Length, legacyStoreTypes.Length);

            for (var idx = 0; idx < storeTypes.Length; idx++)
            {
                TypeUsageVerificationHelper.VerifyEdmTypesEquivalent(legacyStoreTypes[idx], storeTypes[idx]);
            }
        }
        public void Visit_DbConstantExpression_creates_equivalent_legacy_DbConstantExpression()
        {
            var typeUsage =
                TypeUsage.CreateStringTypeUsage(
                    PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String),
                    isUnicode: false,
                    isFixedLength: true,
                    maxLength: 1000);

            var constantExpression = typeUsage.Constant("test");

            var legacyConstantExpression =
                _legacyDbExpressionConverter.Visit(constantExpression) as LegacyCommandTrees.DbConstantExpression;

            Assert.NotNull(legacyConstantExpression);
            Assert.Equal(LegacyCommandTrees.DbExpressionKind.Constant, legacyConstantExpression.ExpressionKind);
            Assert.Equal(constantExpression.Value, legacyConstantExpression.Value);

            TypeUsageVerificationHelper
            .VerifyTypeUsagesEquivalent(legacyConstantExpression.ResultType, constantExpression.ResultType);
        }