public void Constructor_Sets_Properties() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.Snapshot, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.OData40); Assert.Equal(ODataIsolationLevel.Snapshot, odataRequestOptions.IsolationLevel); Assert.Equal(ODataVersion.OData40, odataRequestOptions.ODataMaxVersion); Assert.Equal(ODataMetadataLevel.Minimal, odataRequestOptions.MetadataLevel); Assert.Equal(new Uri("https://services.odata.org/OData"), odataRequestOptions.ServiceRootUri); Assert.Equal(ODataVersion.OData40, odataRequestOptions.ODataVersion); }
public void Validate_ODataRequestOptions_DoesNotThrow_If_AllRequestOptions_Supported() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.OData40); var odataServiceOptions = new ODataServiceOptions( ODataVersion.MinVersion, ODataVersion.MaxVersion, new[] { ODataIsolationLevel.None }, new[] { "application/json" }); odataServiceOptions.Validate(odataRequestOptions); }
public void Validate_ODataRequestOptions_Throws_ODataException_If_ODataVersion_BelowMinSupported() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Minimal, ODataVersion.Parse("3.0"), // symantically this makes no sense but the scenario is needed for the test case. ODataVersion.OData40); var odataServiceOptions = new ODataServiceOptions( ODataVersion.MinVersion, ODataVersion.MaxVersion, new[] { ODataIsolationLevel.None }, new[] { "application/json" }); ODataException odataException = Assert.Throws <ODataException>(() => odataServiceOptions.Validate(odataRequestOptions)); Assert.Equal(ExceptionMessage.ODataVersionNotSupported(odataRequestOptions.ODataVersion, odataServiceOptions.MinVersion, odataServiceOptions.MaxVersion), odataException.Message); Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode); Assert.Equal(ODataRequestHeaderNames.ODataVersion, odataException.Target); }
public void Validate_ODataRequestOptions_Throws_ODataException_If_ODataMaxVersion_AboveMaxSupported() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.Parse("5.0")); var odataServiceOptions = new ODataServiceOptions( ODataVersion.MinVersion, ODataVersion.MaxVersion, new[] { ODataIsolationLevel.None }, new[] { "application/json" }); ODataException odataException = Assert.Throws <ODataException>(() => odataServiceOptions.Validate(odataRequestOptions)); Assert.Equal(ExceptionMessage.ODataMaxVersionNotSupported(odataRequestOptions.ODataMaxVersion, odataServiceOptions.MinVersion, odataServiceOptions.MaxVersion), odataException.Message); Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode); Assert.Equal(ODataRequestHeaderNames.ODataMaxVersion, odataException.Target); }
public void Validate_ODataRequestOptions_Throws_ODataException_If_MetadataLevel_NotSupported() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.None, ODataMetadataLevel.Full, ODataVersion.OData40, ODataVersion.OData40); var odataServiceOptions = new ODataServiceOptions( ODataVersion.MinVersion, ODataVersion.MaxVersion, new[] { ODataIsolationLevel.None }, new[] { "application/json" }); ODataException odataException = Assert.Throws <ODataException>(() => odataServiceOptions.Validate(odataRequestOptions)); Assert.Equal(ExceptionMessage.ODataMetadataLevelNotSupported("full", new[] { "none", "minimal" }), odataException.Message); Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode); Assert.Equal("odata.metadata", odataException.Target); }
public void Validate_ODataRequestOptions_Throws_ODataException_If_IsolationLevel_NotSupported() { var odataRequestOptions = new ODataRequestOptions( new Uri("https://services.odata.org/OData"), ODataIsolationLevel.Snapshot, ODataMetadataLevel.Minimal, ODataVersion.OData40, ODataVersion.OData40); var odataServiceOptions = new ODataServiceOptions( ODataVersion.MinVersion, ODataVersion.MaxVersion, new[] { ODataIsolationLevel.None }, new[] { "application/json" }); ODataException odataException = Assert.Throws <ODataException>(() => odataServiceOptions.Validate(odataRequestOptions)); Assert.Equal(ExceptionMessage.ODataIsolationLevelNotSupported("Snapshot"), odataException.Message); Assert.Equal(HttpStatusCode.PreconditionFailed, odataException.StatusCode); Assert.Equal(ODataRequestHeaderNames.ODataIsolation, odataException.Target); }
/// <summary> /// Creates the <see cref="ServiceDocumentItem"/>s that represent the Entity Data Model. /// </summary> /// <param name="entityDataModel">The Entity Data Model.</param> /// <param name="requestOptions">The OData request options.</param> /// <returns>The <see cref="ServiceDocumentItem"/>s.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="entityDataModel"/> or <paramref name="requestOptions"/> are null.</exception> public static IEnumerable <ServiceDocumentItem> Create(EntityDataModel entityDataModel, ODataRequestOptions requestOptions) { if (entityDataModel is null) { throw new ArgumentNullException(nameof(entityDataModel)); } if (requestOptions is null) { throw new ArgumentNullException(nameof(requestOptions)); } IEnumerable <ServiceDocumentItem> serviceDocumentItems = entityDataModel.EntitySets.Select( kvp => { var setUri = new Uri(kvp.Key, UriKind.Relative); setUri = requestOptions.MetadataLevel == ODataMetadataLevel.None ? new Uri(requestOptions.ServiceRootUri, setUri) : setUri; return(ServiceDocumentItem.EntitySet(kvp.Key, setUri)); }); return(serviceDocumentItems); }