Пример #1
0
        private static void Test_create_copies_value <T>(FacetDescription description, T value)
        {
            var facet = Facet.Create(description, value: value);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
Пример #2
0
        private static bool Equal <T>(FacetValues leftValues, FacetValues rightValues, string facetName)
        {
            var description = FacetDescriptionHelpers.GetFacetDescription <T>(facetName);

            Facet leftFacet     = null;
            var   leftHasValue  = leftValues.TryGetFacet(description, out leftFacet);
            Facet rightFacet    = null;
            var   rightHasValue = rightValues.TryGetFacet(description, out rightFacet);

            return((leftHasValue && rightHasValue &&
                    EqualityComparer <T> .Default.Equals((T)leftFacet.Value, (T)rightFacet.Value)) ||
                   (!leftHasValue && !rightHasValue));
        }
Пример #3
0
        public void Create_copies_value_from_StoreGeneratedPatternFacet()
        {
            var description = new FacetDescription(
                EdmProviderManifest.StoreGeneratedPatternFacetName, new EnumType(typeof(StoreGeneratedPattern)), null, null, null);
            var facet = Facet.Create(description, value: StoreGeneratedPattern.Computed);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
Пример #4
0
        public void Create_copies_value_from_ConcurrencyModeFacet()
        {
            var description = new FacetDescription(
                EdmProviderManifest.ConcurrencyModeFacetName, new EnumType(typeof(ConcurrencyMode)), null, null, null);
            var facet = Facet.Create(description, value: ConcurrencyMode.Fixed);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
Пример #5
0
 internal static bool Equal <TValue>(FacetValues leftValues, FacetValues rightValues)
 {
     return(Equal <string>(leftValues, rightValues, DbProviderManifest.CollationFacetName) &&
            Equal <CollectionKind>(leftValues, rightValues, EdmConstants.CollectionKind) &&
            Equal <ConcurrencyMode>(leftValues, rightValues, EdmProviderManifest.ConcurrencyModeFacetName) &&
            Equal <TValue>(leftValues, rightValues, DbProviderManifest.DefaultValueFacetName) &&
            Equal <bool>(leftValues, rightValues, DbProviderManifest.FixedLengthFacetName) &&
            Equal <bool>(leftValues, rightValues, DbProviderManifest.IsStrictFacetName) &&
            Equal <int>(leftValues, rightValues, DbProviderManifest.MaxLengthFacetName) &&
            Equal <bool>(leftValues, rightValues, DbProviderManifest.NullableFacetName) &&
            Equal <bool>(leftValues, rightValues, DbProviderManifest.UnicodeFacetName) &&
            Equal <byte>(leftValues, rightValues, DbProviderManifest.PrecisionFacetName) &&
            Equal <byte>(leftValues, rightValues, DbProviderManifest.ScaleFacetName) &&
            Equal <int>(leftValues, rightValues, DbProviderManifest.SridFacetName) &&
            Equal <StoreGeneratedPattern>(leftValues, rightValues, EdmProviderManifest.StoreGeneratedPatternFacetName));
 }
Пример #6
0
        public void Create_copies_value_from_PrecisionFacet()
        {
            var description = new FacetDescription(
                DbProviderManifest.PrecisionFacetName, new PrimitiveType {
                PrimitiveTypeKind = PrimitiveTypeKind.Byte
            }, null, null, null);
            var facet = Facet.Create(description, value: (byte)1);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
Пример #7
0
 private static IEnumerable <Facet> OverrideFacetValues <T>(
     IEnumerable <T> facetThings,
     Func <T, FacetDescription> getDescription,
     Func <T, Facet> getFacet,
     FacetValues values)
 {
     foreach (T facetThing in facetThings)
     {
         FacetDescription description = getDescription(facetThing);
         Facet            facet;
         if (!description.IsConstant && values.TryGetFacet(description, out facet))
         {
             yield return(facet);
         }
         else
         {
             yield return(getFacet(facetThing));
         }
     }
 }
Пример #8
0
 /// <summary>
 ///     Factory method for creating a TypeUsage with specified EdmType
 /// </summary>
 /// <param name="edmType"> EdmType for which to create a type usage </param>
 /// <returns> new TypeUsage instance with default facet values </returns>
 internal static TypeUsage Create(EdmType edmType, FacetValues values)
 {
     return(new TypeUsage(
                edmType,
                GetDefaultFacetDescriptionsAndOverrideFacetValues(edmType, values)));
 }
Пример #9
0
 private static IEnumerable <Facet> OverrideFacetValues(IEnumerable <Facet> facets, FacetValues values)
 {
     return(OverrideFacetValues(
                facets,
                f => f.Description,
                f => f,
                values));
 }
Пример #10
0
 private static IEnumerable <Facet> GetDefaultFacetDescriptionsAndOverrideFacetValues(EdmType type, FacetValues values)
 {
     return(OverrideFacetValues(
                type.GetAssociatedFacetDescriptions(),
                fd => fd,
                fd => fd.DefaultValueFacet,
                values));
 }
Пример #11
0
 private static TypeUsage CreateType(PrimitiveTypeKind type, FacetValues facets)
 {
     var primitiveType = EdmProviderManifest.Instance.GetPrimitiveType(type);
     var typeUsage = TypeUsage.Create(primitiveType, facets);
     return typeUsage;
 }
Пример #12
0
 private static IEnumerable <Facet> OverrideFacetValues(
     IEnumerable <Facet> facets,
     FacetValues values)
 {
     return(TypeUsage.OverrideFacetValues <Facet>(facets, (Func <Facet, FacetDescription>)(f => f.Description), (Func <Facet, Facet>)(f => f), values));
 }
Пример #13
0
 private static IEnumerable <Facet> GetDefaultFacetDescriptionsAndOverrideFacetValues(
     EdmType type,
     FacetValues values)
 {
     return(TypeUsage.OverrideFacetValues <FacetDescription>(type.GetAssociatedFacetDescriptions(), (Func <FacetDescription, FacetDescription>)(fd => fd), (Func <FacetDescription, Facet>)(fd => fd.DefaultValueFacet), values));
 }
Пример #14
0
 internal TypeUsage ShallowCopy(FacetValues facetValues)
 {
     return(Create(_edmType, OverrideFacetValues(Facets, facetValues)));
 }
Пример #15
0
        public static FacetValues Create(IEnumerable<Facet> facets)
        {
            var facetValues = new FacetValues();
            foreach (var facet in facets)
            {
                var description = facet.Description;
                switch (description.FacetName)
                {
                    case DbProviderManifest.NullableFacetName:
                        facetValues.Nullable = (bool?)facet.Value;
                        break;
                    case DbProviderManifest.MaxLengthFacetName:
                        var unboundedLength = facet.Value as EdmConstants.Unbounded;
                        if (unboundedLength != null)
                        {
                            facetValues.MaxLength = unboundedLength;
                        }
                        else
                        {
                            facetValues.MaxLength = (int?)facet.Value;
                        }
                        break;
                    case DbProviderManifest.UnicodeFacetName:
                        facetValues.Unicode = (bool?)facet.Value;
                        break;
                    case DbProviderManifest.FixedLengthFacetName:
                        facetValues.FixedLength = (bool?)facet.Value;
                        break;
                    case DbProviderManifest.PrecisionFacetName:
                        var unboundedPrecision = facet.Value as EdmConstants.Unbounded;
                        if (unboundedPrecision != null)
                        {
                            facetValues.Precision = unboundedPrecision;
                        }
                        else
                        {
                            facetValues.Precision = (byte?)facet.Value;
                        }
                        break;
                    case DbProviderManifest.ScaleFacetName:
                        var unboundedScale = facet.Value as EdmConstants.Unbounded;
                        if (unboundedScale != null)
                        {
                            facetValues.Scale = unboundedScale;
                        }
                        else
                        {
                            facetValues.Scale = (byte?)facet.Value;
                        }
                        break;
                    case DbProviderManifest.DefaultValueFacetName:
                        facetValues.DefaultValue = facet.Value;
                        break;
                    case DbProviderManifest.CollationFacetName:
                        facetValues.Collation = (string)facet.Value;
                        break;
                    case DbProviderManifest.SridFacetName:
                        facetValues.Srid = (int?)facet.Value;
                        break;
                    case DbProviderManifest.IsStrictFacetName:
                        facetValues.IsStrict = (bool?)facet.Value;
                        break;
                    case EdmProviderManifest.StoreGeneratedPatternFacetName:
                        facetValues.StoreGeneratedPattern = (StoreGeneratedPattern?)facet.Value;
                        break;
                    case EdmProviderManifest.ConcurrencyModeFacetName:
                        facetValues.ConcurrencyMode = (ConcurrencyMode?)facet.Value;
                        break;
                    case EdmConstants.CollectionKind:
                        facetValues.CollectionKind = (CollectionKind?)facet.Value;
                        break;
                    default:
                        Debug.Assert(false, "Unrecognized facet: " + description.FacetName);
                        break;
                }
            }

            return facetValues;
        }
Пример #16
0
        internal virtual FacetValues ToFacetValues()
        {
            var facets = new FacetValues();

            if (DefaultValue != null)
            {
                facets.DefaultValue = DefaultValue;
            }

            if (IsFixedLength != null)
            {
                facets.FixedLength = IsFixedLength.Value;
            }

            if (IsUnicode != null)
            {
                facets.Unicode = IsUnicode.Value;
            }

            if (MaxLength != null)
            {
                facets.MaxLength = MaxLength.Value;
            }

            if (Precision != null)
            {
                facets.Precision = Precision.Value;
            }

            if (Scale != null)
            {
                facets.Scale = Scale.Value;
            }

            return facets;
        }
        public static FacetValues Create(IEnumerable <Facet> facets)
        {
            FacetValues facetValues = new FacetValues();

            foreach (Facet facet in facets)
            {
                switch (facet.Description.FacetName)
                {
                case "Nullable":
                    facetValues.Nullable = (FacetValueContainer <bool?>)((bool?)facet.Value);
                    continue;

                case "MaxLength":
                    EdmConstants.Unbounded unbounded1 = facet.Value as EdmConstants.Unbounded;
                    facetValues.MaxLength = unbounded1 == null ? (FacetValueContainer <int?>)((int?)facet.Value) : (FacetValueContainer <int?>)unbounded1;
                    continue;

                case "Unicode":
                    facetValues.Unicode = (FacetValueContainer <bool?>)((bool?)facet.Value);
                    continue;

                case "FixedLength":
                    facetValues.FixedLength = (FacetValueContainer <bool?>)((bool?)facet.Value);
                    continue;

                case "Precision":
                    EdmConstants.Unbounded unbounded2 = facet.Value as EdmConstants.Unbounded;
                    facetValues.Precision = unbounded2 == null ? (FacetValueContainer <byte?>)((byte?)facet.Value) : (FacetValueContainer <byte?>)unbounded2;
                    continue;

                case "Scale":
                    EdmConstants.Unbounded unbounded3 = facet.Value as EdmConstants.Unbounded;
                    facetValues.Scale = unbounded3 == null ? (FacetValueContainer <byte?>)((byte?)facet.Value) : (FacetValueContainer <byte?>)unbounded3;
                    continue;

                case "DefaultValue":
                    facetValues.DefaultValue = facet.Value;
                    continue;

                case "Collation":
                    facetValues.Collation = (FacetValueContainer <string>)((string)facet.Value);
                    continue;

                case "SRID":
                    facetValues.Srid = (FacetValueContainer <int?>)((int?)facet.Value);
                    continue;

                case "IsStrict":
                    facetValues.IsStrict = (FacetValueContainer <bool?>)((bool?)facet.Value);
                    continue;

                case "StoreGeneratedPattern":
                    facetValues.StoreGeneratedPattern = (FacetValueContainer <System.Data.Entity.Core.Metadata.Edm.StoreGeneratedPattern?>)((System.Data.Entity.Core.Metadata.Edm.StoreGeneratedPattern?)facet.Value);
                    continue;

                case "ConcurrencyMode":
                    facetValues.ConcurrencyMode = (FacetValueContainer <System.Data.Entity.Core.Metadata.Edm.ConcurrencyMode?>)((System.Data.Entity.Core.Metadata.Edm.ConcurrencyMode?)facet.Value);
                    continue;

                case "CollectionKind":
                    facetValues.CollectionKind = (FacetValueContainer <System.Data.Entity.Core.Metadata.Edm.CollectionKind?>)((System.Data.Entity.Core.Metadata.Edm.CollectionKind?)facet.Value);
                    continue;

                default:
                    continue;
                }
            }
            return(facetValues);
        }
Пример #18
0
 internal TypeUsage ShallowCopy(FacetValues facetValues)
 {
     return(TypeUsage.Create(this._edmType, TypeUsage.OverrideFacetValues((IEnumerable <Facet>) this.Facets, facetValues)));
 }
Пример #19
0
        public static FacetValues Create(IEnumerable <Facet> facets)
        {
            var facetValues = new FacetValues();

            foreach (var facet in facets)
            {
                var description = facet.Description;
                switch (description.FacetName)
                {
                case DbProviderManifest.NullableFacetName:
                    facetValues.Nullable = (bool?)facet.Value;
                    break;

                case DbProviderManifest.MaxLengthFacetName:
                    var unboundedLength = facet.Value as EdmConstants.Unbounded;
                    if (unboundedLength != null)
                    {
                        facetValues.MaxLength = unboundedLength;
                    }
                    else
                    {
                        facetValues.MaxLength = (int?)facet.Value;
                    }
                    break;

                case DbProviderManifest.UnicodeFacetName:
                    facetValues.Unicode = (bool?)facet.Value;
                    break;

                case DbProviderManifest.FixedLengthFacetName:
                    facetValues.FixedLength = (bool?)facet.Value;
                    break;

                case DbProviderManifest.PrecisionFacetName:
                    var unboundedPrecision = facet.Value as EdmConstants.Unbounded;
                    if (unboundedPrecision != null)
                    {
                        facetValues.Precision = unboundedPrecision;
                    }
                    else
                    {
                        facetValues.Precision = (byte?)facet.Value;
                    }
                    break;

                case DbProviderManifest.ScaleFacetName:
                    var unboundedScale = facet.Value as EdmConstants.Unbounded;
                    if (unboundedScale != null)
                    {
                        facetValues.Scale = unboundedScale;
                    }
                    else
                    {
                        facetValues.Scale = (byte?)facet.Value;
                    }
                    break;

                case DbProviderManifest.DefaultValueFacetName:
                    facetValues.DefaultValue = facet.Value;
                    break;

                case DbProviderManifest.CollationFacetName:
                    facetValues.Collation = (string)facet.Value;
                    break;

                case DbProviderManifest.SridFacetName:
                    facetValues.Srid = (int?)facet.Value;
                    break;

                case DbProviderManifest.IsStrictFacetName:
                    facetValues.IsStrict = (bool?)facet.Value;
                    break;

                case EdmProviderManifest.StoreGeneratedPatternFacetName:
                    facetValues.StoreGeneratedPattern = (StoreGeneratedPattern?)facet.Value;
                    break;

                case EdmProviderManifest.ConcurrencyModeFacetName:
                    facetValues.ConcurrencyMode = (ConcurrencyMode?)facet.Value;
                    break;

                case EdmConstants.CollectionKind:
                    facetValues.CollectionKind = (CollectionKind?)facet.Value;
                    break;

                default:
                    Debug.Assert(false, "Unrecognized facet: " + description.FacetName);
                    break;
                }
            }

            return(facetValues);
        }
Пример #20
0
        public void ToFacetValues_returns_specified_facet_values()
        {
            var columnModel = new ColumnModel(PrimitiveTypeKind.Boolean)
            {
                DefaultValue = 0.1,
                IsFixedLength = true,
                IsIdentity = true,
                IsNullable = true,
                IsUnicode = true,
                MaxLength = 64,
                Precision = 5,
                Scale = 3
            };

            var expectedFacetValues = new FacetValues()
            {
                DefaultValue = 0.1,
                FixedLength = true,
                StoreGeneratedPattern = StoreGeneratedPattern.Identity,
                Nullable = true,
                Unicode = true,
                MaxLength = (int?)64,
                Precision = (byte?)5,
                Scale = (byte?)3
            };

            Assert.True(FacetValuesHelpers.Equal<double>(expectedFacetValues, columnModel.ToFacetValues()));
        }