public ServiceVersion(ODataProtocolVersion version) { switch (version) { case ODataProtocolVersion.V4: this.Version = 40; break; } }
public override DataServiceContext ReaderClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { var ctx = base.ReaderClient(serviceRoot, protocolVersion); //new JsonLightConfigurator(ctx, AcceptHeader).Configure(); ctx.Format.UseJson(GetEdmModel()); return ctx; }
/// <summary> /// Initializes a new TestWebRequest instance with simple defaults /// that have no side-effects on querying. /// </summary> public DataServiceContextWithCustomTransportLayer(Uri serviceUri, ODataProtocolVersion maxProtocolVersion, Func<IODataRequestMessage> getRequestMessage, Func<IODataResponseMessage> getResponseMessage) : base(serviceUri, maxProtocolVersion) { this.getRequestMessage = getRequestMessage; this.getResponseMessage = getResponseMessage; this.Configurations.RequestPipeline.OnMessageCreating = this.CreateMessage; }
public TestClientContext(Uri serviceRoot, ODataProtocolVersion version, ClientEdmModel model) : base(serviceRoot, version, model) { }
/// <summary> /// Constructor. /// </summary> /// <param name="maxProtocolVersion">The protocol version this Edm model is created for.</param> internal ClientEdmModel(ODataProtocolVersion maxProtocolVersion) { this.maxProtocolVersion = maxProtocolVersion; }
private DataServiceContextWithCustomTransportLayer CreateTransportLayerContext(string payload, string odataVersion, ODataProtocolVersion maxDataServiceVersion, string contentTypeHeaderValue = MimeApplicationAtom) { IODataRequestMessage requestMessage = new ODataTestMessage(); var responseMessage = new ODataTestMessage(); responseMessage.SetHeader("Content-Type", contentTypeHeaderValue); responseMessage.SetHeader("OData-Version", odataVersion); responseMessage.StatusCode = 200; responseMessage.WriteToStream(payload); responseMessage.SetHeader("Content-Length", responseMessage.MemoryStream.Length.ToString()); var context = new DataServiceContextWithCustomTransportLayer(maxDataServiceVersion, requestMessage, responseMessage); context.EnableAtom = true; context.ResolveName = ResolveName; context.ResolveType = ResolveType; context.Format.UseJson(Model); return context; }
public DataServiceContextWithCustomTransportLayer(ODataProtocolVersion protocolVersion, IODataRequestMessage requestMessage, IODataResponseMessage responseMessage) : this(protocolVersion, () => requestMessage, () => responseMessage) { }
private static bool IsValidScenario(TestWebRequest request, ODataProtocolVersion protocolVersion, ServiceVersions versions, ServiceVersion requestDSV, ServiceVersion requestMDSV, Exception exception) { // figure out the default values of the version if they are null if (requestDSV == null && requestMDSV != null) { requestDSV = requestMDSV.Version > 20 ? requestMDSV : new ServiceVersion(40); } if (exception != null) { Assert.AreEqual(400, request.ResponseStatusCode, "Expecting bad request"); List<string> expectedErrorMessages = new List<string>(); if (requestDSV != null && requestDSV.Version < versions.MinRequestDSV.Version) { expectedErrorMessages.Add(DataServicesResourceUtil.GetString("DataService_DSVTooLow", requestDSV.ToString(), versions.MinRequestDSV.Version / 10, versions.MinRequestDSV.Version % 10)); } if (requestMDSV != null && requestMDSV.Version < versions.MinRequestMDSV.Version) { expectedErrorMessages.Add(DataServicesResourceUtil.GetString("DataService_MaxDSVTooLow", requestMDSV.ToString(), versions.MinRequestMDSV.Version / 10, versions.MinRequestMDSV.Version % 10)); } // Since enableRelationshipLinks is true, the response will be 3.0 if the MPV is set to 3.0. For V1/V2 servers, this setting is ignored if (protocolVersion == ODataProtocolVersion.V4 && requestMDSV != null && requestMDSV.ToProtocolVersion() < protocolVersion) { expectedErrorMessages.Add(DataServicesResourceUtil.GetString("DataService_MaxDSVTooLow", requestMDSV.ToString(), 4, 0)); } if (expectedErrorMessages.Count != 0) { Assert.IsTrue(expectedErrorMessages.Contains(exception.InnerException.Message), "Didn't find the expected error message"); } else { Assert.Fail("Exception not expected, but exception was thrown"); } return false; } Assert.IsTrue(requestDSV == null || requestDSV.Version >= versions.MinRequestDSV.Version, "Request DSV should be equal or greater than the min required DSV"); Assert.IsTrue(requestMDSV == null || requestMDSV.Version >= versions.MinRequestMDSV.Version, "Request MDSV should be equal or greater than the min required MDSV"); return true; }
private static void SendRequestAndVerifyUriAndContext(DSPServiceDefinition service, Func<IEnumerable<Tuple<Func<DataServiceContext, IQueryable>[], Func<DataServiceContext, string>, Action<DataServiceContext, IQueryable, List<object>>>>> queryUrisAndValidations) { using (InProcessWebRequest request = (InProcessWebRequest)service.CreateForInProcess()) { request.StartService(); ODataProtocolVersion[] versions = new ODataProtocolVersion[] { ODataProtocolVersion.V4 }; t.TestUtil.RunCombinations(queryUrisAndValidations(), versions, (testCase, version) => { var getQueries = testCase.Item1; var getExpectedUri = testCase.Item2; var validate = testCase.Item3; foreach (var getQuery in getQueries) { var host = new t.TestServiceHost2(); var requestMessage = new DataServiceHostRequestMessage(host); var ctx = new DataServiceContextWithCustomTransportLayer(request.ServiceRoot, version, () => requestMessage, () => { request.SendRequest(host); return new DataServiceHostResponseMessage(host); }); ctx.EnableAtom = true; ctx.Format.UseAtom(); if (version < ODataProtocolVersion.V4) { var query = getQuery(ctx); try { foreach (var p in query) { } Assert.Fail("Exception expected but received none."); } catch (NotSupportedException e) { Assert.IsTrue( "The expression 'TypeAs' is not supported when MaxProtocolVersion is less than '4.0'." == e.Message || "The method 'OfType' is not supported when MaxProtocolVersion is less than '4.0'." == e.Message); } } else { #region Setup resolvers and events ctx.ResolveType = (typeName) => { if (typeName == typeof(Employee).FullName) { return typeof(Employee); } if (typeName == typeof(PeopleManager).FullName) { return typeof(PeopleManager); } return null; }; ctx.SendingRequest2 += (sender, e) => { Assert.AreEqual("4.0", e.RequestMessage.GetHeader("OData-Version"), "OData-Version mismatch."); Assert.AreEqual("4.0", e.RequestMessage.GetHeader("OData-MaxVersion"), "OData-MaxVersion mismatch."); }; #endregion Setup resolvers and events // Validate Uri var query = getQuery(ctx); string clientGeneratedUri = query.ToString(); Assert.AreEqual(getExpectedUri(ctx), clientGeneratedUri); #region Validate entities List<object> materializedObjects = new List<object>(); // Materialize and validate LinkInfos foreach (var e in query) { EntityDescriptor descriptor = ctx.GetEntityDescriptor(e); if (descriptor != null) { foreach (var link in descriptor.LinkInfos) { switch (link.Name) { case "Aquaintances": case "DirectReports": case "Manager": case "Colleagues": case "BestFriend": case "Friends": // If the entity is not of the base type (Person), then expect navigation links to have a type segment. if (descriptor.ServerTypeName != "AstoriaUnitTests.Tests.DerivedProperty.Person") { t.TestUtil.AssertContains(link.NavigationLink.OriginalString, descriptor.ServerTypeName); if (link.AssociationLink != null) { t.TestUtil.AssertContains(link.AssociationLink.OriginalString, descriptor.ServerTypeName); } } break; default: Assert.Fail("Unexpected link: " + link.Name); return; } } } materializedObjects.Add(e); } #endregion Validate entities #region Validate Links // Validate LinkDescriptors foreach (LinkDescriptor link in ctx.Links) { string identity = ctx.GetEntityDescriptor(link.Source).Identity.AbsoluteUri; int startIdx = identity.IndexOf('(') + 1; int endIdx = identity.IndexOf(')'); int sourceId = int.Parse(identity.Substring(startIdx, endIdx - startIdx)); identity = ctx.GetEntityDescriptor(link.Target).Identity.AbsoluteUri; startIdx = identity.IndexOf('(') + 1; endIdx = identity.IndexOf(')'); int targetId = int.Parse(identity.Substring(startIdx, endIdx - startIdx)); switch (link.SourceProperty) { case "DirectReports": switch (sourceId) { case 1: //"Foo": Assert.Fail("DirectReports link not expected for Foo"); break; case 2: //"Andy": //Assert.IsTrue(targetName == "Pratik" || targetName == "Jimmy"); Assert.IsTrue(targetId == 3 || targetId == 4); break; case 3: //"Pratik": Assert.Fail("DirectReports link not expected for Pratik"); break; case 4: //"Jimmy": Assert.Fail("DirectReports link not expected for Jimmy"); break; case 5: //"Shyam": //Assert.IsTrue(targetName == "Andy" || targetName == "Marcelo"); Assert.IsTrue(targetId == 2 || targetId == 6); break; case 6: //"Marcelo": Assert.Fail("DirectReports link not expected for Marcelo"); break; default: Assert.Fail("Unrecognized id: " + sourceId); break; } break; case "Manager": switch (sourceId) { case 1: //"Foo": Assert.Fail("Manager link not expected for Foo"); break; case 2: //"Andy": //Assert.AreEqual("Shyam", targetName); Assert.AreEqual(5, targetId); break; case 3: //"Pratik": //Assert.AreEqual("Andy", targetName); Assert.AreEqual(2, targetId); break; case 4: //"Jimmy": //Assert.AreEqual("Andy", targetName); Assert.AreEqual(2, targetId); break; case 5: //"Shyam": //Assert.AreEqual("Shyam", targetName); Assert.AreEqual(5, targetId); break; case 6: //"Marcelo": //Assert.AreEqual("Shyam", targetName); Assert.AreEqual(5, targetId); break; default: Assert.Fail("Unrecognized id: " + sourceId); break; } break; case "Colleagues": switch (sourceId) { case 1: //"Foo": Assert.Fail("Colleagues link not expected for Foo"); break; case 2: //"Andy": //Assert.AreEqual("Marcelo", targetName); Assert.AreEqual(6, targetId); break; case 3: //"Pratik": //Assert.AreEqual("Jimmy", targetName); Assert.AreEqual(4, targetId); break; case 4: //"Jimmy": //Assert.AreEqual("Pratik", targetName); Assert.AreEqual(3, targetId); break; case 5: //"Shyam": Assert.Fail("Colleagues link not expected for Shyam"); break; case 6: //"Marcelo": //Assert.AreEqual("Andy", targetName); Assert.AreEqual(2, targetId); break; default: Assert.Fail("Unrecognized id: " + sourceId); break; } break; case "BestFriend": switch (sourceId) { case 1: //"Foo": //Assert.AreEqual("Pratik", targetName); Assert.AreEqual(3, targetId); break; case 2: //"Andy": //Assert.AreEqual("Shyam", targetName); Assert.AreEqual(5, targetId); break; case 3: //"Pratik": //Assert.AreEqual("Andy", targetName); Assert.AreEqual(2, targetId); break; case 4: //"Jimmy": //Assert.AreEqual("Foo", targetName); Assert.AreEqual(1, targetId); break; case 5: //"Shyam": //Assert.AreEqual("Marcelo", targetName); Assert.AreEqual(6, targetId); break; case 6: //"Marcelo": //Assert.AreEqual("Jimmy", targetName); Assert.AreEqual(4, targetId); break; default: Assert.Fail("Unrecognized id: " + sourceId); break; } break; case "Friends": break; default: Assert.Fail("Unexpected link descriptor: " + link.SourceProperty); return; } } #endregion Validate Links // Validation specific to the test case. validate(ctx, query, materializedObjects); } } }); } }
/// <summary> /// Constructor. /// </summary> /// <param name="maxProtocolVersion">The protocol version this Edm model is created for.</param> internal ClientEdmModel(ODataProtocolVersion maxProtocolVersion) { this.maxProtocolVersion = maxProtocolVersion; this.EdmStructuredSchemaElements = new ConcurrentEdmSchemaDictionary(); }
public virtual DataServiceContext WriterClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { var ctx = new Container(serviceRoot, protocolVersion); return(ctx); }
public virtual DataServiceContext ReaderClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { return(new Container(serviceRoot, protocolVersion)); }
public static void SetBaseServiceProtocolVersion(this ServiceContextDescription serviceDescription, ODataProtocolVersion protocolVersion) { serviceDescription.SetAnnotation(BaseServiceProtocolVersionName, protocolVersion); }
public static ODataProtocolVersion GetMaxProtocolVersion(this ServiceContextDescription serviceDescription, ODataProtocolVersion defaultVersion) { return GetMaxProtocolVersion(serviceDescription) ?? defaultVersion; }
public virtual DataServiceContext ReaderClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { //By default reader uses the same configuration as writer. Reading is a more important scenario than writing //so this configuration allows for partial support for reading while using a standard configuration for writing. return WriterClient(serviceRoot, protocolVersion); }
public virtual DataServiceContext WriterClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { DataServiceContext ctx = new DataServiceContext(serviceRoot, protocolVersion); return ctx; }
public override DataServiceContext WriterClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { return(new Container(serviceRoot, protocolVersion)); }
public override DataServiceContext WriterClient(Uri serviceRoot, ODataProtocolVersion protocolVersion) { var ctx = base.WriterClient(serviceRoot, protocolVersion); new JsonLightConfigurator(ctx, AcceptHeader).Configure(); return ctx; }
private DataServiceContextWithCustomTransportLayer CreateTransportLayerContext(string payload, string odataVersion, ODataProtocolVersion maxDataServiceVersion, string contentTypeHeaderValue = MimeApplicationAtom) { IODataRequestMessage requestMessage = new ODataTestMessage(); var responseMessage = new ODataTestMessage(); responseMessage.SetHeader("Content-Type", contentTypeHeaderValue); responseMessage.SetHeader("OData-Version", odataVersion); responseMessage.StatusCode = 200; responseMessage.WriteToStream(payload); responseMessage.SetHeader("Content-Length", responseMessage.MemoryStream.Length.ToString()); var context = new DataServiceContextWithCustomTransportLayer(maxDataServiceVersion, requestMessage, responseMessage); context.EnableAtom = true; context.ResolveName = ResolveName; context.ResolveType = ResolveType; context.Format.UseJson(Model); return(context); }
/// <summary> /// Initializes a new TestWebRequest instance with simple defaults /// that have no side-effects on querying. /// </summary> public DataServiceContextWithCustomTransportLayer(ODataProtocolVersion maxProtocolVersion, Func<IODataRequestMessage> getRequestMessage, Func<IODataResponseMessage> getResponseMessage) : this(DummyUri, maxProtocolVersion, getRequestMessage, getResponseMessage) { }
/// <summary> /// Convert the ODataProtocolVersion to ODataVersion. /// </summary> /// <param name="maxProtocolVersion">ODataProtocolVersion value to convert.</param> /// <returns>an ODataVersion value for the given ODataProtocolVersion value.</returns> internal static ODataVersion ConvertToODataVersion(ODataProtocolVersion maxProtocolVersion) { switch (maxProtocolVersion) { case ODataProtocolVersion.V4: return ODataVersion.V4; default: Debug.Assert(false, "Need to add a case for the new version that got added"); return (ODataVersion)(-1); } }
public Container(Uri serviceRoot, ODataProtocolVersion protocolVersion) : base(serviceRoot, protocolVersion) { this.ResolveName = new Func<Type, string>(this.ResolveNameFromType); this.ResolveType = new Func<string, Type>(this.ResolveTypeFromName); }