Exemplo n.º 1
0
        public void UrlConventionFromSettingAndTypeContextShouldReturnKeyAsSegmentIfSettingIsNullAndTypeContextReturnsKeyAsSegment()
        {
            var typeContext = new TestFeedAndEntryTypeContext()
            {
                UrlConvention = UrlConvention.CreateWithExplicitValue(/*generateKeyAsSegment*/ true)
            };

            UrlConvention.ForUserSettingAndTypeContext(null, typeContext).GenerateKeyAsSegment.Should().BeTrue();
        }
Exemplo n.º 2
0
        public void Init()
        {
            this.keyProperty1 = new ResourceProperty("Key1", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)));
            this.keyProperty2 = new ResourceProperty("Key2", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));

            this.defaultSerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(false));
            this.segmentSerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(true));

            this.singleKeyProperty = new[] { this.keyProperty1 };
            this.compositeKey      = new[] { this.keyProperty1, this.keyProperty2 };
        }
Exemplo n.º 3
0
 public void FullMetadataLevelShouldReturnODataConventionalEntityMetadataBuilder()
 {
     testSubject.CreateEntityMetadataBuilder(
         new ODataEntry(),
         new TestFeedAndEntryTypeContext {
         UrlConvention = UrlConvention.CreateWithExplicitValue(generateKeyAsSegment: false)
     }, new ODataFeedAndEntrySerializationInfo(), /*actualEntityType*/ null,
         SelectedPropertiesNode.EntireSubtree,
         /*isResponse*/ true,
         /*keyAsSegment*/ false,
         /*requestUri*/ null).Should().BeAssignableTo <ODataConventionalEntityMetadataBuilder>();
 }
Exemplo n.º 4
0
        private static EntityToSerialize CreateEntityToSerialize(bool shouldIncludeTypeSegment)
        {
            ResourceType baseType = new ResourceType(typeof(MyType), ResourceTypeKind.EntityType, null, "TestNamespace", "BaseType", /*isAbstract*/ false);

            baseType.AddProperty(new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, new ResourceType(typeof(int), ResourceTypeKind.Primitive, null, "int")));

            baseType.SetReadOnly();

            Uri serviceUri = new Uri("http://dummy");

            KeySerializer keySerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(false));

            Func <ResourceProperty, object> getPropertyValue = p => "fakePropertyValue";

            return(EntityToSerialize.Create(new MyType {
                ID = 42
            }, baseType, "MySet", shouldIncludeTypeSegment, getPropertyValue, keySerializer, serviceUri));
        }
 /// <summary>
 /// Private constructor since the singleton instance is sufficient.
 /// </summary>
 /// <param name="keyAsSegment">Whether use key as segment</param>
 private PathSegmentToContextUrlPathTranslator(bool keyAsSegment)
 {
     KeySerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(keyAsSegment));
 }
Exemplo n.º 6
0
        private static void RunPinningTest(StringBuilder builder, params object[] keyValues)
        {
            var compositeKey = keyValues.Select((k, i) => new { Name = "prop" + i, Value = k }).ToArray();
            var allKeys      = keyValues.Select(k => new[] { new { Name = "prop", Value = k } }).Concat(new[] { compositeKey });

            foreach (var key in allKeys)
            {
                if (builder.Length > 0)
                {
                    builder.AppendLine();
                }

                var properties = key.Select(p => new EdmPropertyValue(p.Name, EdmValueUtils.ConvertPrimitiveValue(p.Value, null).Value)).ToList();
                var entityType = new EdmEntityType("Fake", "Fake");
                entityType.AddKeys(properties.Select(p => new EdmStructuralProperty(entityType, p.Name, p.Value.Type)));
                var entity = new EdmStructuredValue(new EdmEntityTypeReference(entityType, false), properties);
                ODataConventionalUriBuilder uriBuilder = new ODataConventionalUriBuilder(new Uri("http://baseuri.org/"), UrlConvention.CreateWithExplicitValue(false));
                var entityInstanceUri = uriBuilder.BuildEntityInstanceUri(new Uri("http://baseuri.org/Customers"), new Collection <KeyValuePair <string, object> >(properties.Select(p => new KeyValuePair <string, object>(p.Name, ((IEdmPrimitiveValue)p.Value).ToClrValue())).ToList()), entity.Type.FullName());
                builder.Append(entityInstanceUri.OriginalString.Replace("http://baseuri.org/Customers", null).Replace("()", "%28%29"));
            }

            builder.AppendLine();
        }
Exemplo n.º 7
0
        public void InitTest()
        {
            this.navigationLink = new ODataNavigationLink();

            var entry = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };

            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
            var metadataBuilder      = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));

            this.navigationLinkWithFullBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithFullBuilder.MetadataBuilder = metadataBuilder;

            this.navigationLinkWithNoOpBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithNoOpBuilder.MetadataBuilder = new NoOpEntityMetadataBuilder(entry);

            this.navigationLinkWithNullBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithNullBuilder.MetadataBuilder = ODataEntityMetadataBuilder.Null;
        }
Exemplo n.º 8
0
        public ODataOperationTests()
        {
            this.testSubject = new TestODataOperation();

            var entry = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };

            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
            var fullMetadataBuilder  = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));

            this.operationWithFullBuilder = new TestODataOperation {
                Metadata = ContextUri
            };
            this.operationWithFullBuilder.SetMetadataBuilder(fullMetadataBuilder, MetadataDocumentUri);
        }
Exemplo n.º 9
0
        public ODataEntryTests()
        {
            this.odataEntry = new ODataEntry();

            this.odataEntryWithFullBuilder = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };
            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(this.odataEntryWithFullBuilder, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);

            this.odataEntryWithFullBuilder.MetadataBuilder = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(new Uri("http://service/", UriKind.Absolute), UrlConvention.CreateWithExplicitValue(false)));

            this.odataEntryWithNullBuilder = new ODataEntry {
                MetadataBuilder = ODataEntityMetadataBuilder.Null
            };
        }
        public ODataConventionalUriBuilderTests()
        {
            this.defaultBaseUri = new Uri("http://odata.org/base/");
            this.builder        = new ODataConventionalUriBuilder(this.defaultBaseUri, UrlConvention.CreateWithExplicitValue(false));

            this.model = TestModel.BuildDefaultTestModel();
            this.defaultProductInstance     = TestModel.BuildDefaultProductValue(TestModel.GetEntityType(this.model, "TestModel.Product"));
            this.defaultMultipleKeyInstance = TestModel.BuildDefaultMultipleKeyValue(this.model);

            this.idPropertyList = new Dictionary <string, IEdmValue>()
            {
                { "Id", new EdmIntegerConstant(EdmCoreModel.Instance.GetInt32(false), 42) }
            };

            this.typeWithStringKey = new EdmEntityType("Test.Model", "StringKey");
            this.typeWithStringKey.AddKeys(this.typeWithStringKey.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String));
        }